From 5df6d6cd93ed5655065652a008189d1630fbfeab Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期四, 29 十月 2026 16:34:34 +0800
Subject: [PATCH] change

---
 src/components/FileUpload/index.vue |   75 ++++++++++++++++++++++++-------------
 1 files changed, 49 insertions(+), 26 deletions(-)

diff --git a/src/components/FileUpload/index.vue b/src/components/FileUpload/index.vue
index 57e62b7..242b485 100644
--- a/src/components/FileUpload/index.vue
+++ b/src/components/FileUpload/index.vue
@@ -1,6 +1,6 @@
 <template>
   <div class="upload-file">
-    <el-upload multiple :action="uploadFileUrl" :before-upload="handleBeforeUpload" :file-list="fileList" :data="data"
+    <el-upload multiple :action="uploadFileUrl" name="files" :before-upload="handleBeforeUpload" :file-list="fileList" :data="data"
       :limit="limit" :on-error="handleUploadError" :on-exceed="handleExceed" :on-success="handleUploadSuccess"
       :show-file-list="false" :headers="headers" class="upload-file-uploader" ref="fileUpload" v-if="!disabled">
       <!-- 涓婁紶鎸夐挳 -->
@@ -18,9 +18,9 @@
       鐨勬枃浠�
     </div>
     <!-- 鏂囦欢鍒楄〃 -->
-    <transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul">
+    <transition-group ref="uploadListRef" class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul">
       <li :key="file.uid" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in fileList">
-        <el-link :href="`${baseUrl}${file.url}`" :underline="false" target="_blank">
+        <el-link :href="getFileUrl(file.url)" :underline="false" target="_blank">
           <span class="el-icon-document"> {{ getFileName(file.name) }} </span>
         </el-link>
         <div class="ele-upload-list__item-content-action">
@@ -81,7 +81,8 @@
 const { proxy } = getCurrentInstance();
 const emit = defineEmits();
 const number = ref(0);
-const uploadList = ref([]);
+const uploadList = ref([]);
+const uploadListRef = ref();
 const baseUrl = import.meta.env.VITE_APP_BASE_API;
 const uploadFileUrl = ref(import.meta.env.VITE_APP_BASE_API + props.action); // 涓婁紶鏂囦欢鏈嶅姟鍣ㄥ湴鍧�
 const headers = ref({ Authorization: "Bearer " + getToken() });
@@ -95,8 +96,20 @@
   (val) => {
     if (val) {
       let temp = 1;
-      // 棣栧厛灏嗗�艰浆涓烘暟缁�
-      const list = Array.isArray(val) ? val : props.modelValue.split(",");
+      let list = [];
+      if (Array.isArray(val)) {
+        list = val;
+      } else if (typeof val === "string" && val.trim().startsWith("[")) {
+        // 鍚庣杩斿洖/鍓嶇淇濆瓨鐨� JSON 鏁扮粍鏍煎紡锛歔{ id, name, url }]
+        try {
+          const parsed = JSON.parse(val);
+          list = Array.isArray(parsed) ? parsed : [];
+        } catch (e) {
+          list = val.split(",");
+        }
+      } else {
+        list = String(val).split(",");
+      }
       // 鐒跺悗灏嗘暟缁勮浆涓哄璞℃暟缁�
       fileList.value = list.map((item) => {
         if (typeof item === "string") {
@@ -158,13 +171,21 @@
 
 // 涓婁紶鎴愬姛鍥炶皟
 function handleUploadSuccess(res, file) {
-  if (res.code === 200) {
-    uploadList.value.push({ name: res.fileName, url: res.fileName });
+  // 鍚庣 /common/upload 杩斿洖 { code, msg, data: [ { id, name, url, downloadURL ... } ] }
+  const list = Array.isArray(res?.data) ? res.data : [];
+  if (res?.code === 200 && list.length > 0) {
+    list.forEach((item) => {
+      uploadList.value.push({
+        id: item.id ?? item.storageAttachmentId,
+        name: item.name || item.originalFilename || item.fileName || file.name,
+        url: item.url || item.downloadURL || item.previewURL || item.previewUrl || "",
+      });
+    });
     uploadedSuccessfully();
   } else {
     number.value--;
     proxy.$modal.closeLoading();
-    proxy.$modal.msgError(res.msg);
+    proxy.$modal.msgError(res?.msg || "涓婁紶鏂囦欢澶辫触");
     proxy.$refs.fileUpload.handleRemove(file);
     uploadedSuccessfully();
   }
@@ -190,33 +211,35 @@
 }
 
 // 鑾峰彇鏂囦欢鍚嶇О
-function getFileName(name) {
+function getFileName(name) {
   // 濡傛灉鏄痷rl閭d箞鍙栨渶鍚庣殑鍚嶅瓧 濡傛灉涓嶆槸鐩存帴杩斿洖
   if (name.lastIndexOf("/") > -1) {
     return name.slice(name.lastIndexOf("/") + 1);
   } else {
     return name;
   }
-}
+}
+
+function getFileUrl(url) {
+  if (!url) return "";
+  return /^https?:\/\//i.test(url) ? url : `${baseUrl}${url}`;
+}
 
-// 瀵硅薄杞垚鎸囧畾瀛楃涓插垎闅�
-function listToString(list, separator) {
-  let strs = "";
-  separator = separator || ",";
-  for (let i in list) {
-    if (list[i].url) {
-      strs += list[i].url + separator;
-    }
-  }
-  return strs != "" ? strs.substr(0, strs.length - 1) : "";
+// 瀵硅薄杞垚 JSON 鏁扮粍瀛楃涓诧紝淇濆瓨鏂囦欢 id銆佸悕绉颁笌鍦板潃
+function listToString(list) {
+  const files = (list || [])
+    .filter((item) => item && item.url)
+    .map((item) => ({ id: item.id, name: item.name, url: item.url }));
+  return files.length > 0 ? JSON.stringify(files) : "";
 }
 
 // 鍒濆鍖栨嫋鎷芥帓搴�
-onMounted(() => {
-  if (props.drag) {
-    nextTick(() => {
-      const element = document.querySelector(".upload-file-list");
-      Sortable.create(element, {
+onMounted(() => {
+  if (props.drag && !props.disabled) {
+    nextTick(() => {
+      const element = uploadListRef.value?.$el || uploadListRef.value;
+      if (!element) return;
+      Sortable.create(element, {
         ghostClass: "file-upload-darg",
         onEnd: (evt) => {
           const movedItem = fileList.value.splice(evt.oldIndex, 1)[0];

--
Gitblit v1.9.3