From e86cae8515e950b07f88de875346fe45e816209d Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Wed, 24 Dec 2025 15:56:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/ImagePreview/index.vue | 32 +++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/web/src/components/ImagePreview/index.vue b/web/src/components/ImagePreview/index.vue index 679000da..fcb44263 100644 --- a/web/src/components/ImagePreview/index.vue +++ b/web/src/components/ImagePreview/index.vue @@ -231,11 +231,33 @@ const getUrlsByDirectUrls = async (urls: string[]): Promise => { 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); } }