From 70c406afc71db3ac46d52d8bba0f1f9e54cd61ed Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Wed, 14 Jan 2026 15:20:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=96=87=E4=BB=B6pdf?= =?UTF-8?q?=E5=92=8C=E5=9B=BE=E7=89=87=E6=94=AF=E6=8C=81=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=20=20world=E5=92=8Cexcle=E4=B8=8D=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/file/list.vue | 59 ++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/src/components/file/list.vue b/src/components/file/list.vue index 3d45a91..dac519e 100644 --- a/src/components/file/list.vue +++ b/src/components/file/list.vue @@ -205,18 +205,18 @@
- - - - - - - - - - - - + + + 下载文件 + + + + 打印文件 +
@@ -257,6 +257,39 @@ let initialX = 0; let initialY = 0; const fileRrror = ref(false); const tableDatas = ref([]) + +function canPrint(file) { + if (!file?.fileName) return false + const type = getFileType(file.fileName) + return type === FileType.IMG || type === FileType.PDF +} + +function handlePrintnew() { + const file = activeFile.value + if (!file) return + + // 1️⃣ 不支持打印 + if (!canPrint(file)) { + ElMessage.warning('该文件格式不支持打印,请下载后打印') + downloadFile(file) + return + } + + // 2️⃣ 图片:直接打印当前预览区域 + if (getFileType(file.fileName) === FileType.IMG) { + window.print() + return + } + + // 3️⃣ PDF:新窗口打开再打印(最稳定) + if (getFileType(file.fileName) === FileType.PDF) { + const url = `${BASE_PATH}/file/stream/${file.filePath}` + const win = window.open(url) + win && win.print() + } +} + + function filePreview(file) { preview.value = true; activeFile.value = file; @@ -265,7 +298,7 @@ function filePreview(file) { translateX.value = 0; translateY.value = 0; moveFlag = false; - downloadFile(file) + // downloadFile(file) // if (!file?.filePath) { // ElMessage?.warning?.('文件路径不存在,无法下载') // return