zlwu há 10 meses atrás
pai
commit
e86cae8515
1 ficheiros alterados com 27 adições e 5 exclusões
  1. 27 5
      web/src/components/ImagePreview/index.vue

+ 27 - 5
web/src/components/ImagePreview/index.vue

@@ -231,11 +231,33 @@ const getUrlsByDirectUrls = async (urls: string[]): Promise<string[]> => {
   const blobUrls: string[] = [];
 
   for (const url of urls) {
-    if (url.trim()) {
-      const blobUrl = await getImageBlobUrl(url.trim());
-      if (blobUrl) {
-        blobUrls.push(blobUrl);
-      }
+    if (!url.trim()) {
+      continue;
+    }
+    const u = url.trim();
+
+    // 如果已经是 blob / data URL,直接使用
+    if (u.startsWith('blob:') || u.startsWith('data:')) {
+      blobUrls.push(u);
+      continue;
+    }
+
+    // 如果是本地静态资源(例如 Vite 打包的 /src 或 assets 路径),或者是绝对路径但不是受保护的下载接口,
+    // 直接使用 URL,不经由带认证的请求去获取(避免对静态资源发带 token 的 XHR 导致失败)
+    const isHttp = /^https?:\/\//i.test(u);
+    const isProtectedDownload = u.startsWith('/resource/oss/download/');
+    const isLocalAsset = u.startsWith('/src') || u.startsWith('/assets') || (u.startsWith('/') && !isProtectedDownload && !isHttp);
+
+    if (isLocalAsset || isHttp) {
+      // 对于 http(s) 链接直接使用原始 URL(多数第三方/公开图片可直接加载)
+      blobUrls.push(u);
+      continue;
+    }
+
+    // 对于受保护的资源或需认证获取的场景,使用认证请求获取 blob 并创建 blob URL
+    const blobUrl = await getImageBlobUrl(u);
+    if (blobUrl) {
+      blobUrls.push(blobUrl);
     }
   }