From 7d4b929fc42dfe80d1af158ec4652e3681d3bb67 Mon Sep 17 00:00:00 2001 From: cwchen <1048842385@qq.com> Date: Wed, 19 Nov 2025 11:06:32 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/common/UploadMoreFile.vue | 60 +++++++++++++++---- .../technical/components/TechnicalForm.vue | 2 +- .../technical/components/child/FileInfo.vue | 5 +- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/src/views/common/UploadMoreFile.vue b/src/views/common/UploadMoreFile.vue index 79abbb5..6630ad0 100644 --- a/src/views/common/UploadMoreFile.vue +++ b/src/views/common/UploadMoreFile.vue @@ -111,7 +111,7 @@ export default { watch: { fileList: { handler(newVal) { - + if (this.files.length === 0 && newVal.length > 0) { this.$nextTick(() => { if (this.$refs.upload) { @@ -273,24 +273,55 @@ export default { }, handleExceed(files, fileList) { - this.$message.warning(`最多只能上传 ${this.limitUploadNum} 个文件,已自动截取前 ${this.limitUploadNum} 个文件`); - // 将 FileList 转换为数组 const filesArray = Array.from(files); - const remainingSlots = this.limitUploadNum - this.files.length; + // 如果只允许上传一个文件,则替换现有文件 + if (this.limitUploadNum === 1) { + + // 触发删除事件 + this.$emit('del-file', { ...fileList[0], response: fileList[0].res }) + // 清空文件列表 + this.files = []; - if (remainingSlots > 0) { - const filesToAdd = filesArray.slice(0, remainingSlots); - filesToAdd.forEach(file => { - const newFileObj = this.createFileObject(file); - this.files.push(newFileObj); + // 更新 el-upload 的文件列表 + this.$nextTick(() => { + if (this.$refs.upload) { + this.$refs.upload.uploadFiles = []; + } - if (this.autoUpload) { - this.$nextTick(() => { - this.uploadFile(newFileObj); - }); + // 添加新文件(只取第一个) + if (filesArray.length > 0) { + const newFileObj = this.createFileObject(filesArray[0]); + this.files.push(newFileObj); + + if (this.autoUpload) { + this.$nextTick(() => { + this.uploadFile(newFileObj); + }); + } } }); + + this.$message.success('文件已替换'); + } else { + // 多文件模式:保持原有逻辑 + this.$message.warning(`最多只能上传 ${this.limitUploadNum} 个文件,已自动截取前 ${this.limitUploadNum} 个文件`); + + const remainingSlots = this.limitUploadNum - this.files.length; + + if (remainingSlots > 0) { + const filesToAdd = filesArray.slice(0, remainingSlots); + filesToAdd.forEach(file => { + const newFileObj = this.createFileObject(file); + this.files.push(newFileObj); + + if (this.autoUpload) { + this.$nextTick(() => { + this.uploadFile(newFileObj); + }); + } + }); + } } }, @@ -392,10 +423,13 @@ export default { formattedFile.percentage = 100 } + // 保留其他属性 if (file.response) { formattedFile.response = file.response formattedFile.res = file.response } + if (file.filePath) formattedFile.filePath = file.filePath + if (file.statusText) formattedFile.statusText = file.statusText return formattedFile }) diff --git a/src/views/enterpriseLibrary/technical/components/TechnicalForm.vue b/src/views/enterpriseLibrary/technical/components/TechnicalForm.vue index 1ffd5f8..e81248e 100644 --- a/src/views/enterpriseLibrary/technical/components/TechnicalForm.vue +++ b/src/views/enterpriseLibrary/technical/components/TechnicalForm.vue @@ -96,7 +96,7 @@ export default { this.$refs.basicInfo.validate(), this.$refs.fileInfo.validate() ]) - + // 所有校验通过,组装完整数据 let formData = { ...basicInfoData, diff --git a/src/views/enterpriseLibrary/technical/components/child/FileInfo.vue b/src/views/enterpriseLibrary/technical/components/child/FileInfo.vue index 8aa6da7..3ddf06e 100644 --- a/src/views/enterpriseLibrary/technical/components/child/FileInfo.vue +++ b/src/views/enterpriseLibrary/technical/components/child/FileInfo.vue @@ -70,7 +70,7 @@ export default { handler(newVal) { if (Object.keys(newVal).length > 0) { this.limitUploadNum = 1; - this.disabled = true; + // this.disabled = true; this.setFormData(newVal) } }, @@ -102,13 +102,16 @@ export default { }, // 文件删除时触发 handleDelFile(file) { + const delPath = file?.response?.fileRes?.filePath || file?.filePath || null; + if (delPath) { this.form.delFileList.push(delPath); } }, setFormData() { const fileList = this.getFileList(); + this.form = { fileList: fileList, delFileList: []