From 7392fd29087edb17885b9f980aa88de14cd8d5a9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 29 Jan 2026 19:58:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=E5=90=8E=E6=96=87=E4=BB=B6=E5=90=8D=E6=98=BE=E7=A4=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 确保压缩后的文件在前端显示正确的 .zip 后缀 - 使用 nextTick 强制更新文件名避免被组件覆盖 --- frontend/src/views/CreateTask.vue | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/frontend/src/views/CreateTask.vue b/frontend/src/views/CreateTask.vue index 2b28c13..b5f5854 100644 --- a/frontend/src/views/CreateTask.vue +++ b/frontend/src/views/CreateTask.vue @@ -1970,16 +1970,18 @@ const handleUpload = async (options: any) => { if (fileUrls && fileUrls.length > 0) { const fileUrl = fileUrls[0] - console.log('[文件上传] 准备更新文件列表,URL:', fileUrl) + // 确定最终显示的文件名(压缩后的文件名或原文件名) + const finalFileName = wasCompressed ? fileToUpload.name : file.name + console.log('[文件上传] 准备更新文件列表,URL:', fileUrl, '文件名:', finalFileName) // 更新文件列表(显示名使用压缩后的文件名) const fileIndex = fileList.value.findIndex(f => f.uid === file.uid) if (fileIndex !== -1) { const updatedFile = { ...fileList.value[fileIndex], - name: wasCompressed ? fileToUpload.name : file.name, // 显示压缩后的文件名 + name: finalFileName, // 显示压缩后的文件名 status: 'done', - response: { fileUrl: fileUrl, data: fileUrls }, + response: { fileUrl: fileUrl, data: fileUrls, fileName: finalFileName }, url: fileUrl, percent: 100 } as UploadFile @@ -1990,9 +1992,22 @@ const handleUpload = async (options: any) => { uploadProgress.value = 0 if (onSuccess) { - // onSuccess 的第一个参数是响应数据,第二个参数是文件对象 - onSuccess({ fileUrl: fileUrl, data: fileUrls }, file) + // onSuccess 的第一个参数是响应数据 + // 注意:不传原始 file 对象,避免组件用原文件名覆盖 + onSuccess({ fileUrl: fileUrl, data: fileUrls, fileName: finalFileName }) } + + // 使用 nextTick 确保文件名在组件更新后仍然正确 + if (wasCompressed) { + nextTick(() => { + const idx = fileList.value.findIndex(f => f.uid === file.uid) + if (idx !== -1 && fileList.value[idx].name !== finalFileName) { + fileList.value[idx] = { ...fileList.value[idx], name: finalFileName } + console.log('[文件上传] nextTick 强制更新文件名为:', finalFileName) + } + }) + } + message.success(wasCompressed ? '文件压缩并上传成功' : '文件上传成功') } else { throw new Error('上传失败:未返回文件URL')