From dd54e047dd5797367dcdb88f6499f096e0631d75 Mon Sep 17 00:00:00 2001 From: DXC Date: Tue, 21 Apr 2026 14:35:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(outbound):=20=E9=87=8D=E6=9E=84confirmPrint?= =?UTF-8?q?=E4=B8=BAiframe=E6=89=93=E5=8D=B0=E6=A8=A1=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E5=BD=BB=E5=BA=95=E7=B2=89=E7=A2=8E=E5=85=A8=E5=B1=80CSS?= =?UTF-8?q?=E9=AB=98=E5=BA=A6=E9=94=81=E6=AD=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/outbound/Selection.vue | 91 ++++++++++++++++++- 1 file changed, 88 insertions(+), 3 deletions(-) diff --git a/inventory-web/src/views/outbound/Selection.vue b/inventory-web/src/views/outbound/Selection.vue index 2b31f70..55361a6 100644 --- a/inventory-web/src/views/outbound/Selection.vue +++ b/inventory-web/src/views/outbound/Selection.vue @@ -794,6 +794,15 @@ const handlePreview = () => { previewVisible.value = true } +// 创建隐藏 iframe 用于打印 +const printFrame = document.createElement('iframe'); +printFrame.style.position = 'absolute'; +printFrame.style.width = '0'; +printFrame.style.height = '0'; +printFrame.style.border = '0'; +document.body.appendChild(printFrame); +const iframeDoc = printFrame.contentWindow.document; + const confirmPrint = async () => { previewVisible.value = false; // 记录日志 @@ -804,9 +813,85 @@ const confirmPrint = async () => { printSelectionList(JSON.parse(JSON.stringify(payload))).catch(() => {}); } catch (e) {} - setTimeout(() => { - window.print(); - }, 300); + // 获取 #print-area 元素和当前 computed 样式 + const printElement = document.getElementById('print-area'); + if (!printElement) return; + const styles = Array.from(document.styleSheets) + .filter(sheet => { + try { return !sheet.href || sheet.href.indexOf(window.location.host) !== -1; } catch { return false; } + }) + .map(sheet => { + try { + return Array.from(sheet.cssRules).map(rule => rule.cssText).join('\n'); + } catch { return ''; } + }).join('\n'); + + // 4. 将提取的样式和要打印的 HTML 写入 iframe + iframeDoc.open(); + iframeDoc.write(` + + + + IRIS出库拣货确认单 + ${styles} + + + + ${printElement.outerHTML} + + + `); + iframeDoc.close(); + + // 等 iframe 加载完毕后触发打印 + printFrame.onload = () => { + printFrame.contentWindow.focus(); + printFrame.contentWindow.print(); + }; } const confirmExport = () => {