cmat 0.0.111 → 0.0.113

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.
Files changed (256) hide show
  1. package/fesm2022/cmat-components-adapter.mjs +531 -536
  2. package/fesm2022/cmat-components-adapter.mjs.map +1 -1
  3. package/fesm2022/cmat-components-breadcrumb.mjs +521 -356
  4. package/fesm2022/cmat-components-breadcrumb.mjs.map +1 -1
  5. package/fesm2022/cmat-components-card.mjs +150 -42
  6. package/fesm2022/cmat-components-card.mjs.map +1 -1
  7. package/fesm2022/cmat-components-carousel.mjs +1120 -629
  8. package/fesm2022/cmat-components-carousel.mjs.map +1 -1
  9. package/fesm2022/cmat-components-cascade.mjs +861 -441
  10. package/fesm2022/cmat-components-cascade.mjs.map +1 -1
  11. package/fesm2022/cmat-components-chip-input.mjs +580 -335
  12. package/fesm2022/cmat-components-chip-input.mjs.map +1 -1
  13. package/fesm2022/cmat-components-code-editor.mjs +197 -105
  14. package/fesm2022/cmat-components-code-editor.mjs.map +1 -1
  15. package/fesm2022/cmat-components-color-picker.mjs +1762 -825
  16. package/fesm2022/cmat-components-color-picker.mjs.map +1 -1
  17. package/fesm2022/cmat-components-custom-formly.mjs +5196 -2531
  18. package/fesm2022/cmat-components-custom-formly.mjs.map +1 -1
  19. package/fesm2022/cmat-components-data-picker.mjs +1901 -1073
  20. package/fesm2022/cmat-components-data-picker.mjs.map +1 -1
  21. package/fesm2022/cmat-components-date-range.mjs +701 -456
  22. package/fesm2022/cmat-components-date-range.mjs.map +1 -1
  23. package/fesm2022/cmat-components-date-time-display.mjs +137 -30
  24. package/fesm2022/cmat-components-date-time-display.mjs.map +1 -1
  25. package/fesm2022/cmat-components-drawer.mjs +410 -258
  26. package/fesm2022/cmat-components-drawer.mjs.map +1 -1
  27. package/fesm2022/cmat-components-empty-state.mjs +201 -41
  28. package/fesm2022/cmat-components-empty-state.mjs.map +1 -1
  29. package/fesm2022/cmat-components-file-preview.mjs +198 -35
  30. package/fesm2022/cmat-components-file-preview.mjs.map +1 -1
  31. package/fesm2022/cmat-components-filter-toolbar.mjs +320 -72
  32. package/fesm2022/cmat-components-filter-toolbar.mjs.map +1 -1
  33. package/fesm2022/cmat-components-form-actions.mjs +102 -26
  34. package/fesm2022/cmat-components-form-actions.mjs.map +1 -1
  35. package/fesm2022/cmat-components-fullscreen.mjs +167 -47
  36. package/fesm2022/cmat-components-fullscreen.mjs.map +1 -1
  37. package/fesm2022/cmat-components-highlight.mjs +203 -112
  38. package/fesm2022/cmat-components-highlight.mjs.map +1 -1
  39. package/fesm2022/cmat-components-image-viewer.mjs +489 -215
  40. package/fesm2022/cmat-components-image-viewer.mjs.map +1 -1
  41. package/fesm2022/cmat-components-inline-loading.mjs +117 -27
  42. package/fesm2022/cmat-components-inline-loading.mjs.map +1 -1
  43. package/fesm2022/cmat-components-json-editor.mjs +276 -230
  44. package/fesm2022/cmat-components-json-editor.mjs.map +1 -1
  45. package/fesm2022/cmat-components-knob-input.mjs +615 -420
  46. package/fesm2022/cmat-components-knob-input.mjs.map +1 -1
  47. package/fesm2022/cmat-components-loading-overlay.mjs +53 -25
  48. package/fesm2022/cmat-components-loading-overlay.mjs.map +1 -1
  49. package/fesm2022/cmat-components-masonry.mjs +120 -40
  50. package/fesm2022/cmat-components-masonry.mjs.map +1 -1
  51. package/fesm2022/cmat-components-material-color-picker.mjs +332 -155
  52. package/fesm2022/cmat-components-material-color-picker.mjs.map +1 -1
  53. package/fesm2022/cmat-components-material-datetimepicker.mjs +4283 -2504
  54. package/fesm2022/cmat-components-material-datetimepicker.mjs.map +1 -1
  55. package/fesm2022/cmat-components-navigation.mjs +3080 -1404
  56. package/fesm2022/cmat-components-navigation.mjs.map +1 -1
  57. package/fesm2022/cmat-components-opt-input.mjs +540 -466
  58. package/fesm2022/cmat-components-opt-input.mjs.map +1 -1
  59. package/fesm2022/cmat-components-org-chart.mjs +528 -125
  60. package/fesm2022/cmat-components-org-chart.mjs.map +1 -1
  61. package/fesm2022/cmat-components-page-header.mjs +141 -32
  62. package/fesm2022/cmat-components-page-header.mjs.map +1 -1
  63. package/fesm2022/cmat-components-pagination.mjs +866 -534
  64. package/fesm2022/cmat-components-pagination.mjs.map +1 -1
  65. package/fesm2022/cmat-components-password-strength.mjs +873 -434
  66. package/fesm2022/cmat-components-password-strength.mjs.map +1 -1
  67. package/fesm2022/cmat-components-popover.mjs +1012 -731
  68. package/fesm2022/cmat-components-popover.mjs.map +1 -1
  69. package/fesm2022/cmat-components-progress-bar.mjs +98 -35
  70. package/fesm2022/cmat-components-progress-bar.mjs.map +1 -1
  71. package/fesm2022/cmat-components-qrcode.mjs +463 -287
  72. package/fesm2022/cmat-components-qrcode.mjs.map +1 -1
  73. package/fesm2022/cmat-components-rating.mjs +377 -203
  74. package/fesm2022/cmat-components-rating.mjs.map +1 -1
  75. package/fesm2022/cmat-components-rich-text-editor.mjs +153 -39
  76. package/fesm2022/cmat-components-rich-text-editor.mjs.map +1 -1
  77. package/fesm2022/cmat-components-select-search.mjs +926 -496
  78. package/fesm2022/cmat-components-select-search.mjs.map +1 -1
  79. package/fesm2022/cmat-components-select-table.mjs +1280 -842
  80. package/fesm2022/cmat-components-select-table.mjs.map +1 -1
  81. package/fesm2022/cmat-components-select-tree.mjs +998 -690
  82. package/fesm2022/cmat-components-select-tree.mjs.map +1 -1
  83. package/fesm2022/cmat-components-skeleton.mjs +143 -57
  84. package/fesm2022/cmat-components-skeleton.mjs.map +1 -1
  85. package/fesm2022/cmat-components-speed-dial.mjs +457 -303
  86. package/fesm2022/cmat-components-speed-dial.mjs.map +1 -1
  87. package/fesm2022/cmat-components-status-tag.mjs +136 -44
  88. package/fesm2022/cmat-components-status-tag.mjs.map +1 -1
  89. package/fesm2022/cmat-components-table-toolbar.mjs +120 -28
  90. package/fesm2022/cmat-components-table-toolbar.mjs.map +1 -1
  91. package/fesm2022/cmat-components-timeline.mjs +464 -168
  92. package/fesm2022/cmat-components-timeline.mjs.map +1 -1
  93. package/fesm2022/cmat-components-toast.mjs +346 -262
  94. package/fesm2022/cmat-components-toast.mjs.map +1 -1
  95. package/fesm2022/cmat-components-transfer-picker.mjs +1427 -593
  96. package/fesm2022/cmat-components-transfer-picker.mjs.map +1 -1
  97. package/fesm2022/cmat-components-treetable.mjs +372 -112
  98. package/fesm2022/cmat-components-treetable.mjs.map +1 -1
  99. package/fesm2022/cmat-components-upload.mjs +904 -410
  100. package/fesm2022/cmat-components-upload.mjs.map +1 -1
  101. package/fesm2022/cmat-components-x6-angular-shape.mjs +153 -170
  102. package/fesm2022/cmat-components-x6-angular-shape.mjs.map +1 -1
  103. package/fesm2022/cmat-directives-animate-on-scroll.mjs +220 -138
  104. package/fesm2022/cmat-directives-animate-on-scroll.mjs.map +1 -1
  105. package/fesm2022/cmat-directives-arrow-cursor.mjs +246 -193
  106. package/fesm2022/cmat-directives-arrow-cursor.mjs.map +1 -1
  107. package/fesm2022/cmat-directives-autofocus.mjs +43 -25
  108. package/fesm2022/cmat-directives-autofocus.mjs.map +1 -1
  109. package/fesm2022/cmat-directives-data-exporter.mjs +537 -338
  110. package/fesm2022/cmat-directives-data-exporter.mjs.map +1 -1
  111. package/fesm2022/cmat-directives-debounce.mjs +162 -76
  112. package/fesm2022/cmat-directives-debounce.mjs.map +1 -1
  113. package/fesm2022/cmat-directives-digit-only.mjs +457 -356
  114. package/fesm2022/cmat-directives-digit-only.mjs.map +1 -1
  115. package/fesm2022/cmat-directives-equal-validator.mjs +70 -53
  116. package/fesm2022/cmat-directives-equal-validator.mjs.map +1 -1
  117. package/fesm2022/cmat-directives-seamless-auto-scroll.mjs +180 -132
  118. package/fesm2022/cmat-directives-seamless-auto-scroll.mjs.map +1 -1
  119. package/fesm2022/cmat-lib-mock-api.mjs +207 -195
  120. package/fesm2022/cmat-lib-mock-api.mjs.map +1 -1
  121. package/fesm2022/cmat-pipes-bytes.mjs +50 -30
  122. package/fesm2022/cmat-pipes-bytes.mjs.map +1 -1
  123. package/fesm2022/cmat-pipes-date-format.mjs +41 -25
  124. package/fesm2022/cmat-pipes-date-format.mjs.map +1 -1
  125. package/fesm2022/cmat-pipes-find-by-key.mjs +44 -26
  126. package/fesm2022/cmat-pipes-find-by-key.mjs.map +1 -1
  127. package/fesm2022/cmat-pipes-group-by.mjs +50 -38
  128. package/fesm2022/cmat-pipes-group-by.mjs.map +1 -1
  129. package/fesm2022/cmat-pipes-keys.mjs +44 -31
  130. package/fesm2022/cmat-pipes-keys.mjs.map +1 -1
  131. package/fesm2022/cmat-pipes-secure.mjs +60 -49
  132. package/fesm2022/cmat-pipes-secure.mjs.map +1 -1
  133. package/fesm2022/cmat-pipes-uppercase.mjs +39 -22
  134. package/fesm2022/cmat-pipes-uppercase.mjs.map +1 -1
  135. package/fesm2022/cmat-reports.mjs +2761 -0
  136. package/fesm2022/cmat-reports.mjs.map +1 -0
  137. package/fesm2022/cmat-services-alert.mjs +249 -277
  138. package/fesm2022/cmat-services-alert.mjs.map +1 -1
  139. package/fesm2022/cmat-services-config.mjs +110 -81
  140. package/fesm2022/cmat-services-config.mjs.map +1 -1
  141. package/fesm2022/cmat-services-confirmation.mjs +184 -73
  142. package/fesm2022/cmat-services-confirmation.mjs.map +1 -1
  143. package/fesm2022/cmat-services-data.mjs +136 -125
  144. package/fesm2022/cmat-services-data.mjs.map +1 -1
  145. package/fesm2022/cmat-services-export-as.mjs +165 -183
  146. package/fesm2022/cmat-services-export-as.mjs.map +1 -1
  147. package/fesm2022/cmat-services-loading.mjs +116 -95
  148. package/fesm2022/cmat-services-loading.mjs.map +1 -1
  149. package/fesm2022/cmat-services-local-storage.mjs +75 -66
  150. package/fesm2022/cmat-services-local-storage.mjs.map +1 -1
  151. package/fesm2022/cmat-services-media-watcher.mjs +69 -64
  152. package/fesm2022/cmat-services-media-watcher.mjs.map +1 -1
  153. package/fesm2022/cmat-services-platform.mjs +48 -45
  154. package/fesm2022/cmat-services-platform.mjs.map +1 -1
  155. package/fesm2022/cmat-services-print.mjs +984 -1109
  156. package/fesm2022/cmat-services-print.mjs.map +1 -1
  157. package/fesm2022/cmat-services-splash-screen.mjs +53 -38
  158. package/fesm2022/cmat-services-splash-screen.mjs.map +1 -1
  159. package/fesm2022/cmat-services-title.mjs +57 -47
  160. package/fesm2022/cmat-services-title.mjs.map +1 -1
  161. package/fesm2022/cmat-services-translation.mjs +79 -68
  162. package/fesm2022/cmat-services-translation.mjs.map +1 -1
  163. package/fesm2022/cmat-services-utils.mjs +424 -517
  164. package/fesm2022/cmat-services-utils.mjs.map +1 -1
  165. package/fesm2022/cmat-validators.mjs +23 -33
  166. package/fesm2022/cmat-validators.mjs.map +1 -1
  167. package/fesm2022/cmat-version.mjs +12 -16
  168. package/fesm2022/cmat-version.mjs.map +1 -1
  169. package/fesm2022/cmat.mjs +39805 -22511
  170. package/fesm2022/cmat.mjs.map +1 -1
  171. package/package.json +5 -1
  172. package/types/cmat-components-adapter.d.ts +145 -156
  173. package/types/cmat-components-breadcrumb.d.ts +108 -86
  174. package/types/cmat-components-card.d.ts +34 -18
  175. package/types/cmat-components-carousel.d.ts +251 -134
  176. package/types/cmat-components-cascade.d.ts +158 -117
  177. package/types/cmat-components-chip-input.d.ts +105 -71
  178. package/types/cmat-components-code-editor.d.ts +59 -34
  179. package/types/cmat-components-color-picker.d.ts +378 -236
  180. package/types/cmat-components-custom-formly.d.ts +776 -814
  181. package/types/cmat-components-data-picker.d.ts +502 -360
  182. package/types/cmat-components-date-range.d.ts +106 -77
  183. package/types/cmat-components-date-time-display.d.ts +36 -13
  184. package/types/cmat-components-drawer.d.ts +91 -61
  185. package/types/cmat-components-empty-state.d.ts +47 -17
  186. package/types/cmat-components-file-preview.d.ts +42 -14
  187. package/types/cmat-components-filter-toolbar.d.ts +57 -25
  188. package/types/cmat-components-form-actions.d.ts +18 -10
  189. package/types/cmat-components-fullscreen.d.ts +21 -13
  190. package/types/cmat-components-highlight.d.ts +33 -26
  191. package/types/cmat-components-image-viewer.d.ts +119 -58
  192. package/types/cmat-components-inline-loading.d.ts +24 -11
  193. package/types/cmat-components-json-editor.d.ts +39 -28
  194. package/types/cmat-components-knob-input.d.ts +172 -101
  195. package/types/cmat-components-loading-overlay.d.ts +8 -11
  196. package/types/cmat-components-masonry.d.ts +27 -14
  197. package/types/cmat-components-material-color-picker.d.ts +56 -42
  198. package/types/cmat-components-material-datetimepicker.d.ts +817 -454
  199. package/types/cmat-components-navigation.d.ts +295 -221
  200. package/types/cmat-components-opt-input.d.ts +111 -90
  201. package/types/cmat-components-org-chart.d.ts +53 -35
  202. package/types/cmat-components-page-header.d.ts +37 -14
  203. package/types/cmat-components-pagination.d.ts +144 -107
  204. package/types/cmat-components-password-strength.d.ts +197 -86
  205. package/types/cmat-components-popover.d.ts +264 -166
  206. package/types/cmat-components-progress-bar.d.ts +17 -14
  207. package/types/cmat-components-qrcode.d.ts +111 -42
  208. package/types/cmat-components-rating.d.ts +105 -59
  209. package/types/cmat-components-rich-text-editor.d.ts +39 -16
  210. package/types/cmat-components-select-search.d.ts +195 -99
  211. package/types/cmat-components-select-table.d.ts +241 -142
  212. package/types/cmat-components-select-tree.d.ts +185 -118
  213. package/types/cmat-components-skeleton.d.ts +55 -32
  214. package/types/cmat-components-speed-dial.d.ts +86 -61
  215. package/types/cmat-components-status-tag.d.ts +42 -24
  216. package/types/cmat-components-table-toolbar.d.ts +30 -12
  217. package/types/cmat-components-timeline.d.ts +83 -51
  218. package/types/cmat-components-toast.d.ts +84 -85
  219. package/types/cmat-components-transfer-picker.d.ts +228 -181
  220. package/types/cmat-components-treetable.d.ts +63 -39
  221. package/types/cmat-components-upload.d.ts +205 -106
  222. package/types/cmat-components-x6-angular-shape.d.ts +29 -37
  223. package/types/cmat-directives-animate-on-scroll.d.ts +48 -30
  224. package/types/cmat-directives-arrow-cursor.d.ts +55 -35
  225. package/types/cmat-directives-autofocus.d.ts +8 -11
  226. package/types/cmat-directives-data-exporter.d.ts +71 -40
  227. package/types/cmat-directives-debounce.d.ts +31 -28
  228. package/types/cmat-directives-digit-only.d.ts +90 -53
  229. package/types/cmat-directives-equal-validator.d.ts +11 -14
  230. package/types/cmat-directives-seamless-auto-scroll.d.ts +42 -29
  231. package/types/cmat-lib-mock-api.d.ts +46 -55
  232. package/types/cmat-pipes-bytes.d.ts +7 -10
  233. package/types/cmat-pipes-date-format.d.ts +7 -10
  234. package/types/cmat-pipes-find-by-key.d.ts +8 -12
  235. package/types/cmat-pipes-group-by.d.ts +11 -15
  236. package/types/cmat-pipes-keys.d.ts +10 -13
  237. package/types/cmat-pipes-secure.d.ts +14 -17
  238. package/types/cmat-pipes-uppercase.d.ts +7 -10
  239. package/types/cmat-reports.d.ts +1138 -0
  240. package/types/cmat-services-alert.d.ts +80 -87
  241. package/types/cmat-services-config.d.ts +37 -43
  242. package/types/cmat-services-confirmation.d.ts +31 -37
  243. package/types/cmat-services-data.d.ts +18 -21
  244. package/types/cmat-services-export-as.d.ts +28 -33
  245. package/types/cmat-services-loading.d.ts +27 -31
  246. package/types/cmat-services-local-storage.d.ts +17 -21
  247. package/types/cmat-services-media-watcher.d.ts +14 -18
  248. package/types/cmat-services-platform.d.ts +8 -11
  249. package/types/cmat-services-print.d.ts +97 -102
  250. package/types/cmat-services-splash-screen.d.ts +11 -14
  251. package/types/cmat-services-title.d.ts +9 -12
  252. package/types/cmat-services-translation.d.ts +19 -22
  253. package/types/cmat-services-utils.d.ts +76 -80
  254. package/types/cmat-validators.d.ts +5 -8
  255. package/types/cmat-version.d.ts +8 -10
  256. package/types/cmat.d.ts +7551 -5204
