gaoluyang
2026-08-06 d2f6dac989a5f522c14b0243140d8f1639fed975
src/components/upload/file-upload.vue
@@ -143,7 +143,6 @@
}
const { openPreview, previewState } = useFilePreview();
const previewLoading = ref(false);
/** 处理文件预览 */
async function handlePreview(file: UploadFile) {
@@ -157,17 +156,16 @@
    window.open(url, '_blank');
    return;
  }
  previewLoading.value = true;
  try {
    const blob = await requestClient.get(url, { responseType: 'blob' }) as unknown as Blob;
    const blobUrl = URL.createObjectURL(blob);
    // 将绝对 URL 转为相对路径,走 Vite 代理避免跨域
    const path = typeof url === 'string' ? url.replace(/^https?:\/\/[^/]+/, '') : url;
    const blob = await requestClient.download(path);
    const blobUrl = URL.createObjectURL(blob as Blob);
    openPreview(blobUrl, name);
    emit('preview', file);
  } catch {
    message.error('文件加载失败,请尝试下载后查看');
  } finally {
    previewLoading.value = false;
    message.error('文件加载失败');
  }
  emit('preview', file);
}
/** 处理文件数量超限 */