cmat 0.0.110 → 0.0.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -16,9 +16,40 @@ const PRINT_OVERRIDE_CSS = `
|
|
|
16
16
|
overflow: visible !important;
|
|
17
17
|
height: auto !important;
|
|
18
18
|
min-height: auto !important;
|
|
19
|
+
box-sizing: border-box !important;
|
|
19
20
|
-webkit-print-color-adjust: exact;
|
|
20
21
|
print-color-adjust: exact;
|
|
21
22
|
}
|
|
23
|
+
/* 打印内容主体:约束到页面宽度,防止子元素溢出 */
|
|
24
|
+
.cmat-print-body {
|
|
25
|
+
max-width: 100% !important;
|
|
26
|
+
box-sizing: border-box !important;
|
|
27
|
+
}
|
|
28
|
+
/* 打印内容 flex 容器 + 网格行:高度由内容决定,不拉伸超过内容 */
|
|
29
|
+
.cmat-print-body .flex.flex-col {
|
|
30
|
+
height: auto !important;
|
|
31
|
+
min-height: 0 !important;
|
|
32
|
+
flex: none !important;
|
|
33
|
+
}
|
|
34
|
+
.cmat-print-body .grid {
|
|
35
|
+
height: auto !important;
|
|
36
|
+
min-height: 0 !important;
|
|
37
|
+
}
|
|
38
|
+
/* 报表渲染器宿主 + 网格子元素:允许跨页分割,防止内容被整体推到下一页 */
|
|
39
|
+
.cmat-print-body app-chart-renderer,
|
|
40
|
+
.cmat-print-body app-table-renderer,
|
|
41
|
+
.cmat-print-body app-text-renderer {
|
|
42
|
+
break-inside: auto !important;
|
|
43
|
+
margin: 0 !important;
|
|
44
|
+
}
|
|
45
|
+
.cmat-print-body .grid > [class*="col-span"] {
|
|
46
|
+
break-inside: auto !important;
|
|
47
|
+
}
|
|
48
|
+
/* 隐藏 ECharts 交互层:tooltip、axis-pointer 等悬浮 DOM */
|
|
49
|
+
.cmat-print-body .el-tooltip__popper,
|
|
50
|
+
.cmat-print-body [style*="pointer-events"] {
|
|
51
|
+
display: none !important;
|
|
52
|
+
}
|
|
22
53
|
|
|
23
54
|
/* 页眉页脚 */
|
|
24
55
|
.cmat-print-header {
|
|
@@ -62,6 +93,7 @@ const PRINT_OVERRIDE_CSS = `
|
|
|
62
93
|
overflow: visible !important;
|
|
63
94
|
max-height: none !important;
|
|
64
95
|
height: auto !important;
|
|
96
|
+
flex: none !important;
|
|
65
97
|
}
|
|
66
98
|
|
|
67
99
|
.no-print, [data-print-exclude], .print\\:hidden {
|
|
@@ -305,6 +337,126 @@ const PRINT_OVERRIDE_CSS = `
|
|
|
305
337
|
display: block !important;
|
|
306
338
|
}
|
|
307
339
|
|
|
340
|
+
/* ─── 报表组件打印适配 ─── */
|
|
341
|
+
|
|
342
|
+
/* 报表渲染器组件宿主:Angular 自定义元素默认 display:inline,需强制 block + 100% 宽度以填满网格单元格 */
|
|
343
|
+
.cmat-print-body app-chart-renderer,
|
|
344
|
+
.cmat-print-body app-table-renderer,
|
|
345
|
+
.cmat-print-body app-text-renderer {
|
|
346
|
+
display: block !important;
|
|
347
|
+
width: 100% !important;
|
|
348
|
+
min-width: 0 !important;
|
|
349
|
+
box-sizing: border-box !important;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/* 报表主容器:解除滚动容器的固定高度约束 + 阻止 flex 拉伸 */
|
|
353
|
+
.cmat-print-body > main,
|
|
354
|
+
.cmat-print-body .overflow-y-auto,
|
|
355
|
+
.cmat-print-body .overflow-auto {
|
|
356
|
+
overflow: visible !important;
|
|
357
|
+
height: auto !important;
|
|
358
|
+
min-height: 0 !important;
|
|
359
|
+
max-height: none !important;
|
|
360
|
+
flex: none !important;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/* 报表行容器:恢复 flex gap-6 间距(gap 不在 computed style 内联列表中,需手动补回) */
|
|
364
|
+
.cmat-print-body .flex.flex-col.gap-6 {
|
|
365
|
+
gap: 1.5rem !important;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/* 报表网格:强制 12 列布局(不依赖媒体查询) */
|
|
369
|
+
.cmat-print-body .grid {
|
|
370
|
+
display: grid !important;
|
|
371
|
+
grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
|
|
372
|
+
gap: 0.75rem !important;
|
|
373
|
+
}
|
|
374
|
+
/* col-span 工具类覆盖(含响应式前缀) */
|
|
375
|
+
.cmat-print-body .grid > .col-span-1 { grid-column: span 1 / span 1 !important; }
|
|
376
|
+
.cmat-print-body .grid > .col-span-2 { grid-column: span 2 / span 2 !important; }
|
|
377
|
+
.cmat-print-body .grid > .col-span-3 { grid-column: span 3 / span 3 !important; }
|
|
378
|
+
.cmat-print-body .grid > .col-span-4 { grid-column: span 4 / span 4 !important; }
|
|
379
|
+
.cmat-print-body .grid > .col-span-6 { grid-column: span 6 / span 6 !important; }
|
|
380
|
+
.cmat-print-body .grid > .col-span-12 { grid-column: span 12 / span 12 !important; }
|
|
381
|
+
/* Tailwind 响应式前缀 md:/lg: 的 col-span 类 */
|
|
382
|
+
.cmat-print-body .grid > [class*="\\:col-span-4"] { grid-column: span 4 / span 4 !important; }
|
|
383
|
+
.cmat-print-body .grid > [class*="\\:col-span-6"] { grid-column: span 6 / span 6 !important; }
|
|
384
|
+
.cmat-print-body .grid > [class*="\\:col-span-12"] { grid-column: span 12 / span 12 !important; }
|
|
385
|
+
|
|
386
|
+
/* 报表图表:限制打印高度,为表格留出空间 */
|
|
387
|
+
.cmat-print-body .chart-container {
|
|
388
|
+
overflow: hidden !important;
|
|
389
|
+
break-inside: avoid;
|
|
390
|
+
max-height: 100mm !important;
|
|
391
|
+
}
|
|
392
|
+
.cmat-print-body .chart-canvas {
|
|
393
|
+
overflow: hidden !important;
|
|
394
|
+
height: auto !important;
|
|
395
|
+
max-height: 95mm !important;
|
|
396
|
+
}
|
|
397
|
+
/* ECharts 渲染容器 div:约束到父级宽度,防止固定像素内联样式溢出 */
|
|
398
|
+
.cmat-print-body .chart-canvas > div {
|
|
399
|
+
max-width: 100% !important;
|
|
400
|
+
box-sizing: border-box !important;
|
|
401
|
+
}
|
|
402
|
+
.cmat-print-body .chart-canvas img {
|
|
403
|
+
max-width: 100% !important;
|
|
404
|
+
height: auto !important;
|
|
405
|
+
display: block !important;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/* 报表表格容器:移除 overflow 和 max-height 约束 + 约束到页面宽度 */
|
|
409
|
+
.cmat-print-body .table-container {
|
|
410
|
+
overflow: visible !important;
|
|
411
|
+
height: auto !important;
|
|
412
|
+
max-height: none !important;
|
|
413
|
+
min-height: 0 !important;
|
|
414
|
+
max-width: 100% !important;
|
|
415
|
+
box-sizing: border-box !important;
|
|
416
|
+
break-inside: auto !important;
|
|
417
|
+
}
|
|
418
|
+
.cmat-print-body .table-wrapper {
|
|
419
|
+
overflow: visible !important;
|
|
420
|
+
max-height: none !important;
|
|
421
|
+
height: auto !important;
|
|
422
|
+
max-width: 100% !important;
|
|
423
|
+
box-sizing: border-box !important;
|
|
424
|
+
break-inside: auto !important;
|
|
425
|
+
}
|
|
426
|
+
/* 报表表格:强制适应页面宽度,列均分 + 允许跨页分割 */
|
|
427
|
+
.cmat-print-body table[mat-table] {
|
|
428
|
+
width: 100% !important;
|
|
429
|
+
max-width: 100% !important;
|
|
430
|
+
table-layout: fixed !important;
|
|
431
|
+
font-size: 11px !important;
|
|
432
|
+
break-inside: auto !important;
|
|
433
|
+
}
|
|
434
|
+
/* 报表表格单元格:清除内联固定宽度,允许文字换行 */
|
|
435
|
+
.cmat-print-body table[mat-table] td,
|
|
436
|
+
.cmat-print-body table[mat-table] th {
|
|
437
|
+
width: auto !important;
|
|
438
|
+
word-break: break-word !important;
|
|
439
|
+
overflow-wrap: break-word !important;
|
|
440
|
+
white-space: normal !important;
|
|
441
|
+
padding: 4px 8px !important;
|
|
442
|
+
}
|
|
443
|
+
/* 报表表格 tbody:允许跨页分割 */
|
|
444
|
+
.cmat-print-body table[mat-table] tbody {
|
|
445
|
+
break-inside: auto !important;
|
|
446
|
+
display: table-row-group !important;
|
|
447
|
+
}
|
|
448
|
+
/* 报表表格行:防止单行被跨页截断 */
|
|
449
|
+
.cmat-print-body table[mat-table] tr[mat-row],
|
|
450
|
+
.cmat-print-body table[mat-table] tr[mat-row] td {
|
|
451
|
+
break-inside: avoid !important;
|
|
452
|
+
page-break-inside: avoid !important;
|
|
453
|
+
}
|
|
454
|
+
/* 隐藏报表分页组件 */
|
|
455
|
+
.cmat-print-body .pagination-wrapper,
|
|
456
|
+
.cmat-print-body cmat-pagination {
|
|
457
|
+
display: none !important;
|
|
458
|
+
}
|
|
459
|
+
|
|
308
460
|
|
|
309
461
|
`;
|
|
310
462
|
class CmatPrintService {
|
|
@@ -338,6 +490,73 @@ class CmatPrintService {
|
|
|
338
490
|
printHtml(html, options) {
|
|
339
491
|
this._print(html, options);
|
|
340
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* 调试模式:将生成的 HTML 在新标签页中打开,方便用 DevTools 检查布局
|
|
495
|
+
* 调用方式:this._printService.debugPrint(el, { title: '报表' })
|
|
496
|
+
*/
|
|
497
|
+
debugPrint(element, options) {
|
|
498
|
+
const clone = element.cloneNode(true);
|
|
499
|
+
this._syncFormValues(element, clone);
|
|
500
|
+
this._prepareForPrint(element, clone, options);
|
|
501
|
+
const contentHtml = clone.outerHTML;
|
|
502
|
+
const title = options?.title ?? '打印调试';
|
|
503
|
+
const orientation = options?.orientation ?? 'portrait';
|
|
504
|
+
const margins = options?.margins ?? { top: 15, right: 15, bottom: 15, left: 15 };
|
|
505
|
+
const marginStr = `${margins.top}mm ${margins.right}mm ${margins.bottom}mm ${margins.left}mm`;
|
|
506
|
+
const overrideCss = PRINT_OVERRIDE_CSS
|
|
507
|
+
.replace('var(--orientation)', orientation)
|
|
508
|
+
.replace('var(--margins)', marginStr);
|
|
509
|
+
// 关键:转换所有媒体查询,使 debug 标签页(screen 上下文)与实际打印(print 上下文)一致
|
|
510
|
+
// 1. @media screen → @media all(与实际打印一致)
|
|
511
|
+
// 2. @media print → @media all(让打印规则在 screen 中也生效)
|
|
512
|
+
const pageStyles = this._collectAllStyles()
|
|
513
|
+
.replace(/@media\s+print\s+and\s*\(/g, '@media (')
|
|
514
|
+
.replace(/@media\s+print\s*\{/g, '@media all {')
|
|
515
|
+
.replace(/@media\s+screen\s+and\s*\(/g, '@media (')
|
|
516
|
+
.replace(/@media\s+screen\s*\{/g, '@media all {')
|
|
517
|
+
.replace(/@media\s+only\s+screen\s+and\s*\(/g, '@media (')
|
|
518
|
+
.replace(/@media\s+only\s+screen\s*\{/g, '@media all {');
|
|
519
|
+
const cssVars = this._collectCssVariables();
|
|
520
|
+
const htmlClass = document.documentElement.className || 'light';
|
|
521
|
+
const bodyClass = this._getPrintBodyClass();
|
|
522
|
+
const fullHtml = `<!DOCTYPE html>
|
|
523
|
+
<html lang="zh-CN" class="${htmlClass}" style="${cssVars}">
|
|
524
|
+
<head>
|
|
525
|
+
<meta charset="utf-8">
|
|
526
|
+
<base href="${document.baseURI}">
|
|
527
|
+
<title>[DEBUG] ${this._escapeHtml(title)}</title>
|
|
528
|
+
${pageStyles}
|
|
529
|
+
<style>${overrideCss}${options?.customCss ?? ''}</style>
|
|
530
|
+
<style>
|
|
531
|
+
/* 调试模式专属:模拟 A4 页面宽度 */
|
|
532
|
+
body { background: #e0e0e0 !important; }
|
|
533
|
+
.cmat-debug-page {
|
|
534
|
+
max-width: 180mm;
|
|
535
|
+
margin-left: auto !important;
|
|
536
|
+
margin-right: auto !important;
|
|
537
|
+
background: #fff;
|
|
538
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
|
|
539
|
+
padding: ${margins.top}mm ${margins.right}mm ${margins.bottom}mm ${margins.left}mm;
|
|
540
|
+
min-height: 297mm;
|
|
541
|
+
}
|
|
542
|
+
</style>
|
|
543
|
+
</head>
|
|
544
|
+
<body class="${bodyClass}">
|
|
545
|
+
<div style="background:#fff3cd;padding:8px 16px;text-align:center;font-size:14px;border-bottom:2px solid #ffc107;">
|
|
546
|
+
🔧 <strong>调试模式</strong> — 此页面为打印预览 HTML,可用 DevTools 检查元素。
|
|
547
|
+
按 Ctrl+P 可触发实际打印。
|
|
548
|
+
</div>
|
|
549
|
+
<div class="cmat-debug-page">
|
|
550
|
+
<div class="cmat-print-body">${contentHtml}</div>
|
|
551
|
+
</div>
|
|
552
|
+
</body>
|
|
553
|
+
</html>`;
|
|
554
|
+
const blob = new Blob([fullHtml], { type: 'text/html' });
|
|
555
|
+
const url = URL.createObjectURL(blob);
|
|
556
|
+
window.open(url, '_blank');
|
|
557
|
+
// 延迟释放,确保页面加载完成
|
|
558
|
+
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
|
559
|
+
}
|
|
341
560
|
// ─── 私有方法 ───────────────────────────────────────────────
|
|
342
561
|
/**
|
|
343
562
|
* 同步原始 DOM 中表单控件的当前值到克隆节点
|
|
@@ -392,6 +611,12 @@ class CmatPrintService {
|
|
|
392
611
|
_prepareForPrint(original, root, options) {
|
|
393
612
|
// 移除标记为不打印的元素
|
|
394
613
|
root.querySelectorAll('.print\\:hidden, [data-print-exclude]').forEach(el => el.remove());
|
|
614
|
+
// ── 移除 ECharts 交互层:tooltip、axis-pointer 等悬浮 DOM,打印时不应显示 ──
|
|
615
|
+
root.querySelectorAll('.el-tooltip__popper, [style*="pointer-events"]').forEach((el) => {
|
|
616
|
+
if (el.closest('.chart-container, .chart-canvas, [class*="echarts"]')) {
|
|
617
|
+
el.remove();
|
|
618
|
+
}
|
|
619
|
+
});
|
|
395
620
|
// 移除所有按钮(保留 form-field 前缀/后缀按钮、chip 内按钮和 slide-toggle 开关)
|
|
396
621
|
root.querySelectorAll('button').forEach((el) => {
|
|
397
622
|
const isPrefixSuffix = el.closest('.mat-mdc-form-field-icon-prefix, .mat-mdc-form-field-icon-suffix, ' +
|
|
@@ -402,6 +627,26 @@ class CmatPrintService {
|
|
|
402
627
|
el.remove();
|
|
403
628
|
}
|
|
404
629
|
});
|
|
630
|
+
// ── Canvas → Image:克隆不复制 canvas 位图,需转为 img 保留 ECharts 等图表内容 ──
|
|
631
|
+
const origCanvases = original.querySelectorAll('canvas');
|
|
632
|
+
const cloneCanvases = root.querySelectorAll('canvas');
|
|
633
|
+
origCanvases.forEach((origCanvas, i) => {
|
|
634
|
+
const cloneCanvas = cloneCanvases[i];
|
|
635
|
+
if (!cloneCanvas)
|
|
636
|
+
return;
|
|
637
|
+
try {
|
|
638
|
+
const dataUrl = origCanvas.toDataURL('image/png');
|
|
639
|
+
const img = document.createElement('img');
|
|
640
|
+
img.src = dataUrl;
|
|
641
|
+
img.style.width = '100%';
|
|
642
|
+
img.style.height = 'auto';
|
|
643
|
+
img.style.display = 'block';
|
|
644
|
+
cloneCanvas.parentNode?.replaceChild(img, cloneCanvas);
|
|
645
|
+
}
|
|
646
|
+
catch (e) {
|
|
647
|
+
console.warn('[CmatPrintService] Canvas 转图片失败:', e);
|
|
648
|
+
}
|
|
649
|
+
});
|
|
405
650
|
// ── Chips:移除删除按钮的内容(图标),保持 chip 布局 ──
|
|
406
651
|
root.querySelectorAll('.mat-mdc-chip-row button[matChipRemove]').forEach((btn) => {
|
|
407
652
|
btn.innerHTML = '';
|
|
@@ -414,6 +659,184 @@ class CmatPrintService {
|
|
|
414
659
|
});
|
|
415
660
|
// ── 复制关键元素的 computed style 为 inline style ──
|
|
416
661
|
this._inlineComputedStyles(original, root);
|
|
662
|
+
// ── 报表组件:在 computed style 复制后,用 DOM inline !important 强制修复 ──
|
|
663
|
+
// 根元素(通常是 <main>):解除滚动容器的固定高度约束 + 约束到页面宽度
|
|
664
|
+
root.style.setProperty('overflow', 'visible', 'important');
|
|
665
|
+
root.style.setProperty('height', 'auto', 'important');
|
|
666
|
+
root.style.setProperty('min-height', '0', 'important');
|
|
667
|
+
root.style.setProperty('max-height', 'none', 'important');
|
|
668
|
+
root.style.setProperty('max-width', '100%', 'important');
|
|
669
|
+
root.style.setProperty('box-sizing', 'border-box', 'important');
|
|
670
|
+
// 所有滚动容器:解除 overflow/height 约束,防止内容被裁切 + 阻止 flex 拉伸
|
|
671
|
+
root.querySelectorAll('[class*="overflow-y-auto"], [class*="overflow-auto"]').forEach((el) => {
|
|
672
|
+
el.style.setProperty('overflow', 'visible', 'important');
|
|
673
|
+
el.style.setProperty('height', 'auto', 'important');
|
|
674
|
+
el.style.setProperty('min-height', '0', 'important');
|
|
675
|
+
el.style.setProperty('max-height', 'none', 'important');
|
|
676
|
+
el.style.setProperty('flex', 'none', 'important');
|
|
677
|
+
});
|
|
678
|
+
// 外层 flex 容器:恢复 gap-6 间距 + 约束到页面宽度 + 清除 margin + 高度由内容决定
|
|
679
|
+
root.querySelectorAll('[class*="gap-6"]').forEach((el) => {
|
|
680
|
+
el.style.setProperty('gap', '1.5rem', 'important');
|
|
681
|
+
el.style.setProperty('max-width', '100%', 'important');
|
|
682
|
+
el.style.setProperty('margin', '0', 'important');
|
|
683
|
+
el.style.setProperty('box-sizing', 'border-box', 'important');
|
|
684
|
+
el.style.setProperty('height', 'auto', 'important');
|
|
685
|
+
el.style.setProperty('min-height', '0', 'important');
|
|
686
|
+
el.style.setProperty('flex', 'none', 'important');
|
|
687
|
+
});
|
|
688
|
+
// 网格容器:强制 12 列布局(inline !important 覆盖任何 computed style 内联值)
|
|
689
|
+
root.querySelectorAll('.grid').forEach((el) => {
|
|
690
|
+
// 只处理包含 col-span 子元素的网格(报表布局网格),避免影响其他网格
|
|
691
|
+
if (!el.querySelector('[class*="col-span"]'))
|
|
692
|
+
return;
|
|
693
|
+
el.style.setProperty('display', 'grid', 'important');
|
|
694
|
+
el.style.setProperty('grid-template-columns', 'repeat(12, minmax(0, 1fr))', 'important');
|
|
695
|
+
// 恢复 gap-3(gap 不在 _inlineComputedStyles 属性列表中,需手动补回)
|
|
696
|
+
el.style.setProperty('gap', '0.75rem', 'important');
|
|
697
|
+
// 重置网格行容器的固定高度 + 清除 margin + 高度由内容决定
|
|
698
|
+
el.style.setProperty('height', 'auto', 'important');
|
|
699
|
+
el.style.setProperty('min-height', '0', 'important');
|
|
700
|
+
el.style.setProperty('max-height', 'none', 'important');
|
|
701
|
+
el.style.setProperty('overflow', 'visible', 'important');
|
|
702
|
+
el.style.setProperty('max-width', '100%', 'important');
|
|
703
|
+
el.style.setProperty('margin', '0', 'important');
|
|
704
|
+
el.style.setProperty('box-sizing', 'border-box', 'important');
|
|
705
|
+
// 遍历子元素,根据 col-span 类名设置 grid-column
|
|
706
|
+
Array.from(el.children).forEach((child) => {
|
|
707
|
+
const childEl = child;
|
|
708
|
+
const classes = child.className || '';
|
|
709
|
+
// 提取最大的 col-span 值(优先 lg: > md: > 无后缀)
|
|
710
|
+
const lgMatch = /lg:col-span-(\d+)/.exec(classes);
|
|
711
|
+
const mdMatch = /md:col-span-(\d+)/.exec(classes);
|
|
712
|
+
const baseMatch = /(?:^|\s)col-span-(\d+)/.exec(classes);
|
|
713
|
+
let span = lgMatch?.[1] ?? mdMatch?.[1] ?? baseMatch?.[1];
|
|
714
|
+
// 图表容器:强制占满整行(A4 宽度不足以并排显示两个图表)
|
|
715
|
+
if (childEl.querySelector('.chart-container')) {
|
|
716
|
+
span = '12';
|
|
717
|
+
}
|
|
718
|
+
if (span) {
|
|
719
|
+
childEl.style.cssText = '';
|
|
720
|
+
childEl.style.setProperty('grid-column', `span ${span} / span ${span}`, 'important');
|
|
721
|
+
// 重置固定像素宽高,让网格轨道控制尺寸
|
|
722
|
+
childEl.style.setProperty('width', 'auto', 'important');
|
|
723
|
+
childEl.style.setProperty('max-width', '100%', 'important');
|
|
724
|
+
childEl.style.setProperty('min-width', '0', 'important');
|
|
725
|
+
childEl.style.setProperty('height', 'auto', 'important');
|
|
726
|
+
childEl.style.setProperty('min-height', '0', 'important');
|
|
727
|
+
childEl.style.setProperty('max-height', 'none', 'important');
|
|
728
|
+
childEl.style.setProperty('margin', '0', 'important');
|
|
729
|
+
// 允许网格子元素跨页分割,防止内容被整体推到下一页
|
|
730
|
+
childEl.style.setProperty('break-inside', 'auto', 'important');
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
});
|
|
734
|
+
// table-wrapper:彻底清除内联样式(含 _inlineComputedStyles 设置的固定像素值)+ 重新设置
|
|
735
|
+
root.querySelectorAll('.table-wrapper').forEach((el) => {
|
|
736
|
+
el.style.cssText = '';
|
|
737
|
+
el.style.setProperty('overflow', 'visible', 'important');
|
|
738
|
+
el.style.setProperty('max-height', 'none', 'important');
|
|
739
|
+
el.style.setProperty('height', 'auto', 'important');
|
|
740
|
+
el.style.setProperty('max-width', '100%', 'important');
|
|
741
|
+
el.style.setProperty('box-sizing', 'border-box', 'important');
|
|
742
|
+
});
|
|
743
|
+
root.querySelectorAll('.table-container').forEach((el) => {
|
|
744
|
+
el.style.cssText = '';
|
|
745
|
+
el.style.setProperty('overflow', 'visible', 'important');
|
|
746
|
+
el.style.setProperty('height', 'auto', 'important');
|
|
747
|
+
el.style.setProperty('max-height', 'none', 'important');
|
|
748
|
+
el.style.setProperty('min-height', '0', 'important');
|
|
749
|
+
el.style.setProperty('margin', '0', 'important');
|
|
750
|
+
el.style.setProperty('max-width', '100%', 'important');
|
|
751
|
+
el.style.setProperty('box-sizing', 'border-box', 'important');
|
|
752
|
+
});
|
|
753
|
+
// 表格:强制 100% 宽度 + fixed 布局 + 允许跨页分割
|
|
754
|
+
root.querySelectorAll('table[mat-table]').forEach((el) => {
|
|
755
|
+
el.style.setProperty('width', '100%', 'important');
|
|
756
|
+
el.style.setProperty('max-width', '100%', 'important');
|
|
757
|
+
el.style.setProperty('table-layout', 'fixed', 'important');
|
|
758
|
+
el.style.setProperty('break-inside', 'auto', 'important');
|
|
759
|
+
});
|
|
760
|
+
// 表格单元格:清除内联固定宽度 + 允许文字换行
|
|
761
|
+
root.querySelectorAll('table[mat-table] td, table[mat-table] th').forEach((el) => {
|
|
762
|
+
// 清除列的内联 width(来自 column.width 配置),让 table-layout:auto 自动分配
|
|
763
|
+
el.style.removeProperty('width');
|
|
764
|
+
el.style.setProperty('word-break', 'break-word', 'important');
|
|
765
|
+
el.style.setProperty('overflow-wrap', 'break-word', 'important');
|
|
766
|
+
el.style.setProperty('white-space', 'normal', 'important');
|
|
767
|
+
el.style.setProperty('padding', '4px 8px', 'important');
|
|
768
|
+
});
|
|
769
|
+
// 报表渲染器组件宿主:彻底清除内联样式 + 强制 block + 100% 宽度 + 允许跨页
|
|
770
|
+
root.querySelectorAll('app-chart-renderer, app-table-renderer, app-text-renderer').forEach((el) => {
|
|
771
|
+
el.style.cssText = '';
|
|
772
|
+
el.style.setProperty('display', 'block', 'important');
|
|
773
|
+
el.style.setProperty('width', '100%', 'important');
|
|
774
|
+
el.style.setProperty('max-width', '100%', 'important');
|
|
775
|
+
el.style.setProperty('min-width', '0', 'important');
|
|
776
|
+
el.style.setProperty('margin', '0', 'important');
|
|
777
|
+
el.style.setProperty('box-sizing', 'border-box', 'important');
|
|
778
|
+
el.style.setProperty('break-inside', 'auto', 'important');
|
|
779
|
+
});
|
|
780
|
+
// chart-container / chart-canvas / img:彻底清除残留内联样式,重新设置打印友好样式
|
|
781
|
+
// 使用 cssText='' 清除所有内联样式(包括 _inlineComputedStyles 可能设置的固定像素值)
|
|
782
|
+
root.querySelectorAll('.chart-container').forEach((el) => {
|
|
783
|
+
el.style.cssText = '';
|
|
784
|
+
el.style.setProperty('width', '100%', 'important');
|
|
785
|
+
el.style.setProperty('max-width', '100%', 'important');
|
|
786
|
+
el.style.setProperty('min-width', '0', 'important');
|
|
787
|
+
el.style.setProperty('height', 'auto', 'important');
|
|
788
|
+
el.style.setProperty('min-height', '0', 'important');
|
|
789
|
+
el.style.setProperty('max-height', '100mm', 'important');
|
|
790
|
+
el.style.setProperty('overflow', 'hidden', 'important');
|
|
791
|
+
el.style.setProperty('box-sizing', 'border-box', 'important');
|
|
792
|
+
});
|
|
793
|
+
root.querySelectorAll('.chart-canvas').forEach((el) => {
|
|
794
|
+
el.style.cssText = '';
|
|
795
|
+
el.style.setProperty('width', '100%', 'important');
|
|
796
|
+
el.style.setProperty('max-width', '100%', 'important');
|
|
797
|
+
el.style.setProperty('min-width', '0', 'important');
|
|
798
|
+
el.style.setProperty('height', 'auto', 'important');
|
|
799
|
+
el.style.setProperty('min-height', '0', 'important');
|
|
800
|
+
el.style.setProperty('max-height', '95mm', 'important');
|
|
801
|
+
el.style.setProperty('overflow', 'hidden', 'important');
|
|
802
|
+
el.style.setProperty('box-sizing', 'border-box', 'important');
|
|
803
|
+
// 关键:ECharts 在 .chart-canvas 内创建的渲染容器 div 有固定像素内联宽度
|
|
804
|
+
// 必须清除并约束,否则其内部的 img(width:100%) 基于桌面宽度解析
|
|
805
|
+
Array.from(el.children).forEach((child) => {
|
|
806
|
+
if (child.tagName === 'DIV') {
|
|
807
|
+
const childEl = child;
|
|
808
|
+
childEl.style.cssText = '';
|
|
809
|
+
childEl.style.setProperty('width', '100%', 'important');
|
|
810
|
+
childEl.style.setProperty('max-width', '100%', 'important');
|
|
811
|
+
childEl.style.setProperty('min-width', '0', 'important');
|
|
812
|
+
childEl.style.setProperty('height', 'auto', 'important');
|
|
813
|
+
childEl.style.setProperty('box-sizing', 'border-box', 'important');
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
});
|
|
817
|
+
// 图表图片:img 在 ECharts 子 div 内部,用后代选择器
|
|
818
|
+
root.querySelectorAll('.chart-canvas img').forEach((img) => {
|
|
819
|
+
img.style.cssText = '';
|
|
820
|
+
img.style.setProperty('width', '100%', 'important');
|
|
821
|
+
img.style.setProperty('max-width', '100%', 'important');
|
|
822
|
+
img.style.setProperty('height', 'auto', 'important');
|
|
823
|
+
img.style.setProperty('display', 'block', 'important');
|
|
824
|
+
});
|
|
825
|
+
// metric-card:重置固定尺寸,允许内容自适应 A4 网格
|
|
826
|
+
root.querySelectorAll('.metric-card').forEach((el) => {
|
|
827
|
+
el.style.setProperty('width', '100%', 'important');
|
|
828
|
+
el.style.setProperty('max-width', '100%', 'important');
|
|
829
|
+
el.style.setProperty('min-width', '0', 'important');
|
|
830
|
+
el.style.setProperty('height', 'auto', 'important');
|
|
831
|
+
el.style.setProperty('min-height', '0', 'important');
|
|
832
|
+
});
|
|
833
|
+
// metric 子元素:重置固定尺寸,允许文字换行
|
|
834
|
+
root.querySelectorAll('.metric-card .value, .metric-card .label, .metric-card .prefix, .metric-card .suffix').forEach((el) => {
|
|
835
|
+
el.style.setProperty('width', 'auto', 'important');
|
|
836
|
+
el.style.setProperty('max-width', '100%', 'important');
|
|
837
|
+
el.style.setProperty('white-space', 'normal', 'important');
|
|
838
|
+
el.style.setProperty('overflow-wrap', 'break-word', 'important');
|
|
839
|
+
});
|
|
417
840
|
// ── Expansion:强制展开所有面板 ──
|
|
418
841
|
root.querySelectorAll('.mat-expansion-panel').forEach((panel) => {
|
|
419
842
|
panel.classList.add('mat-expanded');
|
|
@@ -434,6 +857,15 @@ class CmatPrintService {
|
|
|
434
857
|
'.mat-mdc-form-field-subscript-wrapper',
|
|
435
858
|
'.mat-mdc-chip-row',
|
|
436
859
|
'.mat-mdc-chip',
|
|
860
|
+
// 报表组件:Angular 属性选择器在克隆节点失效,需内联 computed style
|
|
861
|
+
// 注意:.chart-container 不在此列表 — 其桌面端固定像素宽高+overflow:hidden 会污染打印输出
|
|
862
|
+
'.metric-card',
|
|
863
|
+
'.metric-card .value',
|
|
864
|
+
'.metric-card .prefix',
|
|
865
|
+
'.metric-card .suffix',
|
|
866
|
+
'.metric-card .label',
|
|
867
|
+
'.table-container',
|
|
868
|
+
'.table-wrapper',
|
|
437
869
|
];
|
|
438
870
|
// 从原始元素(而非 document)查找匹配元素,确保索引与克隆节点匹配
|
|
439
871
|
for (const selector of selectors) {
|
|
@@ -624,7 +1056,16 @@ class CmatPrintService {
|
|
|
624
1056
|
/** 创建隐藏 iframe,写入内容,触发打印 */
|
|
625
1057
|
_renderAndPrint(html, options) {
|
|
626
1058
|
const iframe = document.createElement('iframe');
|
|
627
|
-
|
|
1059
|
+
// 放在屏幕后方但保持全视口尺寸渲染,确保 Tailwind 响应式断点正常触发
|
|
1060
|
+
iframe.style.position = 'fixed';
|
|
1061
|
+
iframe.style.left = '0';
|
|
1062
|
+
iframe.style.top = '0';
|
|
1063
|
+
iframe.style.width = '100vw';
|
|
1064
|
+
iframe.style.height = '100vh';
|
|
1065
|
+
iframe.style.border = '0';
|
|
1066
|
+
iframe.style.visibility = 'hidden';
|
|
1067
|
+
iframe.style.zIndex = '-1';
|
|
1068
|
+
iframe.style.pointerEvents = 'none';
|
|
628
1069
|
document.body.appendChild(iframe);
|
|
629
1070
|
const cleanup = () => {
|
|
630
1071
|
iframe.remove();
|