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 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
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;
}
// 鍒濆鍖栨嫋鎷芥帓搴�
--
Gitblit v1.9.3