| | |
| | | } |
| | | |
| | | const { openPreview, previewState } = useFilePreview(); |
| | | const previewLoading = ref(false); |
| | | |
| | | /** 处理文件预览 */ |
| | | async function handlePreview(file: UploadFile) { |
| | |
| | | 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); |
| | | } |
| | | |
| | | /** 处理文件数量超限 */ |