xuzhancheng 1 napja
szülő
commit
b0612d23e8

+ 19 - 4
yudao-ui-admin-vue3/src/components/DynamicReport/BatchUploadFile.vue

@@ -54,14 +54,29 @@ const handleTemplateImage = async () => {
 }
 const handleApply = async (file) => {
   // file.url 可能是已处理过的完整 URL(来自 CustomUploadFile 单独"应用"),也可能是原始路径(来自"一键应用")
-  const url = /^https?:\/\//.test(file.url) ? file.url : buildFileUrl(file.url)
+  const isFullUrl = /^https?:\/\//.test(file.url)
+  const url = isFullUrl ? file.url : buildFileUrl(file.url)
   const base = await urlToBase64(url)
-  let path = props.colList.find(item => item.colCode === "Illustration").colCode
+
+  // 提取相对路径用于存储(name.url 应始终存相对路径,而非完整 URL)
+  let filePath = file.url
+  if (isFullUrl) {
+    // 使用与 buildFileUrl 相同的基础 URL 来还原相对路径
+    const baseUrl = import.meta.env.VITE_FILE_URL || ''
+    const urlObj = new URL(file.url)
+    // 兼容 baseUrl 可能不含协议的情况(如 192.168.0.53:9110/dexdev)
+    const baseUrlWithProtocol = /^https?:\/\//.test(baseUrl) ? baseUrl : `https://${baseUrl}`
+    const basePathname = new URL(baseUrlWithProtocol).pathname.replace(/\/$/, '')
+    // 去掉基础路径前缀,得到纯文件路径
+    filePath = urlObj.pathname.replace(new RegExp(`^${basePathname}/?`), '')
+  }
+
+  let path = props.colList.find(item => item.colCode === "Illustration")?.colCode
   if (!path) {
-    path = props.colList[0].colCode
+    path = props.colList[0]?.colCode
   }
   const name = {
-    url: file.url,
+    url: filePath,
     path: path,
     x: 100,
     y: 50,