From e2e2eb9a2fd79711efae8fd929af773a4ec515e7 Mon Sep 17 00:00:00 2001 From: b2894lxlx <517289602@qq.com> Date: Wed, 23 Sep 2026 14:49:09 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=AE=8C=E5=96=84=E5=90=88?= =?UTF-8?q?=E5=90=8C=E9=99=84=E4=BB=B6=E4=B8=8A=E4=BC=A0=E5=9B=9E=E5=A1=AB?= =?UTF-8?q?=E3=80=81=E7=B1=BB=E5=9E=8B=E5=8C=B9=E9=85=8D=E4=B8=8E=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=99=84=E4=BB=B6=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复上传成功后表格不回显,附件类型可切换,未匹配文件名默认其他文件;列表附件上传支持合同文件/其它附件。 Co-authored-by: Cursor --- .../vehicle-attachment-upload/main.vue | 107 ++++- .../contract-attachment-section.vue | 445 +++++++++++------- src/views/business/contract-manage-change.vue | 3 - src/views/business/contract-manage.vue | 106 ++++- 4 files changed, 454 insertions(+), 207 deletions(-) diff --git a/src/components/vehicle-attachment-upload/main.vue b/src/components/vehicle-attachment-upload/main.vue index 436efec..81961de 100644 --- a/src/components/vehicle-attachment-upload/main.vue +++ b/src/components/vehicle-attachment-upload/main.vue @@ -212,7 +212,14 @@ export default { .filter(Boolean); }, acceptText() { - return this.acceptedList.join(','); + return this.acceptedList + .map(item => { + const value = String(item).trim(); + if (!value || value.includes('/') || value.startsWith('.')) return value; + return `.${value}`; + }) + .filter(Boolean) + .join(','); }, tipText() { return this.tip || `${UNIFIED_ATTACHMENT_TIP_PREFIX}${this.maxSize}M`; @@ -304,12 +311,22 @@ export default { }); }, handleSuccess(response, file, files) { - if (!response || response.success === false || (response.code && response.code !== 200)) { + const code = response?.code; + const codeInvalid = code !== undefined && code !== null && code !== '' && Number(code) !== 200; + if (!response || response.success === false || codeInvalid) { this.$message.error((response && response.msg) || '上传失败'); return; } - this.emitUploadFiles(this.multiple ? files : [file]); - this.$emit('success', this.normalizeUploadFile(file)); + if (file && !file.response) { + file.response = response; + } + const normalized = this.normalizeUploadFile(file, response); + if (!normalized.url) { + this.$message.error('上传成功但未返回文件地址'); + return; + } + this.$emit('success', normalized); + this.emitUploadFiles(this.multiple ? files : [file], normalized); this.$message.success('上传成功'); }, handleChange(file, files) { @@ -323,35 +340,89 @@ export default { this.emitUploadFiles(files); return true; }, - emitUploadFiles(files) { - const list = files - .filter(file => file.status === 'success' || this.getFileUrl(file)) - .map(this.normalizeUploadFile) + emitUploadFiles(files, preferredFile) { + const list = (files || []) + .filter(file => { + if (file?.status === 'fail') return false; + return ( + file?.status === 'success' || + this.getFileUrl(file) || + file?.response?.data || + file?.response?.link || + file?.response + ); + }) + .map(file => this.normalizeUploadFile(file)) .filter(item => item.url); - this.$emit('update:modelValue', list); - this.$emit('change', list); + + if (preferredFile?.url) { + const exists = list.some( + item => + (preferredFile.uid && item.uid && String(item.uid) === String(preferredFile.uid)) || + item.url === preferredFile.url + ); + if (!exists) list.push(preferredFile); + } + + const current = this.parseValue(this.modelValue).map(item => ({ + ...item, + url: this.getFileUrl(item), + })); + const merged = [...current]; + list.forEach(file => { + const index = merged.findIndex( + item => + (file.uid && item.uid && String(item.uid) === String(file.uid)) || + (file.url && this.getFileUrl(item) === file.url) + ); + if (index >= 0) merged.splice(index, 1, { ...merged[index], ...file }); + else merged.push(file); + }); + + const result = merged.filter(item => this.getFileUrl(item)); + this.$emit('update:modelValue', result); + this.$emit('change', result); }, - normalizeUploadFile(file) { - const data = (file.response && file.response.data) || file.data || file; - const url = data.link || data.url || data.domain || file.url || ''; + normalizeUploadFile(file, responseOverride) { + const response = responseOverride || file?.response; + let data = {}; + if (response && typeof response === 'object') { + if (response.data && typeof response.data === 'object') { + data = response.data; + } else if (response.link || response.url || response.domain) { + data = response; + } + } + if (!data.link && !data.url && !data.domain) { + data = file?.data && typeof file.data === 'object' ? file.data : file || {}; + } + const url = + data.link || + data.url || + data.domain || + data.fileLink || + data.fileUrl || + file?.url || + file?.link || + ''; const originalName = data.originalName || - file.originalName || - file.name || + file?.originalName || + file?.name || data.name || this.getFileName(url) || '附件'; const extension = this.getExtension({ name: originalName, url }); return { ...data, - uid: file.uid || data.uid, + uid: file?.uid || data.uid, originalName, name: originalName, url, link: data.link || url, - size: data.size || data.attachSize || file.size || '', + size: data.size || data.attachSize || file?.size || '', extension, - mimeType: data.mimeType || data.contentType || file.raw?.type || MIME_MAP[extension] || '', + mimeType: data.mimeType || data.contentType || file?.raw?.type || MIME_MAP[extension] || '', }; }, handlePreview(file) { diff --git a/src/views/business/components/contract-attachment-section.vue b/src/views/business/components/contract-attachment-section.vue index 297b52c..10119b9 100644 --- a/src/views/business/components/contract-attachment-section.vue +++ b/src/views/business/components/contract-attachment-section.vue @@ -1,94 +1,102 @@ - +