From df982f1554a029a57b0b21ecaa740233cab09a9d Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期二, 07 四月 2026 15:57:57 +0800
Subject: [PATCH] fix(FileUpload/ImageUpload): 修复上传组件文件名显示和模型值格式问题

---
 src/components/ImageUpload/index.vue                    |   32 +++++++++++++++++---------------
 src/components/FileUpload/index.vue                     |   11 ++++++++---
 src/views/collaborativeApproval/knowledgeBase/index.vue |   16 ++++++++--------
 3 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/src/components/FileUpload/index.vue b/src/components/FileUpload/index.vue
index 57e62b7..3300aaa 100644
--- a/src/components/FileUpload/index.vue
+++ b/src/components/FileUpload/index.vue
@@ -100,7 +100,12 @@
       // 鐒跺悗灏嗘暟缁勮浆涓哄璞℃暟缁�
       fileList.value = list.map((item) => {
         if (typeof item === "string") {
-          item = { name: item, url: item };
+          item = { name: getFileName(item), url: item };
+        } else {
+          item = { ...item };
+          if (!item.name) {
+            item.name = getFileName(item.url || item.name || "");
+          }
         }
         item.uid = item.uid || new Date().getTime() + temp++;
         return item;
@@ -184,7 +189,7 @@
       .concat(uploadList.value);
     uploadList.value = [];
     number.value = 0;
-    emit("update:modelValue", listToString(fileList.value));
+    emit("update:modelValue", fileList.value);
     proxy.$modal.closeLoading();
   }
 }
@@ -221,7 +226,7 @@
         onEnd: (evt) => {
           const movedItem = fileList.value.splice(evt.oldIndex, 1)[0];
           fileList.value.splice(evt.newIndex, 0, movedItem);
-          emit("update:modelValue", listToString(fileList.value));
+          emit("update:modelValue", fileList.value);
         },
       });
     });
diff --git a/src/components/ImageUpload/index.vue b/src/components/ImageUpload/index.vue
index 9670c72..3aa7b81 100644
--- a/src/components/ImageUpload/index.vue
+++ b/src/components/ImageUpload/index.vue
@@ -112,10 +112,15 @@
       // 鐒跺悗灏嗘暟缁勮浆涓哄璞℃暟缁�
       fileList.value = list.map((item) => {
         if (typeof item === "string") {
-          if (item.indexOf(baseUrl) === -1 && !isExternal(item)) {
-            item = { name: baseUrl + item, url: baseUrl + item };
-          } else {
-            item = { name: item, url: item };
+          const url =
+            item.indexOf(baseUrl) === -1 && !isExternal(item)
+              ? baseUrl + item
+              : item;
+          item = { name: getFileName(url), url };
+        } else {
+          item = { ...item };
+          if (!item.name) {
+            item.name = getFileName(item.url || item.name || "");
           }
         }
         return item;
@@ -189,7 +194,7 @@
   const findex = fileList.value.map((f) => f.name).indexOf(file.name);
   if (findex > -1 && uploadList.value.length === number.value) {
     fileList.value.splice(findex, 1);
-    emit("update:modelValue", listToString(fileList.value));
+    emit("update:modelValue", fileList.value);
     return false;
   }
 }
@@ -202,7 +207,7 @@
       .concat(uploadList.value);
     uploadList.value = [];
     number.value = 0;
-    emit("update:modelValue", listToString(fileList.value));
+    emit("update:modelValue", fileList.value);
     proxy.$modal.closeLoading();
   }
 }
@@ -219,16 +224,13 @@
   dialogVisible.value = true;
 }
 
-// 瀵硅薄杞垚鎸囧畾瀛楃涓插垎闅�
-function listToString(list, separator) {
-  let strs = "";
-  separator = separator || ",";
-  for (let i in list) {
-    if (undefined !== list[i].url && list[i].url.indexOf("blob:") !== 0) {
-      strs += list[i].url.replace(baseUrl, "") + separator;
-    }
+// 鑾峰彇鏂囦欢鍚�
+function getFileName(name) {
+  if (!name) return "";
+  if (name.lastIndexOf("/") > -1) {
+    return name.slice(name.lastIndexOf("/") + 1);
   }
-  return strs != "" ? strs.substr(0, strs.length - 1) : "";
+  return name;
 }
 
 // 鍒濆鍖栨嫋鎷芥帓搴�
diff --git a/src/views/collaborativeApproval/knowledgeBase/index.vue b/src/views/collaborativeApproval/knowledgeBase/index.vue
index 0c1e44d..236962c 100644
--- a/src/views/collaborativeApproval/knowledgeBase/index.vue
+++ b/src/views/collaborativeApproval/knowledgeBase/index.vue
@@ -133,7 +133,7 @@
             </el-form-item>
           </el-col>
         </el-row>
-        <el-form-item label="闄勪欢鏉愭枡" prop="tempFileIds">
+        <el-form-item label="闄勪欢鏉愭枡" prop="files">
           <el-upload
             v-model:file-list="fileList"
             :action="upload.url"
@@ -318,7 +318,7 @@
     keyPoints: "",
     creator: "",
     usageCount: 0,
-    tempFileIds: []
+    files: []
   },
   dialogVisible: false,
   dialogTitle: "",
@@ -516,7 +516,7 @@
       keyPoints: "",
       creator: userStore.nickName || "",
       usageCount: 0,
-      tempFileIds: []
+      files: []
     });
   } else if (type === "edit" && row) {
     dialogTitle.value = "缂栬緫鐭ヨ瘑";
@@ -532,7 +532,7 @@
       keyPoints: row.keyPoints,
       creator: row.creator,
       usageCount: row.usageCount,
-      tempFileIds: (row.commonFileList || []).map(file => file.id)
+      files: row.commonFileList || []
     });
   }
   dialogVisible.value = true;
@@ -636,7 +636,7 @@
     keyPoints: "",
     creator: userStore.nickName || "",
     usageCount: 0,
-    tempFileIds: []
+    files: []
   });
   // 娓呴櫎琛ㄥ崟楠岃瘉鐘舵��
   if (formRef.value) {
@@ -670,10 +670,10 @@
 function handleUploadSuccess(res, file, uploadFiles) {
   proxy.$modal.closeLoading();
   if (res.code === 200) {
-    if (!form.value.tempFileIds) {
-      form.value.tempFileIds = [];
+    if (!form.value.files) {
+      form.value.files = [];
     }
-    form.value.tempFileIds.push(res.data.tempId);
+    form.value.files.push({url:res.data.tempPath,name:res.data.originalName});
     proxy.$modal.msgSuccess("涓婁紶鎴愬姛");
   } else {
     proxy.$modal.msgError(res.msg);

--
Gitblit v1.9.3