@bchr/bchr-front-lib 0.6.9 → 0.6.11
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.
|
@@ -1,374 +1,373 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
exportPlugin.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
let
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
console.log('
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
let
|
|
124
|
-
let
|
|
125
|
-
let
|
|
126
|
-
let
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
worksheet.
|
|
132
|
-
worksheet.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
*
|
|
191
|
-
* @
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
let
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
let
|
|
205
|
-
let
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
let
|
|
212
|
-
let
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
let
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
let
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
columnStep
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
* [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
|
|
272
|
-
* [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
|
|
273
|
-
* [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
|
|
274
|
-
*
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
let
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
let
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
let
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
export default ExcelKits;
|
|
1
|
+
import * as ExcelJS from "exceljs/dist/exceljs.bare.js";
|
|
2
|
+
import {saveAs} from "file-saver";
|
|
3
|
+
import Values from "./Values";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const DEFAULT_BORDER_COLOR_FOR_EXCEL = "CCCCCC";
|
|
7
|
+
const DEFAULT_FG_COLOR_FOR_EXCEL = "FFFFFF";
|
|
8
|
+
const DEFAULT_COL_HEADER_BG_COLOR = "F2F3F5";
|
|
9
|
+
|
|
10
|
+
const excelHeaderRowStyle = {
|
|
11
|
+
font: {
|
|
12
|
+
size: 10,
|
|
13
|
+
bold: true
|
|
14
|
+
},
|
|
15
|
+
alignment: {
|
|
16
|
+
vertical: 'middle',
|
|
17
|
+
horizontal: 'center'
|
|
18
|
+
},
|
|
19
|
+
fill: {
|
|
20
|
+
type: 'pattern',
|
|
21
|
+
pattern: 'solid',
|
|
22
|
+
fgColor: {
|
|
23
|
+
argb: DEFAULT_COL_HEADER_BG_COLOR
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
border: {
|
|
27
|
+
top: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
|
|
28
|
+
left: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
|
|
29
|
+
bottom: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
|
|
30
|
+
right: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const excelBodyRowStyle = {
|
|
35
|
+
font: {
|
|
36
|
+
size: 10,
|
|
37
|
+
bold: true
|
|
38
|
+
},
|
|
39
|
+
alignment: {
|
|
40
|
+
vertical: 'middle',
|
|
41
|
+
horizontal: 'center'
|
|
42
|
+
},
|
|
43
|
+
fill: {
|
|
44
|
+
type: 'pattern',
|
|
45
|
+
pattern: 'solid',
|
|
46
|
+
fgColor: {
|
|
47
|
+
argb: DEFAULT_FG_COLOR_FOR_EXCEL
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
border: {
|
|
51
|
+
top: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
|
|
52
|
+
left: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
|
|
53
|
+
bottom: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
|
|
54
|
+
right: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const ExcelKits = {
|
|
59
|
+
|
|
60
|
+
exportHandsontableData2CSVFile(handsonTableInstance, fileName) {
|
|
61
|
+
if (handsonTableInstance === null || handsonTableInstance === void 0) {
|
|
62
|
+
throw new IllegalArgumentError("HandsontableInstance is null for ExcelKits#exportHandsontableData2CSVFile");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (Values.isBlankString(fileName)) {
|
|
66
|
+
fileName = `${t('ui.export.csv.file')}-` + new Date().getTime();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const exportPlugin = handsonTableInstance.getPlugin('exportFile');
|
|
70
|
+
exportPlugin.downloadFile('csv', {
|
|
71
|
+
bom: false,
|
|
72
|
+
columnDelimiter: ',',
|
|
73
|
+
columnHeaders: false,
|
|
74
|
+
exportHiddenColumns: true,
|
|
75
|
+
exportHiddenRows: true,
|
|
76
|
+
fileExtension: 'csv',
|
|
77
|
+
filename: fileName,
|
|
78
|
+
mimeType: 'text/csv',
|
|
79
|
+
rowDelimiter: '\r\n',
|
|
80
|
+
rowHeaders: true
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
exportHandsontableData2ExcelFile(handsontableInstance, fileName) {
|
|
85
|
+
if (handsontableInstance === null || handsontableInstance === void 0) {
|
|
86
|
+
throw new IllegalArgumentError("HandsontableInstance is null for ExcelKits#exportHandsontableData2ExcelFile");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (Values.isBlankString(fileName)) {
|
|
90
|
+
fileName = t('ui.export.excel.file') + "-" + new Date().getTime();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let exportGridColumns = [];
|
|
94
|
+
let exportGridData = handsontableInstance.hotInstance.getSourceData();
|
|
95
|
+
|
|
96
|
+
window.handsontableInstance = handsontableInstance;
|
|
97
|
+
|
|
98
|
+
if (handsontableInstance.columnSettings && handsontableInstance.columnSettings.length) {
|
|
99
|
+
handsontableInstance.columnSettings.forEach(column => {
|
|
100
|
+
exportGridColumns.push({
|
|
101
|
+
...column,
|
|
102
|
+
dataIndex: column.data
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log('exportGridColumns :', exportGridColumns)
|
|
108
|
+
console.log('exportGridData :', exportGridData)
|
|
109
|
+
|
|
110
|
+
this.exportTableData2ExcelFile(exportGridColumns, exportGridData, fileName);
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
exportTableData2ExcelFile(columns = [], data = [], fileName) {
|
|
114
|
+
|
|
115
|
+
if (Values.isBlankString(fileName)) {
|
|
116
|
+
fileName = `${t('ui.export.excel.file')}-` + new Date().getTime();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const workbook = new ExcelJS.Workbook();
|
|
120
|
+
const worksheet = workbook.addWorksheet('sheet');
|
|
121
|
+
|
|
122
|
+
let exportGridColumnsData = this.gatherExcelColumnHeaderStructureInfo(this.extractColumns(columns));
|
|
123
|
+
let totalColumnHeaderRowCount = exportGridColumnsData.totalColumnHeaderRowCount;
|
|
124
|
+
let columnHeaderData = exportGridColumnsData.columnHeaderData;
|
|
125
|
+
let rowHeaderArray = exportGridColumnsData.rowHeaderArray;
|
|
126
|
+
let columnHeaderMergeCellArray = exportGridColumnsData.columnHeaderMergeCellArray;
|
|
127
|
+
|
|
128
|
+
let exportGridData = data;
|
|
129
|
+
|
|
130
|
+
worksheet.columns = columnHeaderData;
|
|
131
|
+
worksheet.spliceRows(1, 1);
|
|
132
|
+
worksheet.insertRows(1, rowHeaderArray);
|
|
133
|
+
|
|
134
|
+
exportGridData.forEach(gridItem => {
|
|
135
|
+
worksheet.addRow(gridItem);
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
columnHeaderMergeCellArray.forEach(mergeCells => {
|
|
139
|
+
worksheet.mergeCells(mergeCells)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
// 设置表头样式
|
|
143
|
+
const headerRows = worksheet.getRows(1, totalColumnHeaderRowCount);
|
|
144
|
+
headerRows.forEach((row, rowIndex) => {
|
|
145
|
+
row.eachCell((cell, cellIndex) => {
|
|
146
|
+
cell.style = excelHeaderRowStyle;
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
// 设置表体样式
|
|
151
|
+
const bodyRows = worksheet.getRows(totalColumnHeaderRowCount + 1, totalColumnHeaderRowCount + exportGridData.length + 5);
|
|
152
|
+
bodyRows.forEach((row) => {
|
|
153
|
+
row.eachCell((cell, cellIndex) => {
|
|
154
|
+
cell.style = excelBodyRowStyle;
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
workbook.xlsx.writeBuffer().then(buffer => {
|
|
159
|
+
saveAs(new Blob([buffer], {
|
|
160
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
161
|
+
}), fileName + ".xlsx")
|
|
162
|
+
})
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
extractColumns(children, level) {
|
|
166
|
+
let _this = this;
|
|
167
|
+
if (level === void 0) {
|
|
168
|
+
level = 0;
|
|
169
|
+
}
|
|
170
|
+
return Array.isArray(children)
|
|
171
|
+
? children.map(function (child) {
|
|
172
|
+
return _this.extractChild(child, level);
|
|
173
|
+
})
|
|
174
|
+
: [children, _this.extractChild(children, level)];
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
extractChild(child, level) {
|
|
178
|
+
let _this = this;
|
|
179
|
+
if (level === void 0) {
|
|
180
|
+
level = 0;
|
|
181
|
+
}
|
|
182
|
+
return Object.assign(Object.assign({}, child), {
|
|
183
|
+
level: level,
|
|
184
|
+
children: child.children && _this.extractColumns(child.children, level + 1)
|
|
185
|
+
})
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 收集Excel列头信息(复合表头)
|
|
190
|
+
* @param gridColumns
|
|
191
|
+
* @returns {{totalColumnCount: {int}, totalColumnHeaderRowCount: {int}, columnHeaderArray: [] }}
|
|
192
|
+
*/
|
|
193
|
+
gatherExcelColumnHeaderStructureInfo(gridColumns) {
|
|
194
|
+
let [totalColumnCount, totalColumnHeaderRowCount] = this.getTotalColumnCountAndTotalColumnHeaderRowCount(gridColumns, 0, 1);
|
|
195
|
+
|
|
196
|
+
let columnHeaderArray = [];
|
|
197
|
+
for (let i = 0, count = gridColumns.length; i < count; i++) {
|
|
198
|
+
let column = gridColumns[i];
|
|
199
|
+
this.$buildColumnHeaderArray(column, columnHeaderArray);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
for (let i = 0, count = columnHeaderArray.length; i < count; i++) {
|
|
203
|
+
let subArray = columnHeaderArray[i];
|
|
204
|
+
let lastElem = subArray[subArray.length - 1];
|
|
205
|
+
for (let r = subArray.length; r < totalColumnHeaderRowCount; r++) {
|
|
206
|
+
subArray.push(lastElem);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
let columnHeaderMergeCellArray = [];
|
|
211
|
+
let nextColIndex = 1;
|
|
212
|
+
for (let i = 0, count = gridColumns.length; i < count; i++) {
|
|
213
|
+
let gridColumn = gridColumns[i];
|
|
214
|
+
nextColIndex = this.gatherExcelColumnHeaderMergeCellInfo(gridColumn, columnHeaderMergeCellArray, totalColumnHeaderRowCount, 1, nextColIndex);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let rowHeaderArray = [];
|
|
218
|
+
for (let totalColumnHeaderRowStep = 0; totalColumnHeaderRowStep < totalColumnHeaderRowCount; totalColumnHeaderRowStep++) {
|
|
219
|
+
let rowHeaderColumns = [];
|
|
220
|
+
columnHeaderArray.forEach(columns => {
|
|
221
|
+
rowHeaderColumns.push(columns[totalColumnHeaderRowStep])
|
|
222
|
+
})
|
|
223
|
+
rowHeaderArray.push(rowHeaderColumns);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let columnHeaderData = [];
|
|
227
|
+
let columnIndex = 0;
|
|
228
|
+
|
|
229
|
+
let addColumns = (columns, result) => {
|
|
230
|
+
columns.forEach((column) => {
|
|
231
|
+
let exporterColumn = this.$normalizedExportColumn(column);
|
|
232
|
+
result.push(exporterColumn);
|
|
233
|
+
if (column.children && column.children.length > 1) {
|
|
234
|
+
let children = exporterColumn.columns = [];
|
|
235
|
+
addColumns(column.children, children);
|
|
236
|
+
} else {
|
|
237
|
+
columnIndex++;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
addColumns(gridColumns, columnHeaderData);
|
|
242
|
+
const autoCreateArrayItems = function (column, columnStep, columns) {
|
|
243
|
+
if (column.columns && column.columns.length) {
|
|
244
|
+
columns.splice(columnStep, 1, ...column.columns);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (columnStep === columns.length - 1) {
|
|
248
|
+
console.log('success');
|
|
249
|
+
} else {
|
|
250
|
+
columnStep++;
|
|
251
|
+
autoCreateArrayItems(columns[columnStep], columnStep, columns);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
autoCreateArrayItems(columnHeaderData[0], 0, columnHeaderData);
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
totalColumnCount,
|
|
259
|
+
totalColumnHeaderRowCount,
|
|
260
|
+
columnHeaderArray,
|
|
261
|
+
columnHeaderData,
|
|
262
|
+
rowHeaderArray,
|
|
263
|
+
columnHeaderMergeCellArray
|
|
264
|
+
};
|
|
265
|
+
},
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* @return {Array} eg -
|
|
269
|
+
* [
|
|
270
|
+
* [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
|
|
271
|
+
* [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
|
|
272
|
+
* [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
|
|
273
|
+
* [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
|
|
274
|
+
* ]
|
|
275
|
+
*/
|
|
276
|
+
gatherExcelColumnHeaderMergeCellInfo(gridColumn, columnHeaderMergeCellArray, totalColumnHeaderRowCount, currentColumnHeaderRowIndex = 1, colIndex) {
|
|
277
|
+
|
|
278
|
+
let allChildColumnCount = this.$countAllChildColumnCount(gridColumn);
|
|
279
|
+
|
|
280
|
+
if (Array.isArray(gridColumn.children) && gridColumn.children.length) {
|
|
281
|
+
let gridColumns = gridColumn.children;
|
|
282
|
+
let gridColumnCount = gridColumns.length;
|
|
283
|
+
|
|
284
|
+
columnHeaderMergeCellArray.push([currentColumnHeaderRowIndex, colIndex, currentColumnHeaderRowIndex, colIndex + allChildColumnCount - 1]);
|
|
285
|
+
|
|
286
|
+
for (let i = 0; i < gridColumnCount; i++) {
|
|
287
|
+
this.gatherExcelColumnHeaderMergeCellInfo(gridColumns[i], columnHeaderMergeCellArray, totalColumnHeaderRowCount,
|
|
288
|
+
currentColumnHeaderRowIndex + 1, colIndex + i);
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
if (currentColumnHeaderRowIndex !== totalColumnHeaderRowCount) {
|
|
292
|
+
columnHeaderMergeCellArray.push([currentColumnHeaderRowIndex, colIndex, totalColumnHeaderRowCount, colIndex]);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return colIndex + allChildColumnCount;
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
$countAllChildColumnCount(gridColumn) {
|
|
300
|
+
let columnCount = 0;
|
|
301
|
+
if (gridColumn === null || gridColumn === void 0) {
|
|
302
|
+
return columnCount;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (Array.isArray(gridColumn.children) && gridColumn.children.length) {
|
|
306
|
+
let gridColumns = gridColumn.children;
|
|
307
|
+
let gridColumnCount = gridColumns.length;
|
|
308
|
+
|
|
309
|
+
for (let i = 0; i < gridColumnCount; i++) {
|
|
310
|
+
let childColumnCount = this.$countAllChildColumnCount(gridColumns[i]);
|
|
311
|
+
columnCount = columnCount + childColumnCount;
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
columnCount = 1;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return columnCount;
|
|
318
|
+
},
|
|
319
|
+
|
|
320
|
+
getTotalColumnCountAndTotalColumnHeaderRowCount(gridColumns, totalColumnCount, totalColumnHeaderCount) {
|
|
321
|
+
let maxN2 = totalColumnHeaderCount;
|
|
322
|
+
for (let i = 0, count = gridColumns.length; i < count; i++) {
|
|
323
|
+
let column = gridColumns[i];
|
|
324
|
+
if (Array.isArray(column.children) && column.children.length) {
|
|
325
|
+
let [n1, n2] = this.getTotalColumnCountAndTotalColumnHeaderRowCount(column.children, 0, totalColumnHeaderCount + 1);
|
|
326
|
+
totalColumnCount = totalColumnCount + n1;
|
|
327
|
+
if (n2 > maxN2) {
|
|
328
|
+
maxN2 = n2;
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
totalColumnCount = totalColumnCount + 1;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return [totalColumnCount, maxN2]
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
$buildColumnHeaderArray(column, columnHeaderArray, parentHeaderTitles) {
|
|
339
|
+
if (Array.isArray(column.children) && column.children.length) {
|
|
340
|
+
if (parentHeaderTitles === null || parentHeaderTitles == void 0) {
|
|
341
|
+
parentHeaderTitles = [column.title];
|
|
342
|
+
} else {
|
|
343
|
+
parentHeaderTitles.push(column.title);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
for (let i = 0, count = column.children.length; i < count; i++) {
|
|
347
|
+
let childColumn = column.children[i];
|
|
348
|
+
this.$buildColumnHeaderArray(childColumn, columnHeaderArray, parentHeaderTitles);
|
|
349
|
+
}
|
|
350
|
+
} else {
|
|
351
|
+
let columnSelfHeaderTitleArray = [];
|
|
352
|
+
if (Array.isArray(parentHeaderTitles)) {
|
|
353
|
+
columnSelfHeaderTitleArray.push(...parentHeaderTitles);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
columnSelfHeaderTitleArray.push(column.title);
|
|
357
|
+
|
|
358
|
+
columnHeaderArray.push(columnSelfHeaderTitleArray)
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
$normalizedExportColumn(column) {
|
|
364
|
+
return {
|
|
365
|
+
header : column.title,
|
|
366
|
+
key : column.dataIndex,
|
|
367
|
+
locked : column.locked,
|
|
368
|
+
width : column.width != null ? column.width * 0.1 : undefined
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export default ExcelKits;
|