diff --git a/frontend/src/pages/admin/CreateProductDialog.tsx b/frontend/src/pages/admin/CreateProductDialog.tsx index e128e10..ebda308 100644 --- a/frontend/src/pages/admin/CreateProductDialog.tsx +++ b/frontend/src/pages/admin/CreateProductDialog.tsx @@ -289,57 +289,42 @@ export default function CreateProductDialog({ open, onClose, onCreated }: Props) // ============================================================ function printCurrentQRCode() { - if (!createdSn) return; - const qrUrl = `/api/v1/products/qrcode/${createdSn}`; - const productName = selected?.material_name ?? ""; - const spec = selected?.spec_model ?? ""; - const orderNo2 = orderNo || "—"; - const printWindow = window.open("", "_blank", "width=420,height=480"); - if (!printWindow) return; - printWindow.document.write(` + const printArea = document.getElementById("label-print-area"); + if (!printArea) return; + const printContent = printArea.innerHTML; + + const styles = Array.from(document.querySelectorAll("style, link[rel=\"stylesheet\"]")) + .map(el => el.outerHTML) + .join(""); + + const iframe = document.createElement("iframe"); + iframe.style.position = "absolute"; + iframe.style.width = "0"; + iframe.style.height = "0"; + iframe.style.border = "none"; + document.body.appendChild(iframe); + + const doc = iframe.contentWindow!.document; + doc.write(` + - - 打印标签 - ${createdSn} + 打印标签${styles} - - - +
${printContent}
`); - printWindow.document.close(); + doc.close(); + + iframe.contentWindow!.onload = () => { + iframe.contentWindow!.focus(); + iframe.contentWindow!.print(); + setTimeout(() => { document.body.removeChild(iframe); }, 1000); + }; } // ============================================================ @@ -358,7 +343,7 @@ export default function CreateProductDialog({ open, onClose, onCreated }: Props) {createdSn ? ( /* ---- 成功页 ---- */
-
+
QR