feat: 全系统窗体升级 - 配置驱动通用单据页(BillPage)、原料专用单据页、宽屏弹窗及日期转换优化
This commit is contained in:
@@ -150,16 +150,31 @@ export function createHeadless(options: HeadlessOptions = {}): HeadlessInstance
|
||||
}
|
||||
}
|
||||
|
||||
/** 静默打印:瞬态 0 尺寸 iframe + srcdoc + window.print(),完成后立即移除 */
|
||||
/** 从渲染 HTML 中解析纸张尺寸(@page size 或 CSS 变量 --op-page-w/--op-page-h),默认 A4 */
|
||||
function parsePaperSize(html: string): { w: string; h: string } {
|
||||
const fromAtPage = html.match(/@page\s*{[^}]*size:\s*([\d.]+)mm\s+([\d.]+)mm/i)
|
||||
if (fromAtPage) return { w: `${fromAtPage[1]}mm`, h: `${fromAtPage[2]}mm` }
|
||||
const fromVars = html.match(/--op-page-w:\s*([\d.]+)mm[^}]*?--op-page-h:\s*([\d.]+)mm/i)
|
||||
if (fromVars) return { w: `${fromVars[1]}mm`, h: `${fromVars[2]}mm` }
|
||||
return { w: '210mm', h: '297mm' }
|
||||
}
|
||||
|
||||
/**
|
||||
* 静默打印:瞬态 iframe + srcdoc + window.print(),完成后立即移除。
|
||||
* 注意:iframe 必须带实际纸张尺寸并移出屏幕(不可 0×0,否则 Chrome/Edge
|
||||
* 打印对话框以 0 视口渲染,预览为空白),
|
||||
*/
|
||||
function silentPrint(html: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof document === 'undefined') {
|
||||
reject(new Error('silentPrint 需要浏览器环境'))
|
||||
return
|
||||
}
|
||||
const { w, h } = parsePaperSize(html)
|
||||
const iframe = document.createElement('iframe')
|
||||
iframe.setAttribute('aria-hidden', 'true')
|
||||
iframe.style.cssText = 'position:fixed;right:0;bottom:0;width:0;height:0;border:0;'
|
||||
// 移到屏幕外但保留纸张尺寸视口,保证打印对话框预览可见
|
||||
iframe.style.cssText = `position:fixed;left:-9999px;top:0;width:${w};height:${h};border:0;`
|
||||
let removed = false
|
||||
const cleanup = () => {
|
||||
if (removed) return
|
||||
|
||||
Reference in New Issue
Block a user