From 04d9c4ab1186a9c0490fad8093fbf7fac8bd871a Mon Sep 17 00:00:00 2001 From: Riollee <530377286@qq.com> Date: Sat, 7 Aug 2021 14:31:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90feat=E3=80=91=E9=87=8D=E6=9E=84http?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/navcon.vue | 8 +-- src/utils/http.js | 123 ++++++++++++-------------------- src/views/Content/News.vue | 66 ++++------------- src/views/Content/Patents.vue | 22 +++--- src/views/Editor/EditorPage.vue | 44 ++++++------ src/views/user/UsersManage.vue | 20 +++--- 6 files changed, 109 insertions(+), 174 deletions(-) diff --git a/src/components/navcon.vue b/src/components/navcon.vue index 02b9678..3789b13 100644 --- a/src/components/navcon.vue +++ b/src/components/navcon.vue @@ -1,6 +1,6 @@ /** * 头部菜单 -*/ +*/ @@ -131,7 +98,6 @@ export default { }, ], loading: false, //是显示加载 - editFormVisible: false, //控制编辑页面显示与隐藏 title: '', editForm: { title: '', @@ -167,7 +133,7 @@ export default { }, watch: { - 'formInline.type': function (newVal, oldVal) { + 'formInline.type': function () { this.getdata(this.formInline) }, }, @@ -210,7 +176,7 @@ export default { page: parameter.page, page_size: parameter.limit, } - if (parameter.type >= 0 && parameter.type <= 3) { + if (parameter.type !== '' && parameter.type >= 0 && parameter.type <= 3) { params.type = parameter.type } if (parameter.search !== '') { @@ -222,13 +188,17 @@ export default { that.pageparm.pageSize = that.formInline.pageSize that.pageparm.total = value.count this.loading = false - }).catch(err => { - this.$message.error('加载失败') + }, reason => this.$message.warning(reason)).catch(() => { + this.$message.error('未知错误,加载失败') }) }, callFather (parm) { - this.formInline.page = parm.currentPage + if (this.formInline.limit !== parm.pageSize) { + this.formInline.page = 1 + } else { + this.formInline.page = parm.currentPage + } this.formInline.limit = parm.pageSize this.getdata(this.formInline) }, @@ -238,12 +208,11 @@ export default { }, handleEdit: function (index, row) { - // this.editFormVisible = true if (row !== undefined && row !== 'undefined') { this.editId = row.id - this.$router.push({ name: 'newsEditor', params: { newsId: this.editId.toString() }}) + this.$router.push({ name: 'newsEditor', params: { newsId: this.editId.toString() } }) } else { - this.$router.push({ name: 'newsEditor', params: { newsId: '0' }}) + this.$router.push({ name: 'newsEditor', params: { newsId: '0' } }) } }, @@ -253,10 +222,9 @@ export default { return false } put(`/news/${this.editForm.editId}/`, { ...this.editForm }).then(() => { - this.editFormVisible = false this.$message.success('修改成功') this.getdata(this.formInline) - }).catch(error => this.$message.error('修改失败')) + }, reason => this.$message.warning(reason)).catch(() => this.$message.error('未知错误,修改失败')) }) }, @@ -270,17 +238,13 @@ export default { Delete(`/news/${row.id}/`).then(() => { this.$message.success('删除成功') this.getdata(this.formInline) - }).catch(err => this.$message.error('删除失败')) + }, reason => this.$message.warning(reason)).catch(() => this.$message.error('未知错误,删除失败')) } else { - this.$message.error('删除失败') + this.$message.error('未知错误,删除失败') } }) }, - closeDialog (formName) { - this.editFormVisible = false - this.$refs['editForm'].resetFields() - }, }, } diff --git a/src/views/Content/Patents.vue b/src/views/Content/Patents.vue index 7d873a6..99fa231 100644 --- a/src/views/Content/Patents.vue +++ b/src/views/Content/Patents.vue @@ -228,13 +228,16 @@ export default { that.pageparm.pageSize = that.formInline.pageSize that.pageparm.total = value.count this.loading = false - }).catch(() => { - this.$message.error('加载失败') - }) + }, reason => this.$message.warning(reason)).catch(() => + this.$message.error('未知错误,加载失败')) }, callFather (parm) { - this.formInline.page = parm.currentPage + if (this.formInline.limit !== parm.pageSize) { + this.formInline.page = 1 + } else { + this.formInline.page = parm.currentPage + } this.formInline.limit = parm.pageSize this.getdata(this.formInline) }, @@ -273,13 +276,13 @@ export default { this.editFormVisible = false this.$message.success('修改成功') this.getdata(this.formInline) - }).catch(error => this.$message.error('修改失败')) + }, reason => this.$message.warning(reason)).catch(() => this.$message.error('未知错误,修改失败')) } else if (this.title === '添加') { post(`/patent/`, { ...this.editForm }).then(() => { this.editFormVisible = false this.$message.success('添加成功') this.getdata(this.formInline) - }).catch(() => this.$message.error('添加失败')) + }, reason => this.$message.warning(reason)).catch(() => this.$message.error('未知错误,添加失败')) } }) }, @@ -294,9 +297,9 @@ export default { Delete(`/patent/${row.id}/`).then(() => { this.$message.success('删除成功') this.getdata(this.formInline) - }).catch(err => this.$message.error('删除失败')) + }, reason => this.$message.warning(reason)).catch(() => this.$message.error('未知错误,删除失败')) } else { - this.$message.error('删除失败') + this.$message.error('未知错误,删除失败') } }) }, @@ -314,9 +317,6 @@ export default { margin-top: 20px; } -.userRole { - width: 100%; -} diff --git a/src/views/Editor/EditorPage.vue b/src/views/Editor/EditorPage.vue index 0a603f4..fdfb09b 100644 --- a/src/views/Editor/EditorPage.vue +++ b/src/views/Editor/EditorPage.vue @@ -77,7 +77,7 @@ export default { addArr: [], fileName: '', fileFormat: '.zip,.rar,.7z', - newsFileExist: false + newsFileExist: false, } }, @@ -96,27 +96,25 @@ export default { let formData = new FormData() formData.append('image', resultFiles[0]) post(`/image/`, formData).then(value => { - console.log('value', value) - insertImgFn(value.data.image) - }, reason => { - this.$message.error(reason) - }).catch(err => this.$message.error(err)) + console.log('value', value) + insertImgFn(value.data.image) + }, reason => this.$message.warning(reason), + ).catch(err => this.$message.error(err)) } // 创建编辑器 editor.create() this.editor = editor - if(this.newsId > 0) { + if (this.newsId > 0) { get(`/news/${this.newsId}`).then(value => { - this.editForm.newsTitle = value.title - this.editForm.newsType = value.type - editor.txt.html(value.content) - this.fileName = '该新闻已有文件' - this.newsFileExist = true - }, reason => { - this.$message.error(reason) - }).catch(error => this.$message.error(error)) + this.editForm.newsTitle = value.title + this.editForm.newsType = value.type + editor.txt.html(value.content) + this.fileName = '该新闻已有附件' + this.newsFileExist = true + }, reason => this.$message.warning(reason), + ).catch(() => this.$message.error('未知错误,获取新闻失败')) } }, @@ -148,7 +146,7 @@ export default { formData.append('title', this.editForm.newsTitle) formData.append('content', newsContent.toString()) formData.append('type', this.editForm.newsType) - if(!this.newsFileExist) { + if (!this.newsFileExist) { formData.append('file ', this.addArr[0]) } let headers = { @@ -156,14 +154,16 @@ export default { } if (this.newsId <= 0) { post(`/news/`, formData, {}, headers).then(() => { - this.$message.success('新闻发布成功') - this.$router.push({ name: 'NewsManage' }) - }, reason => {this.$message.error(reason)}).catch(err => this.$message.error('新闻发布失败')) + this.$message.success('新闻发布成功') + this.$router.push({ name: 'NewsManage' }) + }, reason => {this.$message.error(reason)}, + ).catch(err => this.$message.error('未知错误,新闻发布失败')) } else { put(`/news/${this.newsId}/`, formData, {}, headers).then(() => { - this.$message.success('新闻修改成功') - this.$router.push({ name: 'NewsManage' }) - }, reason => {this.$message.error(reason)}).catch(error => this.$message.error('修改失败')) + this.$message.success('新闻修改成功') + this.$router.push({ name: 'NewsManage' }) + }, reason => {this.$message.error(reason)}, + ).catch(error => this.$message.error('未知错误,新闻修改失败')) } }) }, diff --git a/src/views/user/UsersManage.vue b/src/views/user/UsersManage.vue index 14a4d21..6d802cc 100644 --- a/src/views/user/UsersManage.vue +++ b/src/views/user/UsersManage.vue @@ -35,7 +35,8 @@ - + @@ -114,9 +115,9 @@ export default { that.pageparm.pageSize = that.formInline.pageSize that.pageparm.total = value.count this.loading = false - }).catch(() => { - this.$message.error('加载失败') - }) + }, reason => this.$message.warning(reason)).catch(() => + this.$message.error('未知错误,加载失败'), + ) }, callFather (parm) { @@ -155,13 +156,15 @@ export default { this.editFormVisible = false this.$message.success('修改成功') this.getdata(this.formInline) - }).catch(error => this.$message.error('修改失败')) + }, reason => this.$message.warning(reason)).catch(() => + this.$message.error('未知错误,修改失败')) } else if (this.title === '添加') { post(`/user/`, { ...this.editForm }).then(() => { this.editFormVisible = false this.$message.success('添加成功') this.getdata(this.formInline) - }).catch(() => this.$message.error('添加失败')) + }, reason => this.$message.warning(reason)).catch(() => + this.$message.error('未知错误,添加失败')) } }) }, @@ -176,9 +179,10 @@ export default { Delete(`/user/${row.id}/`).then(() => { this.$message.success('删除成功') this.getdata(this.formInline) - }).catch(err => this.$message.error('删除失败')) + }, reason => this.$message.warning(reason)).catch(() => + this.$message.error('未知错误,删除失败')) } else { - this.$message.error('删除失败') + this.$message.error('未知错误,删除失败') } }) }, -- Gitee