From 9b15b4c7e5fb8f280436b7bd17df19c356636058 Mon Sep 17 00:00:00 2001 From: "2358328281@qq.com" <邮箱地址> Date: Sat, 20 Jun 2026 21:17:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E5=AE=BD=E4=BF=AE=E6=94=B9=20pdf=20?= =?UTF-8?q?=E5=92=8C=E5=9B=BE=E7=89=87=20=E9=A2=84=E8=A7=88=20=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/admin/hospitals/list.vue | 18 ++++---- src/views/admin/orders/detail.vue | 71 +++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 20 deletions(-) diff --git a/src/views/admin/hospitals/list.vue b/src/views/admin/hospitals/list.vue index ed7c42f..6295a57 100644 --- a/src/views/admin/hospitals/list.vue +++ b/src/views/admin/hospitals/list.vue @@ -34,17 +34,17 @@ - - - - - + + + + + {{ formatUsageYears(row.signDate) }} - + — - + {{ formatDate(row.signDate) }} - + {{ formatDate(row.maintenanceEnd) }} diff --git a/src/views/admin/orders/detail.vue b/src/views/admin/orders/detail.vue index 5f7a90a..9986063 100644 --- a/src/views/admin/orders/detail.vue +++ b/src/views/admin/orders/detail.vue @@ -48,7 +48,7 @@ link type="primary" class="file-item" - @click="viewReport(f.filePath)" + @click="viewReport(f.filePath, f.fileName)" > {{ f.fileName }} @@ -59,13 +59,13 @@ {{ $t('orderDetail.statusChange') }} - {{ log.action }} · {{ log.operator }} - {{ log.remark }} + {{ log.toStatus }} · {{ log.operator }} + @@ -80,10 +80,15 @@ :before-close="closePreview" > + @@ -118,12 +123,14 @@ const goProcess = () => router.push(`/admin/orders/process/${route.params.id}`); const previewVisible = ref(false); const previewUrl = ref(""); +const previewType = ref(""); // 'pdf' | 'image' | '' const cleanupPreviewUrl = () => { if (previewUrl.value) { URL.revokeObjectURL(previewUrl.value); previewUrl.value = ""; } + previewType.value = ""; }; const closePreview = () => { @@ -131,14 +138,49 @@ const closePreview = () => { cleanupPreviewUrl(); }; -const viewReport = async (attachmentPath) => { +// 根据文件名/扩展名+blob 的 mime 判断文件类型 +const getFileType = (fileName, blob) => { + const name = String(fileName || ""); + const ext = name.split(".").pop()?.toLowerCase() || ""; + const mime = blob?.type || ""; + if (ext === "pdf" || mime === "application/pdf") return "pdf"; + if ( + ["jpg", "jpeg", "png", "gif", "bmp", "webp", "svg"].includes(ext) || + (mime && mime.startsWith("image/")) + ) { + return "image"; + } + return "other"; +}; + +// 浏览器直接下载 blob +const downloadBlob = (blob, fileName) => { + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = fileName || "download"; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + setTimeout(() => URL.revokeObjectURL(url), 0); +}; + +const viewReport = async (attachmentPath, originalName) => { if (!attachmentPath) return; - const fileName = String(attachmentPath); + const path = String(attachmentPath); + // 优先用原始文件名作为下载名,没有则回退到路径 + const downloadName = originalName || path; try { - const blob = await getUploadFile(fileName); - cleanupPreviewUrl(); - previewUrl.value = URL.createObjectURL(blob); - previewVisible.value = true; + const blob = await getUploadFile(path); + const type = getFileType(downloadName, blob); + if (type === "pdf" || type === "image") { + cleanupPreviewUrl(); + previewUrl.value = URL.createObjectURL(blob); + previewType.value = type; + previewVisible.value = true; + } else { + downloadBlob(blob, downloadName); + } } catch (e) { ElMessage.error(e?.message || $t('msg.failed')); } @@ -205,4 +247,11 @@ onMounted(loadDetail); height: 80vh; border: 0; } +.preview-image { + display: block; + max-width: 100%; + max-height: 80vh; + margin: 0 auto; + object-fit: contain; +}