Files
lilishop-ui/seller/src/utils/print.js
lifenlong 832fda813b 升级Vue3,iView替换ElementPlus
- 删除babel配置、更新依赖与入口初始化
- 全量替换UI组件、样式适配,新增迁移文档与标签/过滤器自动化替换脚本
2026-06-05 17:49:43 +08:00

27 lines
932 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 打印指定 DOM 区域(替代 vue-print-nb
*/
export function printElement(elementId, title = "打印") {
const el = document.getElementById(elementId);
if (!el) {
console.warn(`[print] element #${elementId} not found`);
return;
}
const iframe = document.createElement("iframe");
iframe.style.cssText = "position:fixed;right:0;bottom:0;width:0;height:0;border:0";
document.body.appendChild(iframe);
const doc = iframe.contentWindow.document;
doc.open();
doc.write(
`<!DOCTYPE html><html><head><title>${title}</title><style>
body{font-family:Arial,sans-serif;padding:12px;color:#333}
table{width:100%;border-collapse:collapse}
td,th{border:1px solid #ddd;padding:6px}
</style></head><body>${el.innerHTML}</body></html>`
);
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();
setTimeout(() => document.body.removeChild(iframe), 1000);
}