cui-print 1.0.28

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 (80) hide show
  1. package/README.md +29 -0
  2. package/dist/font/iconfont.css +151 -0
  3. package/dist/font/iconfont.js +1 -0
  4. package/dist/font/iconfont.json +247 -0
  5. package/dist/font/iconfont.ttf +0 -0
  6. package/dist/font/iconfont.woff +0 -0
  7. package/dist/font/iconfont.woff2 +0 -0
  8. package/dist/index.css +1 -0
  9. package/dist/index.es.js +51053 -0
  10. package/dist/index.umd.js +1030 -0
  11. package/dist/print-designer-api/create-style/create-base-component-style.js +116 -0
  12. package/dist/print-designer-api/create-style/create-complex-table-style.js +472 -0
  13. package/dist/print-designer-api/create-style/create-form-component-style.js +78 -0
  14. package/dist/print-designer-api/create-style/create-form-item-style.js +144 -0
  15. package/dist/print-designer-api/create-style/create-grid-style.js +49 -0
  16. package/dist/print-designer-api/create-style/create-table-layout-style.js +128 -0
  17. package/dist/print-designer-api/create-style/create-table-style.js +93 -0
  18. package/dist/print-designer-api/print-designer-helper.js +912 -0
  19. package/dist/print-designer-api/print-designer-style-helper.js +96 -0
  20. package/dist/print-designer-api/print-designer-utils.js +27 -0
  21. package/dist/print-designer-api/print-global-style/base.less +20 -0
  22. package/dist/print-designer-api/print-global-style/common.less +3 -0
  23. package/dist/print-designer-api/print-global-style/custom.less +4 -0
  24. package/dist/print-designer-api/print-global-style/index.css +812 -0
  25. package/dist/print-designer-api/print-global-style/index.js +813 -0
  26. package/dist/print-designer-api/print-global-style/index.less +9 -0
  27. package/dist/print-designer-api/print-global-style/print-base-component.less +123 -0
  28. package/dist/print-designer-api/print-global-style/print-container.less +57 -0
  29. package/dist/print-designer-api/print-global-style/print-continue/index.less +14 -0
  30. package/dist/print-designer-api/print-global-style/print-continue/print-complex-table/auto-continue-not-span.less +61 -0
  31. package/dist/print-designer-api/print-global-style/print-continue/print-complex-table/auto-continue-preview.less +12 -0
  32. package/dist/print-designer-api/print-global-style/print-continue/print-complex-table/auto-continue-span.less +88 -0
  33. package/dist/print-designer-api/print-global-style/print-continue/print-complex-table/fixed-continue.less +37 -0
  34. package/dist/print-designer-api/print-global-style/print-continue/print-complex-table/index.less +96 -0
  35. package/dist/print-designer-api/print-global-style/print-continue/print-complex-table/pagination-preview.less +12 -0
  36. package/dist/print-designer-api/print-global-style/print-continue/print-complex-table/pagination.less +61 -0
  37. package/dist/print-designer-api/print-global-style/print-form-component.less +161 -0
  38. package/dist/print-designer-api/print-global-style/print-form-item.less +162 -0
  39. package/dist/print-designer-api/print-global-style/printing.less +16 -0
  40. package/dist/print-designer-api/print-soket.js +31 -0
  41. package/dist/print-designer-api/use-create-html/create-html-utils.js +43 -0
  42. package/dist/print-designer-api/use-create-html/index.js +287 -0
  43. package/dist/print-designer-api/use-create-html/use-base-component-helper.js +129 -0
  44. package/dist/print-designer-api/use-create-html/use-complex-table-helper/complex-table-tools.js +129 -0
  45. package/dist/print-designer-api/use-create-html/use-complex-table-helper/create-table-header.js +111 -0
  46. package/dist/print-designer-api/use-create-html/use-complex-table-helper/index.js +87 -0
  47. package/dist/print-designer-api/use-create-html/use-complex-table-helper/use-auto-height-preview.js +84 -0
  48. package/dist/print-designer-api/use-create-html/use-complex-table-helper/use-auto-height.js +379 -0
  49. package/dist/print-designer-api/use-create-html/use-complex-table-helper/use-default.js +75 -0
  50. package/dist/print-designer-api/use-create-html/use-complex-table-helper/use-fixed-height.js +220 -0
  51. package/dist/print-designer-api/use-create-html/use-complex-table-helper/use-pagination-preview.js +84 -0
  52. package/dist/print-designer-api/use-create-html/use-complex-table-helper/use-pagination.js +272 -0
  53. package/dist/print-designer-api/use-create-html/use-form-component-helper.js +164 -0
  54. package/dist/print-designer-api/use-create-html/use-format/index.js +102 -0
  55. package/dist/print-designer-api/use-create-html/use-format/use-complex-table-auto.js +337 -0
  56. package/dist/print-designer-api/use-create-html/use-format/use-complex-table-fiexd.js +233 -0
  57. package/dist/print-designer-api/use-create-html/use-format/use-complex-table-pagination.js +286 -0
  58. package/dist/print-designer-api/use-create-html/use-grid-helper.js +35 -0
  59. package/dist/print-designer-api/use-create-html/use-table-layout-helper.js +213 -0
  60. package/dist/print-designer-api/use-create-print-js/index.js +147 -0
  61. package/dist/print-designer-api/use-create-print-js/use-base-component-helper.js +54 -0
  62. package/dist/print-designer-api/use-create-print-js/use-form-component-helper.js +4 -0
  63. package/dist/print-designer-api/use-create-print-js/use-table-layout-helper.js +5 -0
  64. package/dist/print-designer-images/demo.jpg +0 -0
  65. package/dist/print-designer-images/demo02.jpg +0 -0
  66. package/dist/style/default-style.css +137 -0
  67. package/dist/style/main.less +66 -0
  68. package/dist/test/base/designer-config.js +594 -0
  69. package/dist/test/base/index.js +3 -0
  70. package/dist/test/base/print-data.js +40 -0
  71. package/dist/test/complex-table/designer-config.js +1668 -0
  72. package/dist/test/complex-table/index.js +3 -0
  73. package/dist/test/complex-table/print-data.js +294 -0
  74. package/dist/test/form/designer-config.js +2057 -0
  75. package/dist/test/form/index.js +3 -0
  76. package/dist/test/form/print-data.js +38 -0
  77. package/dist/test/index.js +4 -0
  78. package/dist/wui-print-designer-plugins/JsBarcode.all.min.js +2 -0
  79. package/dist/wui-print-designer-plugins/qrcode.min.js +1 -0
  80. package/package.json +65 -0