@@ -1,1117 +1,992 @@
1
- import * as i0 from '@angular/core';
2
- import { Injectable } from '@angular/core';
1
+ import * as i0 from "@angular/core";
2
+ import { Injectable } from "@angular/core";
3
+ const PRINT_OVERRIDE_CSS = `
4
+ @page { size: A4 var(--orientation); margin: var(--margins); }
3
5
 
4
- /** 打印覆盖样式:最小干预,保留页面原始视觉效果 */
5
- const PRINT_OVERRIDE_CSS = `
6
- @page { size: A4 var(--orientation); margin: var(--margins); }
7
-
8
- /* 强制亮色背景 */
9
- html, body {
10
- background: #fff !important;
11
- color-scheme: light !important;
12
- }
13
- body {
14
- margin: 0 !important;
15
- padding: 16px !important;
16
- overflow: visible !important;
17
- height: auto !important;
18
- min-height: auto !important;
19
- box-sizing: border-box !important;
20
- -webkit-print-color-adjust: exact;
21
- print-color-adjust: exact;
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
- }
53
-
54
- /* 页眉页脚 */
55
- .cmat-print-header {
56
- text-align: center;
57
- margin-bottom: 16px;
58
- padding-bottom: 10px;
59
- border-bottom: 2px solid #333;
60
- }
61
- .cmat-print-header h1 {
62
- font-size: 18pt;
63
- margin: 0 0 4px 0;
64
- font-weight: 700;
65
- }
66
- .cmat-print-header .cmat-print-time {
67
- font-size: 9pt;
68
- color: #666;
69
- }
70
- .cmat-print-footer {
71
- margin-top: 24px;
72
- padding-top: 8px;
73
- border-top: 1px solid #ccc;
74
- font-size: 9pt;
75
- color: #999;
76
- text-align: center;
77
- }
78
- .cmat-print-body {
79
- width: 100%;
80
- padding-top: 8px;
81
- }
82
-
83
- /* 移除滚动容器的滚动约束,仅针对实际可滚动元素 */
84
- .cmat-print-body {
85
- overflow: visible !important;
86
- max-height: none !important;
87
- }
88
- .cmat-print-body .scrollbar-custom,
89
- .cmat-print-body .overflow-y-auto,
90
- .cmat-print-body .overflow-auto,
91
- .cmat-print-body .mat-drawer-content,
92
- .cmat-print-body .cdk-virtual-scroll-content-wrapper {
93
- overflow: visible !important;
94
- max-height: none !important;
95
- height: auto !important;
96
- flex: none !important;
97
- }
98
-
99
- .no-print, [data-print-exclude], .print\\:hidden {
100
- display: none !important;
101
- }
102
- /* 隐藏 datetimepicker toggle 按钮并重置标签偏移 */
103
- cmat-datetimepicker-toggle, .cmat-datetimepicker-toggle {
104
- display: none !important;
105
- }
106
- .cmat-print-body .mat-mdc-form-field:has(.cmat-datetimepicker-toggle) {
107
- --cmat-prefix-label-offset: 0px !important;
108
- }
109
-
110
- /* 分页控制 */
111
- .page-break-before { page-break-before: always; }
112
- .page-break-after { page-break-after: always; }
113
- .page-break-inside { page-break-inside: avoid; }
114
-
115
- /* 防止表单字段和小组件被分页截断(不包含 formly-field,因为它可能包含多个字段,导致第一页空白) */
116
- .cmat-print-body .mat-mdc-form-field,
117
- .cmat-print-body .mat-mdc-chip-grid,
118
- .cmat-print-body .mat-mdc-chip-row,
119
- .cmat-print-body mat-slider,
120
- .cmat-print-body mat-slide-toggle,
121
- .cmat-print-body .mat-mdc-checkbox,
122
- .cmat-print-body .mat-mdc-radio-button,
123
- .cmat-print-body cmat-date-range,
124
- .cmat-print-body .range {
125
- break-inside: avoid !important;
126
- }
127
-
128
- /* 打印时强制表格使用桌面布局(A4纸宽 < 960px 断点,会触发移动端卡片布局) */
129
- .mat-mdc-table:not(.normal-mobile-table) {
130
- display: table !important;
131
- }
132
- .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-header-row {
133
- display: table-row !important;
134
- position: static !important;
135
- }
136
- .mat-mdc-table:not(.normal-mobile-table) tbody {
137
- display: table-row-group !important;
138
- }
139
- .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-row {
140
- display: table-row !important;
141
- height: auto !important;
142
- position: static !important;
143
- border-radius: 0 !important;
144
- box-shadow: none !important;
145
- padding: 0 !important;
146
- max-height: none !important;
147
- overflow: visible !important;
148
- flex-direction: unset !important;
149
- }
150
- .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-cell {
151
- display: table-cell !important;
152
- padding: 8px 12px !important;
153
- border-bottom: 1px solid rgba(0, 0, 0, 0.12) !important;
154
- }
155
- .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-header-cell {
156
- display: table-cell !important;
157
- padding: 8px 12px !important;
158
- border-bottom: 1px solid rgba(0, 0, 0, 0.12) !important;
159
- font-weight: 600 !important;
160
- position: static !important;
161
- }
162
- /* 奇偶行背景 */
163
- .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-row:nth-child(even) {
164
- background-color: rgb(248 250 252) !important;
165
- }
166
- .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-row:nth-child(odd) {
167
- background-color: #fff !important;
168
- }
169
- /* has-label-on-mobile 在打印时不显示前缀标签 */
170
- .has-label-on-mobile::before {
171
- display: none !important;
172
- }
173
- /* 禁止表头跨页重复 */
174
- .mat-mdc-table .mat-mdc-header-row {
175
- position: static !important;
176
- }
177
- thead {
178
- display: table-header-group !important;
179
- }
180
- thead tr {
181
- position: static !important;
182
- }
183
-
184
- /* 保留所有边框和背景色 */
185
- *, *::before, *::after {
186
- -webkit-print-color-adjust: exact !important;
187
- print-color-adjust: exact !important;
188
- }
189
-
190
- /* 移除 focus ring(打印无意义),但不影响 border/box-shadow */
191
- .mat-mdc-form-field-focus-overlay {
192
- display: none !important;
193
- }
194
- .mat-mdc-focus-indicator::after {
195
- display: none !important;
196
- }
197
-
198
- /* 确保表单字段间有合理间距,顶部留空防止 float-label 跨页被裁切 */
199
- .cmat-print-body .mat-mdc-form-field {
200
- margin-bottom: 0.25em !important;
201
- margin-top: 0.5em !important;
202
- }
203
-
204
- /* Repeat 容器内的字段减少顶部间距 */
205
- .cmat-print-body .repeat-field .mat-mdc-form-field {
206
- margin-top: 0 !important;
207
- }
208
-
209
- .cmat-print-body formly-field {
210
- display: block;
211
- margin-bottom: 0.25em !important;
212
- }
213
- /* 修复 flex-auto 在打印上下文中的布局问题 */
214
- .cmat-print-body formly-form.flex-auto,
215
- .cmat-print-body formly-form[class*="flex-auto"] {
216
- flex: none !important;
217
- }
218
-
219
- /* 确保 mat-hint(Description)可见,但不过宽 */
220
- .cmat-print-body .mat-mdc-form-field-subscript-wrapper {
221
- overflow: visible !important;
222
- height: auto !important;
223
- max-height: none !important;
224
- position: relative !important;
225
- padding-top: 2px !important;
226
- }
227
- .cmat-print-body .mat-mdc-form-field-hint {
228
- color: #555 !important;
229
- opacity: 1 !important;
230
- display: block !important;
231
- line-height: 1.2 !important;
232
- }
233
-
234
- /* Chips:确保打印时正确布局 */
235
- .cmat-print-body .mat-mdc-chip-grid {
236
- display: flex !important;
237
- flex-wrap: wrap !important;
238
- gap: 4px !important;
239
- align-items: center !important;
240
- }
241
- .cmat-print-body .mat-mdc-chip-row {
242
- display: inline-flex !important;
243
- align-items: center !important;
244
-
245
- .mat-mdc-chip-action{
246
- padding-right:12px !important;
247
- }
248
- }
249
- /* 隐藏 chip 内的输入框和自动补全 */
250
- .cmat-print-body .mat-mdc-chip-grid input {
251
- display: none !important;
252
- }
253
- .cmat-print-body .mat-mdc-autocomplete {
254
- display: none !important;
255
- }
256
-
257
- /* Color Picker:确保色块按钮的 ::after 伪元素背景色被打印 */
258
- .cmat-print-body .mat-mdc-form-field-icon-prefix button {
259
- overflow: visible !important;
260
- padding: 4px !important;
261
- width: 32px !important;
262
- height: 32px !important;
263
- min-width: 32px !important;
264
- min-height: 32px !important;
265
- }
266
-
267
- /* 通用:防止 overflow-hidden 裁切 border */
268
- .cmat-print-body .overflow-hidden {
269
- overflow: visible !important;
270
- }
271
-
272
- /* ─── 容器类型打印适配 ─── */
273
-
274
- /* Tabs:展开所有标签页内容,隐藏标签导航 */
275
- .cmat-print-body .mat-mdc-tab-header {
276
- display: none !important;
277
- }
278
- .cmat-print-body .mat-mdc-tab-body-wrapper {
279
- overflow: visible !important;
280
- height: auto !important;
281
- }
282
- .cmat-print-body .mat-mdc-tab-body {
283
- display: block !important;
284
- visibility: visible !important;
285
- opacity: 1 !important;
286
- height: auto !important;
287
- border-bottom: 1px dashed #ccc;
288
- padding-bottom: 12px;
289
- margin-bottom: 12px;
290
- }
291
- /* 在 tab body 前显示标签名 */
292
- .cmat-print-body .mat-mdc-tab-body::before {
293
- content: attr(aria-label);
294
- display: block;
295
- font-weight: 600;
296
- font-size: 1.1em;
297
- margin-bottom: 8px;
298
- color: #333;
299
- }
300
-
301
- /* Stepper:展开所有步骤,隐藏导航按钮 */
302
- .cmat-print-body .mat-horizontal-stepper-header-container {
303
- display: none !important;
304
- }
305
- .cmat-print-body .mat-stepper-horizontal-line {
306
- display: none !important;
307
- }
308
- .cmat-print-body .mat-step {
309
- display: block !important;
310
- visibility: visible !important;
311
- opacity: 1 !important;
312
- height: auto !important;
313
- overflow: visible !important;
314
- margin-bottom: 16px;
315
- padding-bottom: 12px;
316
- border-bottom: 1px dashed #ccc;
317
- }
318
- /* 显示步骤标签 */
319
- .cmat-print-body .mat-step-label {
320
- display: block !important;
321
- font-weight: 600;
322
- font-size: 1.1em;
323
- margin-bottom: 8px;
324
- color: #333;
325
- }
326
-
327
- /* Expansion:强制展开面板 */
328
- .cmat-print-body .mat-expansion-panel {
329
- break-inside: avoid;
330
- margin-bottom: 8px;
331
- }
332
- .cmat-print-body .mat-expansion-panel-content {
333
- height: auto !important;
334
- visibility: visible !important;
335
- opacity: 1 !important;
336
- overflow: visible !important;
337
- display: block !important;
338
- }
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
-
460
-
461
- `;
462
- class CmatPrintService {
463
- /**
464
- * 打印指定 DOM 元素
465
- * 保留原始 DOM 结构和样式,同步表单控件的当前值
466
- */
467
- printElement(element, options) {
468
- const clone = element.cloneNode(true);
469
- // 同步表单控件的 live value 到克隆节点的 attribute
470
- this._syncFormValues(element, clone);
471
- // 移除不需要打印的元素
472
- this._prepareForPrint(element, clone, options);
473
- const contentHtml = clone.outerHTML;
474
- this._print(contentHtml, options);
6
+ /* 强制亮色背景 */
7
+ html, body {
8
+ background: #fff !important;
9
+ color-scheme: light !important;
10
+ }
11
+ body {
12
+ margin: 0 !important;
13
+ padding: 16px !important;
14
+ overflow: visible !important;
15
+ height: auto !important;
16
+ min-height: auto !important;
17
+ box-sizing: border-box !important;
18
+ -webkit-print-color-adjust: exact;
19
+ print-color-adjust: exact;
20
+ }
21
+ /* 打印内容主体:约束到页面宽度,防止子元素溢出 */
22
+ .cmat-print-body {
23
+ max-width: 100% !important;
24
+ box-sizing: border-box !important;
25
+ }
26
+ /* 打印内容 flex 容器 + 网格行:高度由内容决定,不拉伸超过内容 */
27
+ .cmat-print-body .flex.flex-col {
28
+ height: auto !important;
29
+ min-height: 0 !important;
30
+ flex: none !important;
31
+ }
32
+ .cmat-print-body .grid {
33
+ height: auto !important;
34
+ min-height: 0 !important;
35
+ }
36
+ /* 报表渲染器宿主 + 网格子元素:允许跨页分割,防止内容被整体推到下一页 */
37
+ .cmat-print-body app-chart-renderer,
38
+ .cmat-print-body app-table-renderer,
39
+ .cmat-print-body app-text-renderer {
40
+ break-inside: auto !important;
41
+ margin: 0 !important;
42
+ }
43
+ .cmat-print-body .grid > [class*="col-span"] {
44
+ break-inside: auto !important;
45
+ }
46
+ /* 隐藏 ECharts 交互层:tooltip、axis-pointer 等悬浮 DOM */
47
+ .cmat-print-body .el-tooltip__popper,
48
+ .cmat-print-body [style*="pointer-events"] {
49
+ display: none !important;
50
+ }
51
+
52
+ /* 页眉页脚 */
53
+ .cmat-print-header {
54
+ text-align: center;
55
+ margin-bottom: 16px;
56
+ padding-bottom: 10px;
57
+ border-bottom: 2px solid #333;
58
+ }
59
+ .cmat-print-header h1 {
60
+ font-size: 18pt;
61
+ margin: 0 0 4px 0;
62
+ font-weight: 700;
63
+ }
64
+ .cmat-print-header .cmat-print-time {
65
+ font-size: 9pt;
66
+ color: #666;
67
+ }
68
+ .cmat-print-footer {
69
+ margin-top: 24px;
70
+ padding-top: 8px;
71
+ border-top: 1px solid #ccc;
72
+ font-size: 9pt;
73
+ color: #999;
74
+ text-align: center;
75
+ }
76
+ .cmat-print-body {
77
+ width: 100%;
78
+ padding-top: 8px;
79
+ }
80
+
81
+ /* 移除滚动容器的滚动约束,仅针对实际可滚动元素 */
82
+ .cmat-print-body {
83
+ overflow: visible !important;
84
+ max-height: none !important;
85
+ }
86
+ .cmat-print-body .scrollbar-custom,
87
+ .cmat-print-body .overflow-y-auto,
88
+ .cmat-print-body .overflow-auto,
89
+ .cmat-print-body .mat-drawer-content,
90
+ .cmat-print-body .cdk-virtual-scroll-content-wrapper {
91
+ overflow: visible !important;
92
+ max-height: none !important;
93
+ height: auto !important;
94
+ flex: none !important;
95
+ }
96
+
97
+ .no-print, [data-print-exclude], .print\\:hidden {
98
+ display: none !important;
99
+ }
100
+ /* 隐藏 datetimepicker toggle 按钮并重置标签偏移 */
101
+ cmat-datetimepicker-toggle, .cmat-datetimepicker-toggle {
102
+ display: none !important;
103
+ }
104
+ .cmat-print-body .mat-mdc-form-field:has(.cmat-datetimepicker-toggle) {
105
+ --cmat-prefix-label-offset: 0px !important;
106
+ }
107
+
108
+ /* 分页控制 */
109
+ .page-break-before { page-break-before: always; }
110
+ .page-break-after { page-break-after: always; }
111
+ .page-break-inside { page-break-inside: avoid; }
112
+
113
+ /* 防止表单字段和小组件被分页截断(不包含 formly-field,因为它可能包含多个字段,导致第一页空白) */
114
+ .cmat-print-body .mat-mdc-form-field,
115
+ .cmat-print-body .mat-mdc-chip-grid,
116
+ .cmat-print-body .mat-mdc-chip-row,
117
+ .cmat-print-body mat-slider,
118
+ .cmat-print-body mat-slide-toggle,
119
+ .cmat-print-body .mat-mdc-checkbox,
120
+ .cmat-print-body .mat-mdc-radio-button,
121
+ .cmat-print-body cmat-date-range,
122
+ .cmat-print-body .range {
123
+ break-inside: avoid !important;
124
+ }
125
+
126
+ /* 打印时强制表格使用桌面布局(A4纸宽 < 960px 断点,会触发移动端卡片布局) */
127
+ .mat-mdc-table:not(.normal-mobile-table) {
128
+ display: table !important;
129
+ }
130
+ .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-header-row {
131
+ display: table-row !important;
132
+ position: static !important;
133
+ }
134
+ .mat-mdc-table:not(.normal-mobile-table) tbody {
135
+ display: table-row-group !important;
136
+ }
137
+ .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-row {
138
+ display: table-row !important;
139
+ height: auto !important;
140
+ position: static !important;
141
+ border-radius: 0 !important;
142
+ box-shadow: none !important;
143
+ padding: 0 !important;
144
+ max-height: none !important;
145
+ overflow: visible !important;
146
+ flex-direction: unset !important;
147
+ }
148
+ .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-cell {
149
+ display: table-cell !important;
150
+ padding: 8px 12px !important;
151
+ border-bottom: 1px solid rgba(0, 0, 0, 0.12) !important;
152
+ }
153
+ .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-header-cell {
154
+ display: table-cell !important;
155
+ padding: 8px 12px !important;
156
+ border-bottom: 1px solid rgba(0, 0, 0, 0.12) !important;
157
+ font-weight: 600 !important;
158
+ position: static !important;
159
+ }
160
+ /* 奇偶行背景 */
161
+ .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-row:nth-child(even) {
162
+ background-color: rgb(248 250 252) !important;
163
+ }
164
+ .mat-mdc-table:not(.normal-mobile-table) .mat-mdc-row:nth-child(odd) {
165
+ background-color: #fff !important;
166
+ }
167
+ /* has-label-on-mobile 在打印时不显示前缀标签 */
168
+ .has-label-on-mobile::before {
169
+ display: none !important;
170
+ }
171
+ /* 禁止表头跨页重复 */
172
+ .mat-mdc-table .mat-mdc-header-row {
173
+ position: static !important;
174
+ }
175
+ thead {
176
+ display: table-header-group !important;
177
+ }
178
+ thead tr {
179
+ position: static !important;
180
+ }
181
+
182
+ /* 保留所有边框和背景色 */
183
+ *, *::before, *::after {
184
+ -webkit-print-color-adjust: exact !important;
185
+ print-color-adjust: exact !important;
186
+ }
187
+
188
+ /* 移除 focus ring(打印无意义),但不影响 border/box-shadow */
189
+ .mat-mdc-form-field-focus-overlay {
190
+ display: none !important;
191
+ }
192
+ .mat-mdc-focus-indicator::after {
193
+ display: none !important;
194
+ }
195
+
196
+ /* 确保表单字段间有合理间距,顶部留空防止 float-label 跨页被裁切 */
197
+ .cmat-print-body .mat-mdc-form-field {
198
+ margin-bottom: 0.25em !important;
199
+ margin-top: 0.5em !important;
200
+ }
201
+
202
+ /* Repeat 容器内的字段减少顶部间距 */
203
+ .cmat-print-body .repeat-field .mat-mdc-form-field {
204
+ margin-top: 0 !important;
205
+ }
206
+
207
+ .cmat-print-body formly-field {
208
+ display: block;
209
+ margin-bottom: 0.25em !important;
210
+ }
211
+ /* 修复 flex-auto 在打印上下文中的布局问题 */
212
+ .cmat-print-body formly-form.flex-auto,
213
+ .cmat-print-body formly-form[class*="flex-auto"] {
214
+ flex: none !important;
215
+ }
216
+
217
+ /* 确保 mat-hint(Description)可见,但不过宽 */
218
+ .cmat-print-body .mat-mdc-form-field-subscript-wrapper {
219
+ overflow: visible !important;
220
+ height: auto !important;
221
+ max-height: none !important;
222
+ position: relative !important;
223
+ padding-top: 2px !important;
224
+ }
225
+ .cmat-print-body .mat-mdc-form-field-hint {
226
+ color: #555 !important;
227
+ opacity: 1 !important;
228
+ display: block !important;
229
+ line-height: 1.2 !important;
230
+ }
231
+
232
+ /* Chips:确保打印时正确布局 */
233
+ .cmat-print-body .mat-mdc-chip-grid {
234
+ display: flex !important;
235
+ flex-wrap: wrap !important;
236
+ gap: 4px !important;
237
+ align-items: center !important;
238
+ }
239
+ .cmat-print-body .mat-mdc-chip-row {
240
+ display: inline-flex !important;
241
+ align-items: center !important;
242
+
243
+ .mat-mdc-chip-action{
244
+ padding-right:12px !important;
475
245
  }
476
- /**
477
- * 通过 CSS 选择器打印第一个匹配的元素
478
- */
479
- printSelector(selector, options) {
480
- const element = document.querySelector(selector);
481
- if (!element) {
482
- console.warn(`[CmatPrintService] 未找到匹配选择器的元素: ${selector}`);
483
- return;
246
+ }
247
+ /* 隐藏 chip 内的输入框和自动补全 */
248
+ .cmat-print-body .mat-mdc-chip-grid input {
249
+ display: none !important;
250
+ }
251
+ .cmat-print-body .mat-mdc-autocomplete {
252
+ display: none !important;
253
+ }
254
+
255
+ /* Color Picker:确保色块按钮的 ::after 伪元素背景色被打印 */
256
+ .cmat-print-body .mat-mdc-form-field-icon-prefix button {
257
+ overflow: visible !important;
258
+ padding: 4px !important;
259
+ width: 32px !important;
260
+ height: 32px !important;
261
+ min-width: 32px !important;
262
+ min-height: 32px !important;
263
+ }
264
+
265
+ /* 通用:防止 overflow-hidden 裁切 border */
266
+ .cmat-print-body .overflow-hidden {
267
+ overflow: visible !important;
268
+ }
269
+
270
+ /* ─── 容器类型打印适配 ─── */
271
+
272
+ /* Tabs:展开所有标签页内容,隐藏标签导航 */
273
+ .cmat-print-body .mat-mdc-tab-header {
274
+ display: none !important;
275
+ }
276
+ .cmat-print-body .mat-mdc-tab-body-wrapper {
277
+ overflow: visible !important;
278
+ height: auto !important;
279
+ }
280
+ .cmat-print-body .mat-mdc-tab-body {
281
+ display: block !important;
282
+ visibility: visible !important;
283
+ opacity: 1 !important;
284
+ height: auto !important;
285
+ border-bottom: 1px dashed #ccc;
286
+ padding-bottom: 12px;
287
+ margin-bottom: 12px;
288
+ }
289
+ /* 在 tab body 前显示标签名 */
290
+ .cmat-print-body .mat-mdc-tab-body::before {
291
+ content: attr(aria-label);
292
+ display: block;
293
+ font-weight: 600;
294
+ font-size: 1.1em;
295
+ margin-bottom: 8px;
296
+ color: #333;
297
+ }
298
+
299
+ /* Stepper:展开所有步骤,隐藏导航按钮 */
300
+ .cmat-print-body .mat-horizontal-stepper-header-container {
301
+ display: none !important;
302
+ }
303
+ .cmat-print-body .mat-stepper-horizontal-line {
304
+ display: none !important;
305
+ }
306
+ .cmat-print-body .mat-step {
307
+ display: block !important;
308
+ visibility: visible !important;
309
+ opacity: 1 !important;
310
+ height: auto !important;
311
+ overflow: visible !important;
312
+ margin-bottom: 16px;
313
+ padding-bottom: 12px;
314
+ border-bottom: 1px dashed #ccc;
315
+ }
316
+ /* 显示步骤标签 */
317
+ .cmat-print-body .mat-step-label {
318
+ display: block !important;
319
+ font-weight: 600;
320
+ font-size: 1.1em;
321
+ margin-bottom: 8px;
322
+ color: #333;
323
+ }
324
+
325
+ /* Expansion:强制展开面板 */
326
+ .cmat-print-body .mat-expansion-panel {
327
+ break-inside: avoid;
328
+ margin-bottom: 8px;
329
+ }
330
+ .cmat-print-body .mat-expansion-panel-content {
331
+ height: auto !important;
332
+ visibility: visible !important;
333
+ opacity: 1 !important;
334
+ overflow: visible !important;
335
+ display: block !important;
336
+ }
337
+
338
+ /* ─── 报表组件打印适配 ─── */
339
+
340
+ /* 报表渲染器组件宿主:Angular 自定义元素默认 display:inline,需强制 block + 100% 宽度以填满网格单元格 */
341
+ .cmat-print-body app-chart-renderer,
342
+ .cmat-print-body app-table-renderer,
343
+ .cmat-print-body app-text-renderer {
344
+ display: block !important;
345
+ width: 100% !important;
346
+ min-width: 0 !important;
347
+ box-sizing: border-box !important;
348
+ }
349
+
350
+ /* 报表主容器:解除滚动容器的固定高度约束 + 阻止 flex 拉伸 */
351
+ .cmat-print-body > main,
352
+ .cmat-print-body .overflow-y-auto,
353
+ .cmat-print-body .overflow-auto {
354
+ overflow: visible !important;
355
+ height: auto !important;
356
+ min-height: 0 !important;
357
+ max-height: none !important;
358
+ flex: none !important;
359
+ }
360
+
361
+ /* 报表行容器:恢复 flex gap-6 间距(gap 不在 computed style 内联列表中,需手动补回) */
362
+ .cmat-print-body .flex.flex-col.gap-6 {
363
+ gap: 1.5rem !important;
364
+ }
365
+
366
+ /* 报表网格:强制 12 列布局(不依赖媒体查询) */
367
+ .cmat-print-body .grid {
368
+ display: grid !important;
369
+ grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
370
+ gap: 0.75rem !important;
371
+ }
372
+ /* col-span 工具类覆盖(含响应式前缀) */
373
+ .cmat-print-body .grid > .col-span-1 { grid-column: span 1 / span 1 !important; }
374
+ .cmat-print-body .grid > .col-span-2 { grid-column: span 2 / span 2 !important; }
375
+ .cmat-print-body .grid > .col-span-3 { grid-column: span 3 / span 3 !important; }
376
+ .cmat-print-body .grid > .col-span-4 { grid-column: span 4 / span 4 !important; }
377
+ .cmat-print-body .grid > .col-span-6 { grid-column: span 6 / span 6 !important; }
378
+ .cmat-print-body .grid > .col-span-12 { grid-column: span 12 / span 12 !important; }
379
+ /* Tailwind 响应式前缀 md:/lg: 的 col-span 类 */
380
+ .cmat-print-body .grid > [class*="\\:col-span-4"] { grid-column: span 4 / span 4 !important; }
381
+ .cmat-print-body .grid > [class*="\\:col-span-6"] { grid-column: span 6 / span 6 !important; }
382
+ .cmat-print-body .grid > [class*="\\:col-span-12"] { grid-column: span 12 / span 12 !important; }
383
+
384
+ /* 报表图表:限制打印高度,为表格留出空间 */
385
+ .cmat-print-body .chart-container {
386
+ overflow: hidden !important;
387
+ break-inside: avoid;
388
+ max-height: 100mm !important;
389
+ }
390
+ .cmat-print-body .chart-canvas {
391
+ overflow: hidden !important;
392
+ height: auto !important;
393
+ max-height: 95mm !important;
394
+ }
395
+ /* ECharts 渲染容器 div:约束到父级宽度,防止固定像素内联样式溢出 */
396
+ .cmat-print-body .chart-canvas > div {
397
+ max-width: 100% !important;
398
+ box-sizing: border-box !important;
399
+ }
400
+ .cmat-print-body .chart-canvas img {
401
+ max-width: 100% !important;
402
+ height: auto !important;
403
+ display: block !important;
404
+ }
405
+
406
+ /* 报表表格容器:移除 overflow 和 max-height 约束 + 约束到页面宽度 */
407
+ .cmat-print-body .table-container {
408
+ overflow: visible !important;
409
+ height: auto !important;
410
+ max-height: none !important;
411
+ min-height: 0 !important;
412
+ max-width: 100% !important;
413
+ box-sizing: border-box !important;
414
+ break-inside: auto !important;
415
+ }
416
+ .cmat-print-body .table-wrapper {
417
+ overflow: visible !important;
418
+ max-height: none !important;
419
+ height: auto !important;
420
+ max-width: 100% !important;
421
+ box-sizing: border-box !important;
422
+ break-inside: auto !important;
423
+ }
424
+ /* 报表表格:强制适应页面宽度,列均分 + 允许跨页分割 */
425
+ .cmat-print-body table[mat-table] {
426
+ width: 100% !important;
427
+ max-width: 100% !important;
428
+ table-layout: fixed !important;
429
+ font-size: 11px !important;
430
+ break-inside: auto !important;
431
+ }
432
+ /* 报表表格单元格:清除内联固定宽度,允许文字换行 */
433
+ .cmat-print-body table[mat-table] td,
434
+ .cmat-print-body table[mat-table] th {
435
+ width: auto !important;
436
+ word-break: break-word !important;
437
+ overflow-wrap: break-word !important;
438
+ white-space: normal !important;
439
+ padding: 4px 8px !important;
440
+ }
441
+ /* 报表表格 tbody:允许跨页分割 */
442
+ .cmat-print-body table[mat-table] tbody {
443
+ break-inside: auto !important;
444
+ display: table-row-group !important;
445
+ }
446
+ /* 报表表格行:防止单行被跨页截断 */
447
+ .cmat-print-body table[mat-table] tr[mat-row],
448
+ .cmat-print-body table[mat-table] tr[mat-row] td {
449
+ break-inside: avoid !important;
450
+ page-break-inside: avoid !important;
451
+ }
452
+ /* 隐藏报表分页组件 */
453
+ .cmat-print-body .pagination-wrapper,
454
+ .cmat-print-body cmat-pagination {
455
+ display: none !important;
456
+ }
457
+
458
+
459
+ `;
460
+ var CmatPrintService = class CmatPrintService {
461
+ printElement(element, options) {
462
+ const clone = element.cloneNode(true);
463
+ this._syncFormValues(element, clone);
464
+ this._prepareForPrint(element, clone, options);
465
+ const contentHtml = clone.outerHTML;
466
+ this._print(contentHtml, options);
467
+ }
468
+ printSelector(selector, options) {
469
+ const element = document.querySelector(selector);
470
+ if (!element) {
471
+ console.warn(`[CmatPrintService] 未找到匹配选择器的元素: ${selector}`);
472
+ return;
473
+ }
474
+ this.printElement(element, options);
475
+ }
476
+ printHtml(html, options) {
477
+ this._print(html, options);
478
+ }
479
+ debugPrint(element, options) {
480
+ const clone = element.cloneNode(true);
481
+ this._syncFormValues(element, clone);
482
+ this._prepareForPrint(element, clone, options);
483
+ const contentHtml = clone.outerHTML;
484
+ const title = options?.title ?? "打印调试";
485
+ const orientation = options?.orientation ?? "portrait";
486
+ const margins = options?.margins ?? {
487
+ top: 15,
488
+ right: 15,
489
+ bottom: 15,
490
+ left: 15
491
+ };
492
+ const marginStr = `${margins.top}mm ${margins.right}mm ${margins.bottom}mm ${margins.left}mm`;
493
+ const overrideCss = PRINT_OVERRIDE_CSS.replace("var(--orientation)", orientation).replace("var(--margins)", marginStr);
494
+ const pageStyles = this._collectAllStyles().replace(/@media\s+print\s+and\s*\(/g, "@media (").replace(/@media\s+print\s*\{/g, "@media all {").replace(/@media\s+screen\s+and\s*\(/g, "@media (").replace(/@media\s+screen\s*\{/g, "@media all {").replace(/@media\s+only\s+screen\s+and\s*\(/g, "@media (").replace(/@media\s+only\s+screen\s*\{/g, "@media all {");
495
+ const cssVars = this._collectCssVariables();
496
+ const htmlClass = document.documentElement.className || "light";
497
+ const bodyClass = this._getPrintBodyClass();
498
+ const fullHtml = `<!DOCTYPE html>
499
+ <html lang="zh-CN" class="${htmlClass}" style="${cssVars}">
500
+ <head>
501
+ <meta charset="utf-8">
502
+ <base href="${document.baseURI}">
503
+ <title>[DEBUG] ${this._escapeHtml(title)}</title>
504
+ ${pageStyles}
505
+ <style>${overrideCss}${options?.customCss ?? ""}</style>
506
+ <style>
507
+ /* 调试模式专属:模拟 A4 页面宽度 */
508
+ body { background: #e0e0e0 !important; }
509
+ .cmat-debug-page {
510
+ max-width: 180mm;
511
+ margin-left: auto !important;
512
+ margin-right: auto !important;
513
+ background: #fff;
514
+ box-shadow: 0 2px 8px rgba(0,0,0,0.15);
515
+ padding: ${margins.top}mm ${margins.right}mm ${margins.bottom}mm ${margins.left}mm;
516
+ min-height: 297mm;
484
517
  }
485
- this.printElement(element, options);
486
- }
487
- /**
488
- * 打印原始 HTML 字符串(不进行 DOM 转换,直接注入)
489
- */
490
- printHtml(html, options) {
491
- this._print(html, options);
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>
518
+ </style>
519
+ </head>
520
+ <body class="${bodyClass}">
521
+ <div style="background:#fff3cd;padding:8px 16px;text-align:center;font-size:14px;border-bottom:2px solid #ffc107;">
522
+ 🔧 <strong>调试模式</strong> — 此页面为打印预览 HTML,可用 DevTools 检查元素。
523
+ 按 Ctrl+P 可触发实际打印。
524
+ </div>
525
+ <div class="cmat-debug-page">
526
+ <div class="cmat-print-body">${contentHtml}</div>
527
+ </div>
528
+ </body>
553
529
  </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
- }
560
- // ─── 私有方法 ───────────────────────────────────────────────
561
- /**
562
- * 同步原始 DOM 中表单控件的当前值到克隆节点
563
- * cloneNode() 不会复制 input.value 等 live property,
564
- * 必须手动同步为 HTML attribute 才能在 iframe 中正确渲染
565
- */
566
- _syncFormValues(original, clone) {
567
- const origFields = original.querySelectorAll('input, textarea, select');
568
- const cloneFields = clone.querySelectorAll('input, textarea, select');
569
- origFields.forEach((origField, i) => {
570
- const cloneField = cloneFields[i];
571
- if (!cloneField)
572
- return;
573
- if (origField instanceof HTMLInputElement) {
574
- const cloneInput = cloneField;
575
- // 同步 value attribute
576
- cloneInput.setAttribute('value', origField.value);
577
- // 同步 checked 状态
578
- if (origField.type === 'checkbox' || origField.type === 'radio') {
579
- if (origField.checked) {
580
- cloneInput.setAttribute('checked', '');
581
- }
582
- else {
583
- cloneInput.removeAttribute('checked');
584
- }
585
- }
586
- }
587
- else if (origField instanceof HTMLTextAreaElement) {
588
- // textarea 的值通过 textContent 同步
589
- cloneField.textContent = origField.value;
590
- }
591
- else if (origField instanceof HTMLSelectElement) {
592
- const cloneSelect = cloneField;
593
- Array.from(origField.options).forEach((opt, idx) => {
594
- const cloneOpt = cloneSelect.options[idx];
595
- if (!cloneOpt)
596
- return;
597
- if (opt.selected) {
598
- cloneOpt.setAttribute('selected', '');
599
- }
600
- else {
601
- cloneOpt.removeAttribute('selected');
602
- }
603
- });
604
- }
605
- });
606
- }
607
- /**
608
- * 最小化打印准备:DOM 转换 + 清理
609
- * 对无法正确打印的组件进行 DOM 替换,对关键元素复制 computed style
610
- */
611
- _prepareForPrint(original, root, options) {
612
- // 移除标记为不打印的元素
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
- });
620
- // 移除所有按钮(保留 form-field 前缀/后缀按钮、chip 内按钮和 slide-toggle 开关)
621
- root.querySelectorAll('button').forEach((el) => {
622
- const isPrefixSuffix = el.closest('.mat-mdc-form-field-icon-prefix, .mat-mdc-form-field-icon-suffix, ' +
623
- '.mat-mdc-form-field-text-prefix, .mat-mdc-form-field-text-suffix');
624
- const isChipButton = el.closest('.mat-mdc-chip-row');
625
- const isSwitch = el.classList.contains('mdc-switch');
626
- if (!isPrefixSuffix && !isChipButton && !isSwitch) {
627
- el.remove();
628
- }
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
- });
650
- // ── Chips:移除删除按钮的内容(图标),保持 chip 布局 ──
651
- root.querySelectorAll('.mat-mdc-chip-row button[matChipRemove]').forEach((btn) => {
652
- btn.innerHTML = '';
653
- btn.style.cssText = 'display:none !important;';
654
- });
655
- // ── Description (mat-hint):强制紧凑布局 ──
656
- root.querySelectorAll('.mat-mdc-form-field-subscript-wrapper').forEach((wrapper) => {
657
- wrapper.style.cssText += ';overflow:visible!important;height:auto!important;min-height:0!important;max-height:none!important;' +
658
- 'position:relative!important;padding:0!important;margin:0!important;line-height:1!important;font-size:0.85em!important;';
659
- });
660
- // ── 复制关键元素的 computed style 为 inline style ──
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
- });
840
- // ── Expansion:强制展开所有面板 ──
841
- root.querySelectorAll('.mat-expansion-panel').forEach((panel) => {
842
- panel.classList.add('mat-expanded');
843
- });
844
- // 移除用户自定义排除选择器
845
- options?.excludeSelectors?.forEach((selector) => {
846
- root.querySelectorAll(selector).forEach(el => el.remove());
847
- });
848
- }
849
- /**
850
- * 将原始页面中关键元素的 computed style 复制为 inline style
851
- * 确保 iframe 中即使 CSS 规则不生效,样式也能通过 inline style 保留
852
- */
853
- _inlineComputedStyles(original, root) {
854
- // 需要复制 computed style 的选择器列表
855
- // 注意:不包含 .mdc-switch* 和 .mdc-slider*,这些组件的 computed style 可能包含 opacity:0 等不适合打印的值
856
- const selectors = [
857
- '.mat-mdc-form-field-subscript-wrapper',
858
- '.mat-mdc-chip-row',
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',
869
- ];
870
- // 从原始元素(而非 document)查找匹配元素,确保索引与克隆节点匹配
871
- for (const selector of selectors) {
872
- const originals = original.querySelectorAll(selector);
873
- const clones = root.querySelectorAll(selector);
874
- originals.forEach((orig, i) => {
875
- const clone = clones[i];
876
- if (!clone)
877
- return;
878
- const computed = getComputedStyle(orig);
879
- // 复制关键属性
880
- const props = ['display', 'visibility', 'opacity', 'overflow', 'width', 'height',
881
- 'min-width', 'min-height', 'max-width', 'max-height', 'padding', 'margin',
882
- 'border', 'border-radius', 'background-color', 'color', 'font-size', 'font-weight',
883
- 'line-height', 'position', 'top', 'left', 'right', 'bottom', 'flex', 'flex-direction',
884
- 'align-items', 'justify-content', 'gap', 'box-shadow', 'transform'];
885
- for (const prop of props) {
886
- const val = computed.getPropertyValue(prop);
887
- if (val) {
888
- clone.style.setProperty(prop, val, 'important');
889
- }
890
- }
891
- });
892
- }
893
- }
894
- /** 构建完整 HTML 并注入 iframe 执行打印 */
895
- _print(contentHtml, options) {
896
- const title = options?.title ?? '打印';
897
- const orientation = options?.orientation ?? 'portrait';
898
- const margins = options?.margins ?? { top: 15, right: 15, bottom: 15, left: 15 };
899
- const now = new Date();
900
- const timeStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
901
- // 页眉
902
- let headerHtml = '';
903
- if (options?.header !== null) {
904
- headerHtml = options?.header ?? `
905
- <div class="cmat-print-header">
906
- <h1>${this._escapeHtml(title)}</h1>
907
- <div class="cmat-print-time">打印时间:${timeStr}</div>
908
- </div>
530
+ const blob = new Blob([fullHtml], { type: "text/html" });
531
+ const url = URL.createObjectURL(blob);
532
+ window.open(url, "_blank");
533
+ setTimeout(() => URL.revokeObjectURL(url), 6e4);
534
+ }
535
+ _syncFormValues(original, clone) {
536
+ const origFields = original.querySelectorAll("input, textarea, select");
537
+ const cloneFields = clone.querySelectorAll("input, textarea, select");
538
+ origFields.forEach((origField, i) => {
539
+ const cloneField = cloneFields[i];
540
+ if (!cloneField) return;
541
+ if (origField instanceof HTMLInputElement) {
542
+ const cloneInput = cloneField;
543
+ cloneInput.setAttribute("value", origField.value);
544
+ if (origField.type === "checkbox" || origField.type === "radio") {
545
+ if (origField.checked) cloneInput.setAttribute("checked", "");
546
+ else cloneInput.removeAttribute("checked");
547
+ }
548
+ } else if (origField instanceof HTMLTextAreaElement) cloneField.textContent = origField.value;
549
+ else if (origField instanceof HTMLSelectElement) {
550
+ const cloneSelect = cloneField;
551
+ Array.from(origField.options).forEach((opt, idx) => {
552
+ const cloneOpt = cloneSelect.options[idx];
553
+ if (!cloneOpt) return;
554
+ if (opt.selected) cloneOpt.setAttribute("selected", "");
555
+ else cloneOpt.removeAttribute("selected");
556
+ });
557
+ }
558
+ });
559
+ }
560
+ _prepareForPrint(original, root, options) {
561
+ root.querySelectorAll(".print\\:hidden, [data-print-exclude]").forEach((el) => el.remove());
562
+ root.querySelectorAll(".el-tooltip__popper, [style*=\"pointer-events\"]").forEach((el) => {
563
+ if (el.closest(".chart-container, .chart-canvas, [class*=\"echarts\"]")) el.remove();
564
+ });
565
+ root.querySelectorAll("button").forEach((el) => {
566
+ const isPrefixSuffix = el.closest(".mat-mdc-form-field-icon-prefix, .mat-mdc-form-field-icon-suffix, .mat-mdc-form-field-text-prefix, .mat-mdc-form-field-text-suffix");
567
+ const isChipButton = el.closest(".mat-mdc-chip-row");
568
+ const isSwitch = el.classList.contains("mdc-switch");
569
+ if (!isPrefixSuffix && !isChipButton && !isSwitch) el.remove();
570
+ });
571
+ const origCanvases = original.querySelectorAll("canvas");
572
+ const cloneCanvases = root.querySelectorAll("canvas");
573
+ origCanvases.forEach((origCanvas, i) => {
574
+ const cloneCanvas = cloneCanvases[i];
575
+ if (!cloneCanvas) return;
576
+ try {
577
+ const dataUrl = origCanvas.toDataURL("image/png");
578
+ const img = document.createElement("img");
579
+ img.src = dataUrl;
580
+ img.style.width = "100%";
581
+ img.style.height = "auto";
582
+ img.style.display = "block";
583
+ cloneCanvas.parentNode?.replaceChild(img, cloneCanvas);
584
+ } catch (e) {
585
+ console.warn("[CmatPrintService] Canvas 转图片失败:", e);
586
+ }
587
+ });
588
+ root.querySelectorAll(".mat-mdc-chip-row button[matChipRemove]").forEach((btn) => {
589
+ btn.innerHTML = "";
590
+ btn.style.cssText = "display:none !important;";
591
+ });
592
+ root.querySelectorAll(".mat-mdc-form-field-subscript-wrapper").forEach((wrapper) => {
593
+ wrapper.style.cssText += ";overflow:visible!important;height:auto!important;min-height:0!important;max-height:none!important;position:relative!important;padding:0!important;margin:0!important;line-height:1!important;font-size:0.85em!important;";
594
+ });
595
+ this._inlineComputedStyles(original, root);
596
+ root.style.setProperty("overflow", "visible", "important");
597
+ root.style.setProperty("height", "auto", "important");
598
+ root.style.setProperty("min-height", "0", "important");
599
+ root.style.setProperty("max-height", "none", "important");
600
+ root.style.setProperty("max-width", "100%", "important");
601
+ root.style.setProperty("box-sizing", "border-box", "important");
602
+ root.querySelectorAll("[class*=\"overflow-y-auto\"], [class*=\"overflow-auto\"]").forEach((el) => {
603
+ el.style.setProperty("overflow", "visible", "important");
604
+ el.style.setProperty("height", "auto", "important");
605
+ el.style.setProperty("min-height", "0", "important");
606
+ el.style.setProperty("max-height", "none", "important");
607
+ el.style.setProperty("flex", "none", "important");
608
+ });
609
+ root.querySelectorAll("[class*=\"gap-6\"]").forEach((el) => {
610
+ el.style.setProperty("gap", "1.5rem", "important");
611
+ el.style.setProperty("max-width", "100%", "important");
612
+ el.style.setProperty("margin", "0", "important");
613
+ el.style.setProperty("box-sizing", "border-box", "important");
614
+ el.style.setProperty("height", "auto", "important");
615
+ el.style.setProperty("min-height", "0", "important");
616
+ el.style.setProperty("flex", "none", "important");
617
+ });
618
+ root.querySelectorAll(".grid").forEach((el) => {
619
+ if (!el.querySelector("[class*=\"col-span\"]")) return;
620
+ el.style.setProperty("display", "grid", "important");
621
+ el.style.setProperty("grid-template-columns", "repeat(12, minmax(0, 1fr))", "important");
622
+ el.style.setProperty("gap", "0.75rem", "important");
623
+ el.style.setProperty("height", "auto", "important");
624
+ el.style.setProperty("min-height", "0", "important");
625
+ el.style.setProperty("max-height", "none", "important");
626
+ el.style.setProperty("overflow", "visible", "important");
627
+ el.style.setProperty("max-width", "100%", "important");
628
+ el.style.setProperty("margin", "0", "important");
629
+ el.style.setProperty("box-sizing", "border-box", "important");
630
+ Array.from(el.children).forEach((child) => {
631
+ const childEl = child;
632
+ const classes = child.className || "";
633
+ const lgMatch = /lg:col-span-(\d+)/.exec(classes);
634
+ const mdMatch = /md:col-span-(\d+)/.exec(classes);
635
+ const baseMatch = /(?:^|\s)col-span-(\d+)/.exec(classes);
636
+ let span = lgMatch?.[1] ?? mdMatch?.[1] ?? baseMatch?.[1];
637
+ if (childEl.querySelector(".chart-container")) span = "12";
638
+ if (span) {
639
+ childEl.style.cssText = "";
640
+ childEl.style.setProperty("grid-column", `span ${span} / span ${span}`, "important");
641
+ childEl.style.setProperty("width", "auto", "important");
642
+ childEl.style.setProperty("max-width", "100%", "important");
643
+ childEl.style.setProperty("min-width", "0", "important");
644
+ childEl.style.setProperty("height", "auto", "important");
645
+ childEl.style.setProperty("min-height", "0", "important");
646
+ childEl.style.setProperty("max-height", "none", "important");
647
+ childEl.style.setProperty("margin", "0", "important");
648
+ childEl.style.setProperty("break-inside", "auto", "important");
649
+ }
650
+ });
651
+ });
652
+ root.querySelectorAll(".table-wrapper").forEach((el) => {
653
+ el.style.cssText = "";
654
+ el.style.setProperty("overflow", "visible", "important");
655
+ el.style.setProperty("max-height", "none", "important");
656
+ el.style.setProperty("height", "auto", "important");
657
+ el.style.setProperty("max-width", "100%", "important");
658
+ el.style.setProperty("box-sizing", "border-box", "important");
659
+ });
660
+ root.querySelectorAll(".table-container").forEach((el) => {
661
+ el.style.cssText = "";
662
+ el.style.setProperty("overflow", "visible", "important");
663
+ el.style.setProperty("height", "auto", "important");
664
+ el.style.setProperty("max-height", "none", "important");
665
+ el.style.setProperty("min-height", "0", "important");
666
+ el.style.setProperty("margin", "0", "important");
667
+ el.style.setProperty("max-width", "100%", "important");
668
+ el.style.setProperty("box-sizing", "border-box", "important");
669
+ });
670
+ root.querySelectorAll("table[mat-table]").forEach((el) => {
671
+ el.style.setProperty("width", "100%", "important");
672
+ el.style.setProperty("max-width", "100%", "important");
673
+ el.style.setProperty("table-layout", "fixed", "important");
674
+ el.style.setProperty("break-inside", "auto", "important");
675
+ });
676
+ root.querySelectorAll("table[mat-table] td, table[mat-table] th").forEach((el) => {
677
+ el.style.removeProperty("width");
678
+ el.style.setProperty("word-break", "break-word", "important");
679
+ el.style.setProperty("overflow-wrap", "break-word", "important");
680
+ el.style.setProperty("white-space", "normal", "important");
681
+ el.style.setProperty("padding", "4px 8px", "important");
682
+ });
683
+ root.querySelectorAll("app-chart-renderer, app-table-renderer, app-text-renderer").forEach((el) => {
684
+ el.style.cssText = "";
685
+ el.style.setProperty("display", "block", "important");
686
+ el.style.setProperty("width", "100%", "important");
687
+ el.style.setProperty("max-width", "100%", "important");
688
+ el.style.setProperty("min-width", "0", "important");
689
+ el.style.setProperty("margin", "0", "important");
690
+ el.style.setProperty("box-sizing", "border-box", "important");
691
+ el.style.setProperty("break-inside", "auto", "important");
692
+ });
693
+ root.querySelectorAll(".chart-container").forEach((el) => {
694
+ el.style.cssText = "";
695
+ el.style.setProperty("width", "100%", "important");
696
+ el.style.setProperty("max-width", "100%", "important");
697
+ el.style.setProperty("min-width", "0", "important");
698
+ el.style.setProperty("height", "auto", "important");
699
+ el.style.setProperty("min-height", "0", "important");
700
+ el.style.setProperty("max-height", "100mm", "important");
701
+ el.style.setProperty("overflow", "hidden", "important");
702
+ el.style.setProperty("box-sizing", "border-box", "important");
703
+ });
704
+ root.querySelectorAll(".chart-canvas").forEach((el) => {
705
+ el.style.cssText = "";
706
+ el.style.setProperty("width", "100%", "important");
707
+ el.style.setProperty("max-width", "100%", "important");
708
+ el.style.setProperty("min-width", "0", "important");
709
+ el.style.setProperty("height", "auto", "important");
710
+ el.style.setProperty("min-height", "0", "important");
711
+ el.style.setProperty("max-height", "95mm", "important");
712
+ el.style.setProperty("overflow", "hidden", "important");
713
+ el.style.setProperty("box-sizing", "border-box", "important");
714
+ Array.from(el.children).forEach((child) => {
715
+ if (child.tagName === "DIV") {
716
+ const childEl = child;
717
+ childEl.style.cssText = "";
718
+ childEl.style.setProperty("width", "100%", "important");
719
+ childEl.style.setProperty("max-width", "100%", "important");
720
+ childEl.style.setProperty("min-width", "0", "important");
721
+ childEl.style.setProperty("height", "auto", "important");
722
+ childEl.style.setProperty("box-sizing", "border-box", "important");
723
+ }
724
+ });
725
+ });
726
+ root.querySelectorAll(".chart-canvas img").forEach((img) => {
727
+ img.style.cssText = "";
728
+ img.style.setProperty("width", "100%", "important");
729
+ img.style.setProperty("max-width", "100%", "important");
730
+ img.style.setProperty("height", "auto", "important");
731
+ img.style.setProperty("display", "block", "important");
732
+ });
733
+ root.querySelectorAll(".metric-card").forEach((el) => {
734
+ el.style.setProperty("width", "100%", "important");
735
+ el.style.setProperty("max-width", "100%", "important");
736
+ el.style.setProperty("min-width", "0", "important");
737
+ el.style.setProperty("height", "auto", "important");
738
+ el.style.setProperty("min-height", "0", "important");
739
+ });
740
+ root.querySelectorAll(".metric-card .value, .metric-card .label, .metric-card .prefix, .metric-card .suffix").forEach((el) => {
741
+ el.style.setProperty("width", "auto", "important");
742
+ el.style.setProperty("max-width", "100%", "important");
743
+ el.style.setProperty("white-space", "normal", "important");
744
+ el.style.setProperty("overflow-wrap", "break-word", "important");
745
+ });
746
+ root.querySelectorAll(".mat-expansion-panel").forEach((panel) => {
747
+ panel.classList.add("mat-expanded");
748
+ });
749
+ options?.excludeSelectors?.forEach((selector) => {
750
+ root.querySelectorAll(selector).forEach((el) => el.remove());
751
+ });
752
+ }
753
+ _inlineComputedStyles(original, root) {
754
+ for (const selector of [
755
+ ".mat-mdc-form-field-subscript-wrapper",
756
+ ".mat-mdc-chip-row",
757
+ ".mat-mdc-chip",
758
+ ".metric-card",
759
+ ".metric-card .value",
760
+ ".metric-card .prefix",
761
+ ".metric-card .suffix",
762
+ ".metric-card .label",
763
+ ".table-container",
764
+ ".table-wrapper"
765
+ ]) {
766
+ const originals = original.querySelectorAll(selector);
767
+ const clones = root.querySelectorAll(selector);
768
+ originals.forEach((orig, i) => {
769
+ const clone = clones[i];
770
+ if (!clone) return;
771
+ const computed = getComputedStyle(orig);
772
+ for (const prop of [
773
+ "display",
774
+ "visibility",
775
+ "opacity",
776
+ "overflow",
777
+ "width",
778
+ "height",
779
+ "min-width",
780
+ "min-height",
781
+ "max-width",
782
+ "max-height",
783
+ "padding",
784
+ "margin",
785
+ "border",
786
+ "border-radius",
787
+ "background-color",
788
+ "color",
789
+ "font-size",
790
+ "font-weight",
791
+ "line-height",
792
+ "position",
793
+ "top",
794
+ "left",
795
+ "right",
796
+ "bottom",
797
+ "flex",
798
+ "flex-direction",
799
+ "align-items",
800
+ "justify-content",
801
+ "gap",
802
+ "box-shadow",
803
+ "transform"
804
+ ]) {
805
+ const val = computed.getPropertyValue(prop);
806
+ if (val) clone.style.setProperty(prop, val, "important");
807
+ }
808
+ });
809
+ }
810
+ }
811
+ _print(contentHtml, options) {
812
+ const title = options?.title ?? "打印";
813
+ const orientation = options?.orientation ?? "portrait";
814
+ const margins = options?.margins ?? {
815
+ top: 15,
816
+ right: 15,
817
+ bottom: 15,
818
+ left: 15
819
+ };
820
+ const now = /* @__PURE__ */ new Date();
821
+ const timeStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")} ${String(now.getHours()).padStart(2, "0")}:${String(now.getMinutes()).padStart(2, "0")}`;
822
+ let headerHtml = "";
823
+ if (options?.header !== null) headerHtml = options?.header ?? `
824
+ <div class="cmat-print-header">
825
+ <h1>${this._escapeHtml(title)}</h1>
826
+ <div class="cmat-print-time">打印时间:${timeStr}</div>
827
+ </div>
909
828
  `;
910
- }
911
- // 页脚
912
- let footerHtml = '';
913
- if (options?.footer !== null) {
914
- footerHtml = options?.footer ?? `
915
- <div class="cmat-print-footer">
916
- 此文档由系统生成 · ${timeStr}
917
- </div>
829
+ let footerHtml = "";
830
+ if (options?.footer !== null) footerHtml = options?.footer ?? `
831
+ <div class="cmat-print-footer">
832
+ 此文档由系统生成 · ${timeStr}
833
+ </div>
918
834
  `;
919
- }
920
- // 收集页面已有样式(通过 styleSheets API 完整收集)
921
- const pageStyles = this._collectAllStyles();
922
- // 收集 CSS 自定义属性(变量),确保 iframe 中边框颜色等不丢失
923
- const cssVars = this._collectCssVariables();
924
- // 复制原始页面的 html/body class(保留主题类名)
925
- const htmlClass = document.documentElement.className || 'light';
926
- const bodyClass = this._getPrintBodyClass();
927
- // 打印覆盖样式
928
- const marginStr = `${margins.top}mm ${margins.right}mm ${margins.bottom}mm ${margins.left}mm`;
929
- const overrideCss = PRINT_OVERRIDE_CSS
930
- .replace('var(--orientation)', orientation)
931
- .replace('var(--margins)', marginStr);
932
- const fullHtml = `<!DOCTYPE html>
933
- <html lang="zh-CN" class="${htmlClass}" style="${cssVars}">
934
- <head>
935
- <meta charset="utf-8">
936
- <base href="${document.baseURI}">
937
- <title>${this._escapeHtml(title)}</title>
938
- ${pageStyles}
939
- <style>${overrideCss}${options?.customCss ?? ''}</style>
940
- </head>
941
- <body class="${bodyClass}">
942
- ${headerHtml}
943
- <div class="cmat-print-body">${contentHtml}</div>
944
- ${footerHtml}
945
- </body>
835
+ const pageStyles = this._collectAllStyles();
836
+ const cssVars = this._collectCssVariables();
837
+ const htmlClass = document.documentElement.className || "light";
838
+ const bodyClass = this._getPrintBodyClass();
839
+ const marginStr = `${margins.top}mm ${margins.right}mm ${margins.bottom}mm ${margins.left}mm`;
840
+ const overrideCss = PRINT_OVERRIDE_CSS.replace("var(--orientation)", orientation).replace("var(--margins)", marginStr);
841
+ const fullHtml = `<!DOCTYPE html>
842
+ <html lang="zh-CN" class="${htmlClass}" style="${cssVars}">
843
+ <head>
844
+ <meta charset="utf-8">
845
+ <base href="${document.baseURI}">
846
+ <title>${this._escapeHtml(title)}</title>
847
+ ${pageStyles}
848
+ <style>${overrideCss}${options?.customCss ?? ""}</style>
849
+ </head>
850
+ <body class="${bodyClass}">
851
+ ${headerHtml}
852
+ <div class="cmat-print-body">${contentHtml}</div>
853
+ ${footerHtml}
854
+ </body>
946
855
  </html>`;
947
- this._renderAndPrint(fullHtml, options);
948
- }
949
- /**
950
- * 通过 document.styleSheets API 收集所有样式规则
951
- * 关键处理:将 @media screen 转换为同时适用于 print
952
- * (因为 iframe 调用 print() 时媒体类型切换为 print,screen-only 规则会失效)
953
- */
954
- _collectAllStyles() {
955
- const cssTexts = [];
956
- try {
957
- for (const sheet of Array.from(document.styleSheets)) {
958
- try {
959
- const rules = sheet.cssRules;
960
- if (!rules || rules.length === 0)
961
- continue;
962
- let cssText = '';
963
- for (const rule of Array.from(rules)) {
964
- cssText += rule.cssText + '\n';
965
- }
966
- if (cssText.trim()) {
967
- cssTexts.push(`<style>${this._transformMediaForPrint(cssText)}</style>`);
968
- }
969
- }
970
- catch {
971
- // 跨域样式表无法读取 cssRules,使用 <link> 回退
972
- if (sheet.href) {
973
- cssTexts.push(`<link rel="stylesheet" href="${sheet.href}" media="all">`);
974
- }
975
- }
976
- }
977
- }
978
- catch (e) {
979
- console.warn('[CmatPrintService] 样式收集异常:', e);
980
- }
981
- return cssTexts.join('\n ');
982
- }
983
- /**
984
- * 将 @media screen 相关查询转换为同时适用 print
985
- * 确保打印时不丢失屏幕样式(如表格奇偶行、border 等)
986
- */
987
- _transformMediaForPrint(css) {
988
- // @media screen and (...) → @media (...)
989
- // @media screen → 移除 media 类型限制
990
- return css
991
- .replace(/@media\s+screen\s+and\s*\(/g, '@media (')
992
- .replace(/@media\s+screen\s*\{/g, '@media all {')
993
- .replace(/@media\s+only\s+screen\s+and\s*\(/g, '@media (')
994
- .replace(/@media\s+only\s+screen\s*\{/g, '@media all {');
995
- }
996
- /**
997
- * 收集页面 :root 上的所有 CSS 自定义属性(变量)
998
- * 这些变量定义了 Material/Tailwind 的边框颜色、主题色等
999
- * 克隆到 iframe 时祖先链断裂,需要手动复制
1000
- */
1001
- _collectCssVariables() {
1002
- const vars = [];
1003
- const rootStyles = getComputedStyle(document.documentElement);
1004
- // 从 document.styleSheets 中提取 :root 规则里的自定义属性
1005
- try {
1006
- for (const sheet of Array.from(document.styleSheets)) {
1007
- try {
1008
- const rules = sheet.cssRules;
1009
- if (!rules)
1010
- continue;
1011
- for (const rule of Array.from(rules)) {
1012
- if (rule instanceof CSSStyleRule) {
1013
- const selector = rule.selectorText;
1014
- if (selector === ':root' || selector === 'html' || selector === ':root, html') {
1015
- const props = Array.from({ length: rule.style.length }, (_, i) => rule.style[i]);
1016
- for (const prop of props) {
1017
- if (prop.startsWith('--')) {
1018
- vars.push(`${prop}: ${rule.style.getPropertyValue(prop)}`);
1019
- }
1020
- }
1021
- }
1022
- }
1023
- }
1024
- }
1025
- catch {
1026
- // 跨域样式表跳过
1027
- }
1028
- }
1029
- }
1030
- catch (e) {
1031
- console.warn('[CmatPrintService] CSS变量收集异常:', e);
1032
- }
1033
- // 补充:从 computed style 获取运行时可能动态设置的变量
1034
- // 遍历常见的 Material/Tailwind 变量前缀
1035
- const prefixes = ['--mdc-', '--mat-', '--md-', '--tw-', '--ck-', '--color-', '--border-'];
1036
- const rootProps = Array.from({ length: rootStyles.length }, (_, i) => rootStyles[i]);
1037
- for (const prop of rootProps) {
1038
- if (prop.startsWith('--') && prefixes.some(p => prop.startsWith(p))) {
1039
- const value = rootStyles.getPropertyValue(prop);
1040
- if (value && !vars.some(v => v.startsWith(prop + ':'))) {
1041
- vars.push(`${prop}: ${value.trim()}`);
1042
- }
1043
- }
1044
- }
1045
- return vars.join('; ');
1046
- }
1047
- /** 获取打印用的 body class(复制原始页面的主题类名,移除布局类名) */
1048
- _getPrintBodyClass() {
1049
- const bodyClasses = document.body.className.split(/\s+/);
1050
- // 保留主题相关 class,移除布局/滚动类
1051
- const excludeClasses = new Set(['overflow-hidden', 'h-full', 'w-full', 'h-screen', 'w-screen']);
1052
- return bodyClasses
1053
- .filter(c => c && !excludeClasses.has(c))
1054
- .join(' ');
1055
- }
1056
- /** 创建隐藏 iframe,写入内容,触发打印 */
1057
- _renderAndPrint(html, options) {
1058
- const iframe = document.createElement('iframe');
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';
1069
- document.body.appendChild(iframe);
1070
- const cleanup = () => {
1071
- iframe.remove();
1072
- options?.afterPrint?.();
1073
- };
1074
- iframe.onload = () => {
1075
- // 给渲染一点时间(图片、字体等)
1076
- setTimeout(() => {
1077
- try {
1078
- iframe.contentWindow?.focus();
1079
- iframe.contentWindow?.print();
1080
- }
1081
- catch (e) {
1082
- console.error('[CmatPrintService] 打印失败:', e);
1083
- }
1084
- // 监听打印完成(兼容处理)
1085
- if (iframe.contentWindow) {
1086
- iframe.contentWindow.onafterprint = cleanup;
1087
- // 兜底:部分浏览器不触发 onafterprint
1088
- setTimeout(cleanup, 60000);
1089
- }
1090
- else {
1091
- cleanup();
1092
- }
1093
- }, 300);
1094
- };
1095
- // 使用 srcdoc 替代已废弃的 document.write
1096
- iframe.srcdoc = html;
1097
- }
1098
- /** HTML 转义 */
1099
- _escapeHtml(text) {
1100
- const div = document.createElement('div');
1101
- div.textContent = text;
1102
- return div.innerHTML;
1103
- }
1104
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatPrintService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1105
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatPrintService, providedIn: 'root' }); }
1106
- }
1107
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: CmatPrintService, decorators: [{
1108
- type: Injectable,
1109
- args: [{ providedIn: 'root' }]
1110
- }] });
1111
-
1112
- /**
1113
- * Generated bundle index. Do not edit.
1114
- */
1115
-
856
+ this._renderAndPrint(fullHtml, options);
857
+ }
858
+ _collectAllStyles() {
859
+ const cssTexts = [];
860
+ try {
861
+ for (const sheet of Array.from(document.styleSheets)) try {
862
+ const rules = sheet.cssRules;
863
+ if (!rules || rules.length === 0) continue;
864
+ let cssText = "";
865
+ for (const rule of Array.from(rules)) cssText += rule.cssText + "\n";
866
+ if (cssText.trim()) cssTexts.push(`<style>${this._transformMediaForPrint(cssText)}</style>`);
867
+ } catch {
868
+ if (sheet.href) cssTexts.push(`<link rel="stylesheet" href="${sheet.href}" media="all">`);
869
+ }
870
+ } catch (e) {
871
+ console.warn("[CmatPrintService] 样式收集异常:", e);
872
+ }
873
+ return cssTexts.join("\n ");
874
+ }
875
+ _transformMediaForPrint(css) {
876
+ return css.replace(/@media\s+screen\s+and\s*\(/g, "@media (").replace(/@media\s+screen\s*\{/g, "@media all {").replace(/@media\s+only\s+screen\s+and\s*\(/g, "@media (").replace(/@media\s+only\s+screen\s*\{/g, "@media all {");
877
+ }
878
+ _collectCssVariables() {
879
+ const vars = [];
880
+ const rootStyles = getComputedStyle(document.documentElement);
881
+ try {
882
+ for (const sheet of Array.from(document.styleSheets)) try {
883
+ const rules = sheet.cssRules;
884
+ if (!rules) continue;
885
+ for (const rule of Array.from(rules)) if (rule instanceof CSSStyleRule) {
886
+ const selector = rule.selectorText;
887
+ if (selector === ":root" || selector === "html" || selector === ":root, html") {
888
+ const props = Array.from({ length: rule.style.length }, (_, i) => rule.style[i]);
889
+ for (const prop of props) if (prop.startsWith("--")) vars.push(`${prop}: ${rule.style.getPropertyValue(prop)}`);
890
+ }
891
+ }
892
+ } catch {}
893
+ } catch (e) {
894
+ console.warn("[CmatPrintService] CSS变量收集异常:", e);
895
+ }
896
+ const prefixes = [
897
+ "--mdc-",
898
+ "--mat-",
899
+ "--md-",
900
+ "--tw-",
901
+ "--ck-",
902
+ "--color-",
903
+ "--border-"
904
+ ];
905
+ const rootProps = Array.from({ length: rootStyles.length }, (_, i) => rootStyles[i]);
906
+ for (const prop of rootProps) if (prop.startsWith("--") && prefixes.some((p) => prop.startsWith(p))) {
907
+ const value = rootStyles.getPropertyValue(prop);
908
+ if (value && !vars.some((v) => v.startsWith(prop + ":"))) vars.push(`${prop}: ${value.trim()}`);
909
+ }
910
+ return vars.join("; ");
911
+ }
912
+ _getPrintBodyClass() {
913
+ const bodyClasses = document.body.className.split(/\s+/);
914
+ const excludeClasses = /* @__PURE__ */ new Set([
915
+ "overflow-hidden",
916
+ "h-full",
917
+ "w-full",
918
+ "h-screen",
919
+ "w-screen"
920
+ ]);
921
+ return bodyClasses.filter((c) => c && !excludeClasses.has(c)).join(" ");
922
+ }
923
+ _renderAndPrint(html, options) {
924
+ const iframe = document.createElement("iframe");
925
+ iframe.style.position = "fixed";
926
+ iframe.style.left = "0";
927
+ iframe.style.top = "0";
928
+ iframe.style.width = "100vw";
929
+ iframe.style.height = "100vh";
930
+ iframe.style.border = "0";
931
+ iframe.style.visibility = "hidden";
932
+ iframe.style.zIndex = "-1";
933
+ iframe.style.pointerEvents = "none";
934
+ document.body.appendChild(iframe);
935
+ const cleanup = () => {
936
+ iframe.remove();
937
+ options?.afterPrint?.();
938
+ };
939
+ iframe.onload = () => {
940
+ setTimeout(() => {
941
+ try {
942
+ iframe.contentWindow?.focus();
943
+ iframe.contentWindow?.print();
944
+ } catch (e) {
945
+ console.error("[CmatPrintService] 打印失败:", e);
946
+ }
947
+ if (iframe.contentWindow) {
948
+ iframe.contentWindow.onafterprint = cleanup;
949
+ setTimeout(cleanup, 6e4);
950
+ } else cleanup();
951
+ }, 300);
952
+ };
953
+ iframe.srcdoc = html;
954
+ }
955
+ _escapeHtml(text) {
956
+ const div = document.createElement("div");
957
+ div.textContent = text;
958
+ return div.innerHTML;
959
+ }
960
+ static {
961
+ this.ɵfac = i0.ɵɵngDeclareFactory({
962
+ minVersion: "12.0.0",
963
+ version: "22.2.3",
964
+ ngImport: i0,
965
+ type: CmatPrintService,
966
+ deps: [],
967
+ target: i0.ɵɵFactoryTarget.Injectable
968
+ });
969
+ }
970
+ static {
971
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
972
+ minVersion: "12.0.0",
973
+ version: "22.2.3",
974
+ ngImport: i0,
975
+ type: CmatPrintService,
976
+ providedIn: "root"
977
+ });
978
+ }
979
+ };
980
+ i0.ɵɵngDeclareClassMetadata({
981
+ minVersion: "12.0.0",
982
+ version: "22.2.3",
983
+ ngImport: i0,
984
+ type: CmatPrintService,
985
+ decorators: [{
986
+ type: Injectable,
987
+ args: [{ providedIn: "root" }]
988
+ }]
989
+ });
1116
990
  export { CmatPrintService };
1117
- //# sourceMappingURL=cmat-services-print.mjs.map
991
+
992
+ //# sourceMappingURL=cmat-services-print.mjs.map