From a7b8b8247974d56b4b1f125a4128aebf3d1368e1 Mon Sep 17 00:00:00 2001 From: hyx Date: Wed, 19 Apr 2023 16:03:37 +0800 Subject: [PATCH] =?UTF-8?q?CN-965=20=E7=9F=A5=E8=AF=86=E5=BA=93Preview?= =?UTF-8?q?=EF=BC=9A1.=E4=B8=80=E6=9D=A1=E4=B8=80=E6=9D=A1=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=95=B0=E6=8D=AE=EF=BC=8C=E7=9B=B4=E5=88=B0=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AE=8C=E6=AF=95=EF=BC=8C=E5=88=97=E8=A1=A8=E6=9C=AA?= =?UTF-8?q?=E6=98=BE=E7=A4=BAnodata=EF=BC=9B2.=E5=88=97=E8=A1=A8=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=95=B0=E6=8D=AE=E6=97=B6=EF=BC=8C=E4=B8=8D=E5=BC=B9?= =?UTF-8?q?=E5=87=BA=E5=AF=B9=E8=AF=9D=E6=A1=86=EF=BC=9B3.=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=9C=80=E5=90=8E=E4=B8=80=E6=9D=A1=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=97=B6=E6=8A=A5=E9=94=99=EF=BC=9B4.=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=B8=AD=EF=BC=8C=E6=AD=A4=E6=97=B6=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=8A=A5=E9=94=99=E6=8C=89=E9=92=AE=EF=BC=8C=E6=8A=A5?= =?UTF-8?q?=E9=94=99=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/setting/KnowledgeBaseForm.vue | 222 +++++++++++++----------- 1 file changed, 121 insertions(+), 101 deletions(-) diff --git a/src/views/setting/KnowledgeBaseForm.vue b/src/views/setting/KnowledgeBaseForm.vue index f634bfc6..37309088 100644 --- a/src/views/setting/KnowledgeBaseForm.vue +++ b/src/views/setting/KnowledgeBaseForm.vue @@ -431,8 +431,7 @@ export default { if (this.fileList.length > 0 && this.fileList[0].status === 'success') { this.fileListBack = this.fileList[0] } - const file = fileList.slice(-1) - this.fileList = file + this.fileList = fileList.slice(-1) }, uploadError () { this.uploadLoading = false @@ -481,6 +480,7 @@ export default { this.editTagErrorTip = '' this.editIndex = -1 this.isPreviewChange = true + this.importedDataNoData = true } if (this.fileListBack !== undefined && this.fileListBack.status === 'success' && this.importedData.length > 0) { @@ -491,20 +491,26 @@ export default { if (!this.isShowUploadTips) { this.isShowUploadTips = true const self = this - this.$confirm(this.$t('tip.uploadFile'), { - confirmButtonText: this.$t('tip.confirm'), - cancelButtonText: this.$t('overall.cancel'), - message: this.$t('tip.uploadFileTips'), - title: this.$t('tip.uploadFile'), - type: 'warning', - iconClass: 'width:0px;height:0px;', - customClass: 'del-model' - }).then(() => { + if (this.importedData.length > 0) { + this.$confirm(this.$t('tip.uploadFile'), { + confirmButtonText: this.$t('tip.confirm'), + cancelButtonText: this.$t('overall.cancel'), + message: this.$t('tip.uploadFileTips'), + title: this.$t('tip.uploadFile'), + type: 'warning', + iconClass: 'width:0px;height:0px;', + customClass: 'del-model' + }).then(() => { + this.isClick = true + self.$refs.upload.$refs.uploadRef.handleClick() + }).catch(e => {}).finally(() => { + this.isShowUploadTips = false + }) + } else { this.isClick = true - self.$refs.upload.$refs.uploadRef.handleClick() - }).catch(e => {}).finally(() => { this.isShowUploadTips = false - }) + self.$refs.upload.$refs.uploadRef.handleClick() + } } }, promiseState (p) { @@ -525,19 +531,23 @@ export default { reject(new Error(this.$t('validate.fileSizeLimit', { size: unitConvert(this.uploadFileSizeLimit, unitTypes.byte).join('') }))) } else { if (!this.isClick) { - this.$confirm(this.$t('tip.uploadFile'), { - confirmButtonText: this.$t('tip.confirm'), - cancelButtonText: this.$t('overall.cancel'), - message: this.$t('tip.uploadFileTips'), - title: this.$t('tip.uploadFile'), - type: 'warning', - iconClass: 'width:0px;height:0px;', - customClass: 'del-model' - }).then(() => { + if (this.importedData.length > 0) { + this.$confirm(this.$t('tip.uploadFile'), { + confirmButtonText: this.$t('tip.confirm'), + cancelButtonText: this.$t('overall.cancel'), + message: this.$t('tip.uploadFileTips'), + title: this.$t('tip.uploadFile'), + type: 'warning', + iconClass: 'width:0px;height:0px;', + customClass: 'del-model' + }).then(() => { + resolve() + }).catch(e => { + reject(e) + }) + } else { resolve() - }).catch(e => { - reject(e) - }) + } } else { resolve() } @@ -575,7 +585,7 @@ export default { // 删除内容为空的新增记录 const lastIndex = this.importedData.length - 1 const lastData = this.importedData[lastIndex] - if (lastData.tagItem === '' && lastData.tagValue === '') { + if (lastData !== undefined && lastData.tagItem === '' && lastData.tagValue === '') { this.importedData.pop() } this.importedPageObj.total = this.importedData.length @@ -639,88 +649,96 @@ export default { this.previewErrorTip = '' } if (valid) { - this.$refs.editForm.validate((validImportData) => { - if (validImportData) { - // 校验通过后组织数据、请求接口 - if (valid && !this.uploadErrorTip && !this.previewErrorTip) { - const postData = { - tagName: this.editObject.tagName, - tagType: this.editObject.tagType, - data: [] - } - // 避免点击新增后,并没有保存新增项就点击了save,此时删除新增的空白项 - if (this.importedData[this.importedData.length - 1].tagItem === '') { - this.importedData.pop() - } - this.importedData.forEach(d => { - const findData = postData.data.find(d2 => d2.tagValue === d.tagValue) - if (findData) { - findData.itemList.add(d.tagItem) + if (this.$refs.editForm) { + this.$refs.editForm.validate((validImportData) => { + if (validImportData) { + // 校验通过后组织数据、请求接口 + if (valid && !this.uploadErrorTip && !this.previewErrorTip) { + if (this.importedData.length === 1 && this.importedData[0].tagItem === '') { + // this.blockOperation.save = false } else { - const set = new Set() - set.add(d.tagItem) - postData.data.push({ - tagValue: d.tagValue, - itemList: set + const postData = { + tagName: this.editObject.tagName, + tagType: this.editObject.tagType, + data: [] + } + // 避免点击新增后,并没有保存新增项就点击了save,此时删除新增的空白项 + if (this.importedData[this.importedData.length - 1].tagItem === '') { + this.importedData.pop() + } + this.importedData.forEach(d => { + const findData = postData.data.find(d2 => d2.tagValue === d.tagValue) + if (findData) { + findData.itemList.add(d.tagItem) + } else { + const set = new Set() + set.add(d.tagItem) + postData.data.push({ + tagValue: d.tagValue, + itemList: set + }) + } }) + postData.data.forEach(d => { + // d.itemList = [...d.itemList] + d.itemList = Array.from(d.itemList) + }) + postData.remark = this.editObject.remark + if (!this.editObject.id) { + axios.post(this.url, postData).then(response => { + if (response.data.code === 200) { + this.$message({ + duration: 2000, + type: 'success', + message: this.$t('tip.saveSuccess') + }) + this.$router.push({ + path: '/knowledgeBase', + t: +new Date() + }) + } else { + this.errorMsgHandler(response) + } + }).catch(e => { + console.error(e) + this.errorMsgHandler(e) + }).finally(() => { + this.blockOperation.save = false + }) + } else { + postData.id = this.editObject.id + axios.put(this.url, postData).then(response => { + if (response.data.code === 200) { + this.$message({ + duration: 2000, + type: 'success', + message: this.$t('tip.saveSuccess') + }) + this.$router.push({ + path: '/knowledgeBase', + t: +new Date() + }) + } else { + this.errorMsgHandler(response) + } + }).catch(e => { + console.error(e) + this.errorMsgHandler(e) + }).finally(() => { + this.blockOperation.save = false + }) + } } - }) - postData.data.forEach(d => { - // d.itemList = [...d.itemList] - d.itemList = Array.from(d.itemList) - }) - postData.remark = this.editObject.remark - if (!this.editObject.id) { - axios.post(this.url, postData).then(response => { - if (response.data.code === 200) { - this.$message({ - duration: 2000, - type: 'success', - message: this.$t('tip.saveSuccess') - }) - this.$router.push({ - path: '/knowledgeBase', - t: +new Date() - }) - } else { - this.errorMsgHandler(response) - } - }).catch(e => { - console.error(e) - this.errorMsgHandler(e) - }).finally(() => { - this.blockOperation.save = false - }) } else { - postData.id = this.editObject.id - axios.put(this.url, postData).then(response => { - if (response.data.code === 200) { - this.$message({ - duration: 2000, - type: 'success', - message: this.$t('tip.saveSuccess') - }) - this.$router.push({ - path: '/knowledgeBase', - t: +new Date() - }) - } else { - this.errorMsgHandler(response) - } - }).catch(e => { - console.error(e) - this.errorMsgHandler(e) - }).finally(() => { - this.blockOperation.save = false - }) + this.blockOperation.save = false } } else { this.blockOperation.save = false } - } else { - this.blockOperation.save = false - } - }) + }) + } else { + this.blockOperation.save = false + } } else { this.blockOperation.save = false } @@ -806,11 +824,13 @@ export default { if (total > 0 && total < 10) { this.importedData.push({ tagItem: '', tagValue: '', status: 1 }) this.showImportedData.push({ tagItem: '', tagValue: '', status: 1 }) + this.importedDataNoData = false } else { const lastPageSize = Math.ceil((total + 1) / 10) this.pageNo(lastPageSize) this.importedData.push({ tagItem: '', tagValue: '', status: 1 }) this.showImportedData.push({ tagItem: '', tagValue: '', status: 1 }) + this.importedDataNoData = false } this.importedPageObj.total = this.importedData.length this.timer = setTimeout(() => {