@@ -0,0 +1,286 @@
1
+ import { deepCopy, extractNumbers } from "../../print-designer-utils";
2
+ export default ({ printData, printConfig, formConfig, layoutConfig, tablePaginationElements } = {}) => {
3
+ const formatLayoutConfig = () => {
4
+ console.log("【复杂表格分页】formatLayoutConfig入参===>", {
5
+ printData: deepCopy(printData),
6
+ printConfig: deepCopy(printConfig),
7
+ formConfig: deepCopy(formConfig),
8
+ layoutConfig: deepCopy(layoutConfig),
9
+ tablePaginationElements
10
+ });
11
+ let paginationDetails = _getPaginationDetails();
12
+ console.log("【复杂表格分页】获取续打信息====>paginationDetails", paginationDetails);
13
+ if (!paginationDetails.paginationState || !paginationDetails.dataField) {
14
+ return layoutConfig;
15
+ }
16
+ printData[paginationDetails.dataField] = _formatTableData({ paginationDetails });
17
+ let continueAllData = printData[paginationDetails.dataField];
18
+ console.log("【复杂表格分页】处理后的数据====>continueAllData", deepCopy(continueAllData));
19
+ let continueSplitData = _splitPaginationAllData({
20
+ continueAllData,
21
+ pageMaxRow: paginationDetails.pageMaxRow
22
+ });
23
+ console.log("【复杂表格分页】拆分数据====>continueSplitData", continueSplitData);
24
+ let oldLayoutConfig = _filterLayoutConfig();
25
+ let layoutConfigExcludingLastPage = _formatLayoutConfigExcludingLastPage({ oldLayoutConfig });
26
+ let newLayoutConfig = [];
27
+ continueSplitData.forEach((item, index) => {
28
+ let currentPage = index + 1;
29
+ let pageLayoutConfig = _createPageLayoutConfig({
30
+ oldLayoutConfig,
31
+ layoutConfigExcludingLastPage,
32
+ paginationDetails,
33
+ pageComplateTableData: item,
34
+ currentPage: currentPage,
35
+ pageCount: continueSplitData.length
36
+ });
37
+ newLayoutConfig.push(...pageLayoutConfig);
38
+ });
39
+ return newLayoutConfig;
40
+ };
41
+ function _createPageLayoutConfig({
42
+ oldLayoutConfig,
43
+ layoutConfigExcludingLastPage,
44
+ paginationDetails,
45
+ pageComplateTableData,
46
+ currentPage,
47
+ pageCount
48
+ } = {}) {
49
+ let pageLayoutConfig;
50
+ if (currentPage < pageCount) {
51
+ // 不是最后一页 需要过滤在最后一页显示的元素
52
+ pageLayoutConfig = deepCopy(layoutConfigExcludingLastPage);
53
+ } else {
54
+ pageLayoutConfig = deepCopy(oldLayoutConfig);
55
+ }
56
+ let newField = `_pagination_${paginationDetails.dataField}_${currentPage}`;
57
+ let nowTablePaginationConfig = {
58
+ type: "pagination_default",
59
+ currentPage,
60
+ blankRowCount: 0
61
+ };
62
+ let layoutConfigIndex = _getComplexTableIndex({ nowLayoutConfig: pageLayoutConfig });
63
+ pageLayoutConfig[layoutConfigIndex].props.field = newField;
64
+ printData[newField] = deepCopy(pageComplateTableData);
65
+
66
+ // 最后一页还有空白行
67
+ if (currentPage == pageCount && pageComplateTableData.length < paginationDetails.pageMaxRow) {
68
+ nowTablePaginationConfig.blankRowCount = paginationDetails.pageMaxRow - pageComplateTableData.length;
69
+ nowTablePaginationConfig.type = "pagination_afterBlankRow";
70
+ }
71
+ pageLayoutConfig[layoutConfigIndex]._tablePaginationConfig = nowTablePaginationConfig;
72
+ if (pageCount > 1) {
73
+ if (currentPage > 1) {
74
+ // 添加分页上边距
75
+ pageLayoutConfig.unshift({
76
+ type: "pageTop"
77
+ });
78
+ }
79
+ if (currentPage < pageCount) {
80
+ // 添加分页下边距
81
+ pageLayoutConfig.push({
82
+ type: "pageBottom"
83
+ });
84
+ // 添加分页
85
+ pageLayoutConfig.push({
86
+ type: "pageBreak"
87
+ });
88
+ }
89
+ }
90
+ return pageLayoutConfig;
91
+ }
92
+ function _filterLayoutConfig() {
93
+ // 只保留第一个续打表格
94
+ let newLayoutConfig = [];
95
+ let paginationConfigItem = false;
96
+ layoutConfig.forEach((item, index) => {
97
+ let nowProps = !!item.props ? item.props : {};
98
+ if (item.type == "complexTable" && !!nowProps.canContinue && !!paginationConfigItem) {
99
+ return;
100
+ }
101
+ if (item.type == "complexTable" && !!nowProps.canContinue) {
102
+ paginationConfigItem = item;
103
+ }
104
+ newLayoutConfig.push(item);
105
+ });
106
+ return newLayoutConfig;
107
+ }
108
+ function _getPaginationDetails() {
109
+ let paginationDetails = {
110
+ paginationState: false
111
+ };
112
+ if (!layoutConfig || layoutConfig.length <= 0) {
113
+ return paginationDetails;
114
+ }
115
+ let paginationConfigItem = false;
116
+ layoutConfig.forEach((item, index) => {
117
+ if (!!paginationConfigItem) {
118
+ return;
119
+ }
120
+ let nowProps = !!item.props ? item.props : {};
121
+ if (item.type == "complexTable" && !!nowProps.isPaginationMode) {
122
+ paginationConfigItem = item;
123
+ }
124
+ });
125
+ if (!paginationConfigItem) {
126
+ return paginationDetails;
127
+ }
128
+ let paginationConfigItemProps = !!paginationConfigItem.props ? paginationConfigItem.props : {};
129
+ let paginationConfigItemStyle = !!paginationConfigItem.style ? paginationConfigItem.style : {};
130
+ paginationDetails.paginationState = true;
131
+ paginationDetails.paginationConfigItem = deepCopy(paginationConfigItem);
132
+ paginationDetails.dataField = !!paginationConfigItemProps.field ? paginationConfigItemProps.field : "";
133
+ paginationDetails.pageMaxRow = !!paginationConfigItemProps.perPageMaxRow ? paginationConfigItemProps.perPageMaxRow : 0;
134
+ paginationDetails.contentRowHeight = !!paginationConfigItemProps.contentRowHeight
135
+ ? paginationConfigItemProps.contentRowHeight
136
+ : 0;
137
+ if (!paginationConfigItemStyle.contentCell_borderWidth && !!paginationConfigItemStyle.contentCell_borderTopWidth) {
138
+ paginationDetails.contentRowBorderTop = extractNumbers(paginationConfigItemStyle.contentCell_borderTopWidth);
139
+ } else if (!!paginationConfigItemStyle.contentCell_borderWidth) {
140
+ paginationDetails.contentRowBorderTop = extractNumbers(paginationConfigItemStyle.contentCell_borderWidth);
141
+ } else {
142
+ paginationDetails.contentRowBorderTop = 0;
143
+ }
144
+ if (!paginationConfigItemStyle.contentCell_borderWidth && !!paginationConfigItemStyle.contentCell_borderBottomWidth) {
145
+ paginationDetails.contentRowBorderBottom = extractNumbers(paginationConfigItemStyle.contentCell_borderBottomWidth);
146
+ } else if (!!paginationConfigItemStyle.contentCell_borderWidth) {
147
+ paginationDetails.contentRowBorderBottom = extractNumbers(paginationConfigItemStyle.contentCell_borderWidth);
148
+ } else {
149
+ paginationDetails.contentRowBorderBottom = 0;
150
+ }
151
+ // 页尾向上合并行数
152
+ if (!!paginationConfigItemProps.mergedFooterRowCount || paginationConfigItemProps.mergedFooterRowCount === 0) {
153
+ paginationDetails.mergedFooterRowCount = paginationConfigItemProps.mergedFooterRowCount;
154
+ } else {
155
+ paginationDetails.mergedFooterRowCount = 1;
156
+ }
157
+ //_printDataTotal内部逻辑使用
158
+ paginationDetails._printDataTotal = 0;
159
+ return paginationDetails;
160
+ }
161
+ function _formatTableData({ paginationDetails } = {}) {
162
+ let oldTableData = [];
163
+ let tempTableData = [];
164
+ let tableDataGroup = [];
165
+ if (!!printData[paginationDetails.dataField]) {
166
+ oldTableData = deepCopy(printData[paginationDetails.dataField]);
167
+ }
168
+ tempTableData.push(...oldTableData);
169
+ tempTableData.forEach((item, index) => {
170
+ let groupItem = [];
171
+ let excessRows = _getContentTrExcessRows({ paginationDetails, index, rowData: item });
172
+ item._paginationMode_excessRowsLength = excessRows.length;
173
+ groupItem.push(item, ...excessRows);
174
+ tableDataGroup.push(groupItem);
175
+ });
176
+ let newTableData = [];
177
+ tableDataGroup.forEach((groupItem, groupIndex) => {
178
+ if (groupIndex.length > 1) {
179
+ groupItem[0]._paginationMode_type = "excessContentRow";
180
+ } else {
181
+ groupItem[0]._paginationMode_type = "notExcess";
182
+ }
183
+ newTableData.push(...groupItem);
184
+ });
185
+ return newTableData;
186
+ }
187
+ function _getContentTrExcessRows({ paginationDetails, index, rowData }) {
188
+ // 获取超出行数
189
+ const trElement = tablePaginationElements.querySelector(`[content-index="${index}"]`);
190
+ let trContentMinHeight =
191
+ trElement.clientHeight - paginationDetails.contentRowBorderTop - paginationDetails.contentRowBorderBottom;
192
+ let trContentHeight = trContentMinHeight;
193
+ let contentTextElements = trElement.querySelectorAll(".content-text");
194
+ for (let i = 0; i < contentTextElements.length; i++) {
195
+ let element = contentTextElements[i];
196
+ if (element.offsetHeight > trContentHeight) {
197
+ trContentHeight = element.offsetHeight;
198
+ }
199
+ }
200
+ let excessRows = [];
201
+ let excessRowsLength = (trContentHeight - paginationDetails.contentRowHeight) / paginationDetails.contentRowHeight;
202
+ excessRowsLength = Math.ceil(excessRowsLength);
203
+ paginationDetails._printDataTotal += excessRowsLength + 1;
204
+ // 剩余行数
205
+ let pageSurplus = paginationDetails.pageMaxRow - (paginationDetails._printDataTotal % paginationDetails.pageMaxRow);
206
+ if (pageSurplus >= 0 && pageSurplus <= paginationDetails.mergedFooterRowCount) {
207
+ excessRowsLength += pageSurplus;
208
+ paginationDetails._printDataTotal += pageSurplus;
209
+ }
210
+ for (let i = 0; i < excessRowsLength; i++) {
211
+ let newRowData = deepCopy(rowData);
212
+ newRowData._paginationMode_type = "excessBlankRow";
213
+ newRowData._paginationMode_excessIndex = i;
214
+ newRowData._paginationMode_excessRowsLength = excessRowsLength;
215
+ excessRows.push(newRowData);
216
+ }
217
+ return excessRows;
218
+ }
219
+ function _splitPaginationAllData({ continueAllData, pageMaxRow, continueBeforeRowCount }) {
220
+ let result = [];
221
+ let newAllData = continueAllData;
222
+ for (let i = 0; i < newAllData.length; i += pageMaxRow) {
223
+ result.push(newAllData.slice(i, i + pageMaxRow));
224
+ }
225
+ return result;
226
+ }
227
+ function _formatLayoutConfigExcludingLastPage({ oldLayoutConfig }) {
228
+ // 排除最后一页显示的元素
229
+ let newLayoutConfig = [];
230
+ let layoutConfigCopy = deepCopy(oldLayoutConfig);
231
+ layoutConfigCopy.forEach((item, index) => {
232
+ if (item.type == "grid") {
233
+ item.children.forEach((gridItem, gridItemIndex) => {
234
+ let gridItemCopy = deepCopy(gridItem);
235
+ gridItem.children = [];
236
+ gridItemCopy.children.forEach((componentItem, componentIndex) => {
237
+ if (!__getExcludingState(componentItem)) {
238
+ gridItem.children.push(componentItem);
239
+ }
240
+ });
241
+ });
242
+ newLayoutConfig.push(item);
243
+ } else if (item.type == "tableLayout") {
244
+ let itemCopy = deepCopy(item);
245
+ item.children = [];
246
+ itemCopy.children.forEach((componentItem, componentIndex) => {
247
+ if (!__getExcludingState(componentItem)) {
248
+ item.children.push(componentItem);
249
+ }
250
+ });
251
+ newLayoutConfig.push(item);
252
+ } else if (item.type == "complexTable") {
253
+ newLayoutConfig.push(item);
254
+ } else {
255
+ if (!__getExcludingState(item)) {
256
+ newLayoutConfig.push(item);
257
+ }
258
+ }
259
+ });
260
+ function __getExcludingState(componentItem) {
261
+ if (!componentItem.props) {
262
+ return false;
263
+ }
264
+ if (!!componentItem.props.showOnLastPage) {
265
+ return true;
266
+ }
267
+ return false;
268
+ }
269
+ return newLayoutConfig;
270
+ }
271
+ function _getComplexTableIndex({ nowLayoutConfig }) {
272
+ let layoutConfigIndex = -1;
273
+ nowLayoutConfig.forEach((item, index) => {
274
+ if (layoutConfigIndex >= 0) {
275
+ return;
276
+ }
277
+ if (item.type == "complexTable") {
278
+ layoutConfigIndex = index;
279
+ }
280
+ });
281
+ return layoutConfigIndex;
282
+ }
283
+ return {
284
+ formatLayoutConfig
285
+ };
286
+ };
@@ -0,0 +1,35 @@
1
+ import printDesignerStyleHelper from "../print-designer-style-helper";
2
+ import createHtmlUtils from "./create-html-utils";
3
+ export default ({ printData, printConfig, formConfig, layoutConfig, createHtmlByComponentItem, errorLogs } = {}) => {
4
+ const createGridHtml = (item) => {
5
+ let gridHtml = "";
6
+ if (!item.children || item.children.length <= 0) {
7
+ return gridHtml;
8
+ }
9
+ item.children.forEach((gridItem, gridItemIndex) => {
10
+ gridHtml += `<div class="print-grid-item" style="${printDesignerStyleHelper.createGridItemStyle({
11
+ styleConfig: gridItem.style,
12
+ props: gridItem.props
13
+ })}">${_createGridItemHtml(gridItem)}</div>`;
14
+ });
15
+ gridHtml = `<div class="print-grid ${createHtmlUtils.formatComponentClass({
16
+ componentItem: item
17
+ })}" style="${printDesignerStyleHelper.createGridStyle({
18
+ styleConfig: item.style
19
+ })}">${gridHtml}</div>`;
20
+ return gridHtml;
21
+ };
22
+ function _createGridItemHtml(gridItem) {
23
+ let gridItemHtml = "";
24
+ if (!gridItem.children || gridItem.children.length <= 0) {
25
+ return gridItemHtml;
26
+ }
27
+ gridItem.children.forEach((componentItem, componentIndex) => {
28
+ gridItemHtml += createHtmlByComponentItem(componentItem);
29
+ });
30
+ return gridItemHtml;
31
+ }
32
+ return {
33
+ createGridHtml
34
+ };
35
+ };
@@ -0,0 +1,213 @@
1
+ import printDesignerStyleHelper from "../print-designer-style-helper";
2
+ import createHtmlUtils from "./create-html-utils";
3
+ export default ({ printData, printConfig, formConfig, layoutConfig, createHtmlByComponentItem, errorLogs } = {}) => {
4
+ const createTableLayoutHtml = (item) => {
5
+ let tableLayoutHtml = "";
6
+ if (!item.props || !item.props.row || !item.props.col) {
7
+ return tableLayoutHtml;
8
+ }
9
+ let { spanCellDict, spanCellList } = _createTableLayoutSpanDetails(item);
10
+ let rowLength = item.props.row;
11
+ let colLength = item.props.col;
12
+ for (let rowIndex = 0; rowIndex < rowLength; rowIndex++) {
13
+ let cellHtml = ``;
14
+ for (let colIndex = 0; colIndex < colLength; colIndex++) {
15
+ let nowCellHtml = _getCellHtml({ rowIndex, colIndex, spanCellList, tableLayoutDetails: item });
16
+ cellHtml += nowCellHtml;
17
+ }
18
+ let rowHtml = `<tr>${cellHtml}</tr>`;
19
+ tableLayoutHtml += rowHtml;
20
+ }
21
+ tableLayoutHtml = `<table class="print-table-layout ${createHtmlUtils.formatComponentClass({
22
+ componentItem: item
23
+ })}" style="${printDesignerStyleHelper.createTableLayoutStyle({
24
+ styleConfig: item.style
25
+ })}" cellspacing="0" cellpadding="0">${tableLayoutHtml}</table>`;
26
+ return tableLayoutHtml;
27
+ };
28
+ function _getCellId({ rowIndex, colIndex } = {}) {
29
+ return `${rowIndex}-${colIndex}`;
30
+ }
31
+ function _createTableLayoutSpanDetails(tableLayoutDetails) {
32
+ let spanCellDict = {};
33
+ let spanCellList = [];
34
+ if (!tableLayoutDetails.layout || tableLayoutDetails.layout.length <= 0) {
35
+ return { spanCellDict, spanCellList };
36
+ }
37
+ tableLayoutDetails.layout.forEach((item, index) => {
38
+ let rowspan = !!item.rowspan ? item.rowspan : 1;
39
+ let colspan = !!item.colspan ? item.colspan : 1;
40
+ let minRowIndex = item.rowIndex;
41
+ let maxRowIndex = item.rowIndex + rowspan - 1;
42
+ let minColIndex = item.colIndex;
43
+ let maxColIndex = item.colIndex + colspan - 1;
44
+ let itemSpanCellList = [];
45
+ for (let rowIndex = minRowIndex; rowIndex <= maxRowIndex; rowIndex++) {
46
+ for (let colIndex = minColIndex; colIndex <= maxColIndex; colIndex++) {
47
+ let newCellDetails;
48
+ if (rowIndex === item.rowIndex && colIndex === item.colIndex) {
49
+ newCellDetails = {
50
+ rowIndex,
51
+ colIndex,
52
+ rowspan,
53
+ colspan,
54
+ show: true
55
+ };
56
+ } else {
57
+ newCellDetails = {
58
+ rowIndex,
59
+ colIndex,
60
+ rowspan,
61
+ colspan,
62
+ startRowIndex: item.rowIndex,
63
+ startColIndex: item.colIndex,
64
+ show: false
65
+ };
66
+ }
67
+ itemSpanCellList.push(newCellDetails);
68
+ }
69
+ }
70
+ spanCellDict[_getCellId({ rowIndex: item.rowIndex, colIndex: item.colIndex })] = itemSpanCellList;
71
+ spanCellList.push(...itemSpanCellList);
72
+ });
73
+ return { spanCellDict, spanCellList };
74
+ }
75
+ function _getCellShow({ rowIndex, colIndex, spanCellList }) {
76
+ if (!spanCellList || spanCellList.length <= 0) {
77
+ return true;
78
+ }
79
+ let cellItem = spanCellList.find((item, index) => {
80
+ return rowIndex === item.rowIndex && item.colIndex === colIndex;
81
+ });
82
+ if (!cellItem) {
83
+ return true;
84
+ }
85
+ if (!!cellItem) {
86
+ return cellItem.show;
87
+ }
88
+ }
89
+ function _getRowspan({ rowIndex, colIndex, layout } = {}) {
90
+ let nowRowspan = 1;
91
+ if (!layout || layout.length <= 0) {
92
+ return nowRowspan;
93
+ }
94
+ let cellItem = layout.find((item, index) => {
95
+ return rowIndex === item.rowIndex && item.colIndex === colIndex;
96
+ });
97
+ if (!cellItem) {
98
+ return nowRowspan;
99
+ }
100
+ if (!!cellItem && !!cellItem.rowspan) {
101
+ return cellItem.rowspan;
102
+ }
103
+ return nowRowspan;
104
+ }
105
+ function _getColspan({ rowIndex, colIndex, layout } = {}) {
106
+ let nowColspan = 1;
107
+ if (!layout || layout.length <= 0) {
108
+ return nowColspan;
109
+ }
110
+ let cellItem = layout.find((item, index) => {
111
+ return rowIndex === item.rowIndex && item.colIndex === colIndex;
112
+ });
113
+ if (!cellItem) {
114
+ return nowColspan;
115
+ }
116
+ if (!!cellItem && !!cellItem.colspan) {
117
+ return cellItem.colspan;
118
+ }
119
+ return nowColspan;
120
+ }
121
+ function _getCellHtml({ rowIndex, colIndex, spanCellList, tableLayoutDetails } = {}) {
122
+ let cellShow = _getCellShow({ rowIndex, colIndex, spanCellList });
123
+ let cellHtml = "";
124
+ if (!cellShow) {
125
+ return "";
126
+ }
127
+ let layout = tableLayoutDetails.layout;
128
+ let styleRules = tableLayoutDetails.styleRules;
129
+ let styleRulesId = printDesignerStyleHelper.getTableLayoutStyleRulesId({
130
+ rowIndex,
131
+ colIndex
132
+ });
133
+ let tdStyleConfig = false;
134
+ if (!!styleRules && !!styleRules[styleRulesId]) {
135
+ tdStyleConfig = styleRules[styleRulesId];
136
+ }
137
+ let slashHtml = "";
138
+ let componentsHtml = "";
139
+ if (!!tdStyleConfig.container_custom_slash) {
140
+ // 有斜线
141
+ slashHtml = _createSlashHtml({
142
+ tableLayoutId: tableLayoutDetails.id,
143
+ rowIndex,
144
+ colIndex,
145
+ tableLayoutStyleConfig: tableLayoutDetails.style,
146
+ tdStyleConfig
147
+ });
148
+ } else {
149
+ // 没有斜线才会渲染组件
150
+ let componentList = _getComponentList({ rowIndex, colIndex, tableLayoutDetails });
151
+ componentList.forEach((componentItem, componentIndex) => {
152
+ componentsHtml += createHtmlByComponentItem(componentItem);
153
+ });
154
+ }
155
+ cellHtml = `<td rowspan="${_getRowspan({
156
+ rowIndex,
157
+ colIndex,
158
+ layout
159
+ })}" colspan="${_getColspan({
160
+ rowIndex,
161
+ colIndex,
162
+ layout
163
+ })}" style="${printDesignerStyleHelper.createTableLayoutTdStyle({
164
+ tableLayoutStyleConfig: tableLayoutDetails.style,
165
+ tdStyleConfig
166
+ })}">${slashHtml}<div class="print-table-layout_td-container" style="${printDesignerStyleHelper.createTableLayoutTdContainerStyle(
167
+ {
168
+ tableLayoutStyleConfig: tableLayoutDetails.style,
169
+ tdStyleConfig
170
+ }
171
+ )}">${componentsHtml}</div></td>`;
172
+ return cellHtml;
173
+ }
174
+ function _getComponentList({ rowIndex, colIndex, tableLayoutDetails } = {}) {
175
+ let componentList = [];
176
+ if (!tableLayoutDetails || !tableLayoutDetails.children || tableLayoutDetails.children.length <= 0) {
177
+ return componentList;
178
+ }
179
+ tableLayoutDetails.children.forEach((componentItem, componentIndex) => {
180
+ if (componentItem.rowIndex === rowIndex && componentItem.colIndex === colIndex) {
181
+ componentList.push(componentItem);
182
+ }
183
+ });
184
+ return componentList;
185
+ }
186
+ function _createSlashHtml({ tableLayoutId, rowIndex, colIndex, tableLayoutStyleConfig, tdStyleConfig } = {}) {
187
+ let slashContainerHtml = "";
188
+ let slashHtml = "";
189
+ let slashTextLeftHtml = "";
190
+ let slashTexRightHtml = "";
191
+ let slashTexLeft = "";
192
+ let slashTexRight = "";
193
+ if (!!tdStyleConfig && !!tdStyleConfig.container_custom_slashTextLeft) {
194
+ slashTexLeft = tdStyleConfig.container_custom_slashTextLeft;
195
+ }
196
+ if (!!tdStyleConfig && !!tdStyleConfig.container_custom_slashTextRight) {
197
+ slashTexRight = tdStyleConfig.container_custom_slashTextRight;
198
+ }
199
+ slashHtml = `<div class="_p-t-l_td-slash_slash"></div>`;
200
+ slashTextLeftHtml = `<div class="_p-t-l_td-slash_left">${slashTexLeft}</div>`;
201
+ slashTexRightHtml = `<div class="_p-t-l_td-slash_right">${slashTexRight}</div>`;
202
+ slashContainerHtml = `<div id="${tableLayoutId}_${_getCellId({
203
+ rowIndex,
204
+ colIndex
205
+ })}_slash" class="print-table-layout_td-slash print-table-layout_td-slash--${
206
+ tdStyleConfig.container_custom_slashDirection
207
+ }">${slashTextLeftHtml}${slashHtml}${slashTexRightHtml}</div>`;
208
+ return slashContainerHtml;
209
+ }
210
+ return {
211
+ createTableLayoutHtml
212
+ };
213
+ };
@@ -0,0 +1,147 @@
1
+ import useBaseComponentHelper from "./use-base-component-helper";
2
+ import useFormComponentHelper from "./use-form-component-helper";
3
+ import useTableLayoutHelper from "./use-table-layout-helper";
4
+ export default ({ printData = {}, layoutConfig } = {}) => {
5
+ const baseComponentHelper = useBaseComponentHelper({
6
+ printData,
7
+ layoutConfig
8
+ });
9
+ const formComponentHelper = useFormComponentHelper({
10
+ printData,
11
+ layoutConfig
12
+ });
13
+ const tableLayoutHelper = useTableLayoutHelper({
14
+ printData,
15
+ layoutConfig
16
+ });
17
+ const createJsStringByComponentItem = (componentItem) => {
18
+ let newJsString = "";
19
+ if (componentItem.type == "barcode") {
20
+ newJsString = baseComponentHelper.createBarcodeJsString(componentItem);
21
+ return newJsString;
22
+ }
23
+ if (componentItem.type == "qrcode") {
24
+ newJsString = baseComponentHelper.creatQrcodeJsString(componentItem);
25
+ return newJsString;
26
+ }
27
+ return newJsString;
28
+ };
29
+ const createJsStringOnGrid = (item) => {
30
+ let newJsString = "";
31
+ if (!item.children || item.children.length <= 0) {
32
+ return newJsString;
33
+ }
34
+ item.children.forEach((gridItem, gridItemIndex) => {
35
+ if (!gridItem.children || gridItem.children.length <= 0) {
36
+ return;
37
+ }
38
+ gridItem.children.forEach((componentItem, componentIndex) => {
39
+ newJsString += createJsStringByComponentItem(componentItem);
40
+ });
41
+ });
42
+ return newJsString;
43
+ };
44
+ const createJsStringOnTablelayout = (item) => {
45
+ let newJsString = "";
46
+ let styleRules = !!item.styleRules ? item.styleRules : {};
47
+ let children = !!item.children ? item.children : [];
48
+ Object.keys(styleRules).forEach((key, index) => {
49
+ let nowStyleRule = styleRules[key];
50
+ if (!nowStyleRule.container_custom_slash) {
51
+ return;
52
+ }
53
+ newJsString += `setTableLayoutTdSlashStyle("${item.id}_${key}_slash","${nowStyleRule.container_custom_slashDirection}");\n`;
54
+ });
55
+ children.forEach((componentItem, componentIndex) => {
56
+ newJsString += createJsStringByComponentItem(componentItem);
57
+ });
58
+ return newJsString;
59
+ };
60
+ const createJsStringByComplexTable = (item) => {
61
+ let newJsString = "";
62
+ let headerRules = !!item.headerRules ? item.headerRules : {};
63
+ Object.keys(headerRules).forEach((key, index) => {
64
+ let nowHeaderRule = headerRules[key];
65
+ if (!nowHeaderRule.props || !nowHeaderRule.props.slash) {
66
+ return;
67
+ }
68
+ newJsString += `setComplexTableHeaderTdSlashStyleBySlashName("${item.id}_header_${key}_slash","${nowHeaderRule.props.slashDirection}");\n`;
69
+ });
70
+ return newJsString;
71
+ };
72
+ const createBaseJsString = () => {
73
+ const setTableLayoutTdSlashStyle = `
74
+ function setTableLayoutTdSlashStyle(containerId, direction) {
75
+ let slashContainerDom = document.getElementById(containerId);
76
+ if (!slashContainerDom) {
77
+ return;
78
+ }
79
+ let parent = slashContainerDom.parentElement; // 获取祖父元素
80
+ let slashDom = parent.querySelector("._p-t-l_td-slash_slash");
81
+ let width = parent.clientWidth;
82
+ let height = parent.clientHeight;
83
+ let slashWidth = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
84
+ let slashDeg = (Math.atan(height / width) * 180) / Math.PI;
85
+ slashDom.style.width = slashWidth + "px";
86
+ slashDom.style.transformOrigin = "top left";
87
+ if (direction == "top-left") {
88
+ slashDom.style.transform = "rotate(" + slashDeg + "deg)";
89
+ } else {
90
+ slashDom.style.transform = "rotate(-" + slashDeg + "deg)";
91
+ }
92
+ }
93
+ `;
94
+ const setComplexTableHeaderTdSlashStyleBySlashName = `
95
+ function setComplexTableHeaderTdSlashStyleBySlashName(slashName, direction) {
96
+ if (!slashName) {
97
+ return;
98
+ }
99
+ const slashElements = document.querySelectorAll('[name="'+ slashName +'"]');
100
+ slashElements.forEach((element) => {
101
+ setComplexTableHeaderTdSlashStyle(element, direction);
102
+ });
103
+ }
104
+ `;
105
+ const setComplexTableHeaderTdSlashStyle = `
106
+ function setComplexTableHeaderTdSlashStyle(slashContainerDom, direction) {
107
+ if (!slashContainerDom) {
108
+ return;
109
+ }
110
+ let parent = slashContainerDom.parentElement; // 获取祖父元素
111
+ let slashDom = parent.querySelector("._p-c-t_td-slash_slash");
112
+ let width = parent.clientWidth;
113
+ let height = parent.clientHeight;
114
+ let slashWidth = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
115
+ let slashDeg = (Math.atan(height / width) * 180) / Math.PI;
116
+ slashDom.style.width = slashWidth + "px";
117
+ slashDom.style.transformOrigin = "top left";
118
+ if (direction == "top-left") {
119
+ slashDom.style.transform = "rotate(" + slashDeg + "deg)";
120
+ } else {
121
+ slashDom.style.transform = "rotate(-" + slashDeg + "deg)";
122
+ }
123
+ }
124
+ `;
125
+ const createQRCode = `
126
+ function createQRCode(name, qrcodeConfig) {
127
+ let qrElements = document.getElementsByName(name);
128
+ for (let i = 0; i < qrElements.length; i++) {
129
+ const element = qrElements[i];
130
+ let qrcode = new QRCode(element, qrcodeConfig);
131
+ }
132
+ }
133
+ `;
134
+ return `
135
+ ${setTableLayoutTdSlashStyle}
136
+ ${setComplexTableHeaderTdSlashStyleBySlashName}
137
+ ${setComplexTableHeaderTdSlashStyle}
138
+ ${createQRCode}`;
139
+ };
140
+ return {
141
+ createJsStringByComponentItem,
142
+ createJsStringOnGrid,
143
+ createJsStringOnTablelayout,
144
+ createJsStringByComplexTable,
145
+ createBaseJsString
146
+ };
147
+ };