@fecp/designer 5.5.105 → 5.5.108

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 (35) hide show
  1. package/es/_virtual/exceljs.min.mjs +7 -0
  2. package/es/_virtual/exceljs.min2.mjs +4 -0
  3. package/es/designer/package.json.mjs +1 -1
  4. package/es/designer/src/packages/dialog/useDialogDialog.mjs +1 -1
  5. package/es/designer/src/packages/dialogGlobal/useDialogGlobalDialog.mjs +1 -1
  6. package/es/designer/src/packages/form/property/widgets.vue.mjs +2 -2
  7. package/es/designer.css +126 -95
  8. package/es/node_modules/@vxe-ui/plugin-export-xlsx/es/index.esm.mjs +809 -0
  9. package/es/node_modules/exceljs/dist/exceljs.min.mjs +23129 -0
  10. package/es/packages/mobile/node_modules/vant/es/tag/Tag.mjs +80 -0
  11. package/es/packages/mobile/node_modules/vant/es/tag/index.mjs +8 -0
  12. package/es/packages/mobile/src/components/custom/approvalList/ApprovalCard.vue.mjs +139 -0
  13. package/es/packages/mobile/src/components/custom/approvalList/ApprovalList.vue.mjs +116 -300
  14. package/es/packages/vue/index.mjs +6 -1
  15. package/es/packages/vue/src/components/layout/Layout.vue.mjs +8 -3
  16. package/es/packages/vue/src/components/table/Table.vue.mjs +125 -4
  17. package/es/packages/vue/src/components/table/TableColumn.vue.mjs +6 -115
  18. package/lib/_virtual/exceljs.min.js +7 -0
  19. package/lib/_virtual/exceljs.min2.js +4 -0
  20. package/lib/designer/package.json.js +1 -1
  21. package/lib/designer/src/packages/dialog/useDialogDialog.js +1 -1
  22. package/lib/designer/src/packages/dialogGlobal/useDialogGlobalDialog.js +1 -1
  23. package/lib/designer/src/packages/form/property/widgets.vue.js +2 -2
  24. package/lib/designer.css +126 -95
  25. package/lib/node_modules/@vxe-ui/plugin-export-xlsx/es/index.esm.js +809 -0
  26. package/lib/node_modules/exceljs/dist/exceljs.min.js +23129 -0
  27. package/lib/packages/mobile/node_modules/vant/es/tag/Tag.js +80 -0
  28. package/lib/packages/mobile/node_modules/vant/es/tag/index.js +7 -0
  29. package/lib/packages/mobile/src/components/custom/approvalList/ApprovalCard.vue.js +139 -0
  30. package/lib/packages/mobile/src/components/custom/approvalList/ApprovalList.vue.js +119 -303
  31. package/lib/packages/vue/index.js +5 -0
  32. package/lib/packages/vue/src/components/layout/Layout.vue.js +8 -3
  33. package/lib/packages/vue/src/components/table/Table.vue.js +125 -4
  34. package/lib/packages/vue/src/components/table/TableColumn.vue.js +6 -115
  35. package/package.json +1 -1
@@ -0,0 +1,809 @@
1
+ import XEUtils from "xe-utils";
2
+ let VxeUI;
3
+ let globalExcelJS;
4
+ const defaultHeaderBackgroundColor = "f2f2f2";
5
+ const defaultCellFontColor = "000000";
6
+ const defaultCellBorderStyle = "thin";
7
+ const defaultCellBorderColor = "e0e0e0";
8
+ const defaultFontSizeMaps = {
9
+ default: 14,
10
+ medium: 14,
11
+ small: 13,
12
+ mini: 12
13
+ };
14
+ const httpPromiseMaps = {};
15
+ const httpBufferMaps = {};
16
+ function getExcelJS() {
17
+ const ExcelJS = globalExcelJS || window.ExcelJS;
18
+ if (!ExcelJS) {
19
+ console.error("[@vxe-ui/plugin-export-xlsx 4.5.2] Install error. ExcelJS not exist.");
20
+ }
21
+ return ExcelJS;
22
+ }
23
+ function getCellLabel($xeTable, column, cellValue) {
24
+ const { cellType, cellRender, editRender } = column;
25
+ const renderOpts = editRender || cellRender;
26
+ if (cellValue) {
27
+ if (renderOpts) {
28
+ if (["VxeImage", "VxeImageGroup", "VxeUpload"].includes(renderOpts.name || "")) {
29
+ return "";
30
+ }
31
+ }
32
+ if (column.type === "seq") {
33
+ const tableProps = $xeTable.props;
34
+ const { treeConfig } = tableProps;
35
+ if (!treeConfig) {
36
+ if (!isNaN(cellValue)) {
37
+ return Number(cellValue);
38
+ }
39
+ }
40
+ return XEUtils.toValueString(cellValue);
41
+ }
42
+ switch (cellType) {
43
+ case "string":
44
+ return XEUtils.toValueString(cellValue);
45
+ case "number":
46
+ if (!isNaN(cellValue)) {
47
+ return Number(cellValue);
48
+ }
49
+ break;
50
+ }
51
+ if (cellValue.length < 12 && !isNaN(cellValue)) {
52
+ return Number(cellValue);
53
+ }
54
+ }
55
+ return XEUtils.toValueString(cellValue);
56
+ }
57
+ function getFooterData($xeTable, opts, footerData) {
58
+ const $xeGrid = $xeTable.xeGrid;
59
+ const $xeGantt = $xeTable.xeGantt;
60
+ const { footerFilterMethod } = opts;
61
+ return footerFilterMethod ? footerData.filter((items, index) => footerFilterMethod({ $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt, items, $rowIndex: index })) : footerData;
62
+ }
63
+ function getFooterCellValue($xeTable, opts, row, column) {
64
+ const { renderer } = VxeUI;
65
+ const { computeColumnOpts } = $xeTable.getComputeMaps();
66
+ const columnOpts = computeColumnOpts.value;
67
+ const renderOpts = column.editRender || column.cellRender;
68
+ let footLabelMethod = column.footerExportMethod;
69
+ if (!footLabelMethod && renderOpts && renderOpts.name) {
70
+ const compConf = renderer.get(renderOpts.name);
71
+ if (compConf) {
72
+ footLabelMethod = compConf.tableFooterExportMethod || compConf.footerExportMethod;
73
+ }
74
+ }
75
+ if (!footLabelMethod) {
76
+ footLabelMethod = columnOpts.footerExportMethod;
77
+ }
78
+ if (footLabelMethod) {
79
+ const _columnIndex = $xeTable.getVTColumnIndex(column);
80
+ return footLabelMethod({ $table: $xeTable, items: row, itemIndex: _columnIndex, row, _columnIndex, column, options: opts });
81
+ }
82
+ if ($xeTable.getFooterCellLabel) {
83
+ return getCellLabel($xeTable, column, $xeTable.getFooterCellLabel(row, column));
84
+ }
85
+ if (XEUtils.isArray(row)) {
86
+ const _columnIndex = $xeTable.getVTColumnIndex(column);
87
+ return getCellLabel($xeTable, column, row[_columnIndex]);
88
+ }
89
+ return getCellLabel($xeTable, column, XEUtils.get(row, column.field));
90
+ }
91
+ function getValidColumn(column) {
92
+ const { childNodes } = column;
93
+ const isColGroup = childNodes && childNodes.length;
94
+ if (isColGroup) {
95
+ return getValidColumn(childNodes[0]);
96
+ }
97
+ return column;
98
+ }
99
+ function setExcelRowHeight(excelRow, height) {
100
+ if (height) {
101
+ excelRow.height = XEUtils.floor(height * 0.92, 2);
102
+ }
103
+ }
104
+ function setExcelCellStyle(excelCell, align) {
105
+ excelCell.protection = {
106
+ locked: false
107
+ };
108
+ excelCell.alignment = {
109
+ vertical: "middle",
110
+ horizontal: align || "left"
111
+ };
112
+ }
113
+ function getImgType(name) {
114
+ const index = name.lastIndexOf(".");
115
+ let ext = "";
116
+ if (index > 0) {
117
+ ext = name.substring(index + 1).toLowerCase();
118
+ }
119
+ return ext || "png";
120
+ }
121
+ function getExcelCellCurrencySymbol(currencySymbol) {
122
+ if (currencySymbol === "$") {
123
+ return "$";
124
+ }
125
+ if (currencySymbol === "¥" || currencySymbol === "¥") {
126
+ return "¥";
127
+ }
128
+ return currencySymbol;
129
+ }
130
+ function getExcelCellNumberValSymbol(digits) {
131
+ return `0.${XEUtils.padEnd("0", digits, "0")}`;
132
+ }
133
+ function getExcelCellNumberColorSymbol(showNegativeStatus) {
134
+ if (showNegativeStatus) {
135
+ return "[Red]";
136
+ }
137
+ return "";
138
+ }
139
+ function settExcelCellFormat(workbook, worksheet, excelCell, column, excelRow, row) {
140
+ const { getConfig, getI18n } = VxeUI;
141
+ const { cellType, cellRender, editRender } = column;
142
+ if (cellType !== "string") {
143
+ const renderOpts = editRender || cellRender;
144
+ if (renderOpts) {
145
+ const { name, props = {}, showNegativeStatus } = renderOpts;
146
+ if (name === "VxeNumberInput" || name === "FormatNumberInput") {
147
+ const { type, digits } = props;
148
+ const numberInputConfig = getConfig().numberInput || {};
149
+ if (type === "amount") {
150
+ const numDigits = digits || numberInputConfig.digits || 2;
151
+ const numSymbol = getExcelCellNumberValSymbol(numDigits);
152
+ excelCell.numFmt = `##${numSymbol};${getExcelCellNumberColorSymbol(showNegativeStatus)}\\-##${numSymbol}`;
153
+ const showCurrency = props.showCurrency;
154
+ if (XEUtils.isBoolean(showCurrency) ? showCurrency : numberInputConfig.showCurrency) {
155
+ const currencySymbol = getExcelCellCurrencySymbol(props.currencySymbol || numberInputConfig.currencySymbol || getI18n("vxe.numberInput.currencySymbol") || "");
156
+ excelCell.numFmt = `"${currencySymbol}"#,##${numSymbol};${getExcelCellNumberColorSymbol(showNegativeStatus)}-"${currencySymbol}"#,##${numSymbol}`;
157
+ }
158
+ } else {
159
+ const numDigits = digits || (type === "float" ? numberInputConfig.digits : 2) || 1;
160
+ const numSymbol = getExcelCellNumberValSymbol(numDigits);
161
+ excelCell.numFmt = `##${numSymbol};${getExcelCellNumberColorSymbol(showNegativeStatus)}\\-##${numSymbol}`;
162
+ }
163
+ } else if (renderOpts.name === "VxeImage" || renderOpts.name === "VxeImageGroup") {
164
+ const { width, height } = (renderOpts.name === "VxeImage" ? props : props.imageStyle) || {};
165
+ const cellValue = XEUtils.get(row, column.field);
166
+ if (cellValue) {
167
+ (XEUtils.isArray(cellValue) ? cellValue.slice(0, 1) : [cellValue]).forEach((item) => {
168
+ if (item) {
169
+ const imgUrl = XEUtils.isString(item) ? item : item.url;
170
+ if (imgUrl) {
171
+ const imgBuffer = httpBufferMaps[imgUrl];
172
+ if (imgBuffer) {
173
+ const cellImage = workbook.addImage({
174
+ buffer: imgBuffer,
175
+ extension: getImgType(imgUrl)
176
+ });
177
+ worksheet.addImage(cellImage, {
178
+ tl: {
179
+ col: Math.max(0, XEUtils.toNumber(excelCell.col) - 1),
180
+ row: Math.max(0, XEUtils.toNumber(excelCell.row) - 1)
181
+ },
182
+ ext: {
183
+ width: XEUtils.toNumber(width || height) || 24,
184
+ height: XEUtils.toNumber(height || width) || 24
185
+ }
186
+ });
187
+ }
188
+ }
189
+ }
190
+ });
191
+ }
192
+ } else if (renderOpts.name === "VxeUpload" && props.mode === "image") {
193
+ const { urlField, typeField, imageConfig } = props;
194
+ const { width, height } = imageConfig || {};
195
+ const cellValue = XEUtils.get(row, column.field);
196
+ if (cellValue) {
197
+ (XEUtils.isArray(cellValue) ? cellValue.slice(0, 1) : [cellValue]).forEach((item) => {
198
+ if (item) {
199
+ const imgUrl = XEUtils.isString(item) ? item : item[urlField || "url"];
200
+ if (imgUrl) {
201
+ const imgBuffer = httpBufferMaps[imgUrl];
202
+ if (imgBuffer) {
203
+ const cellImage = workbook.addImage({
204
+ buffer: imgBuffer,
205
+ extension: (XEUtils.isString(item) ? "" : item[typeField]) || getImgType(imgUrl)
206
+ });
207
+ worksheet.addImage(cellImage, {
208
+ tl: {
209
+ col: Math.max(0, XEUtils.toNumber(excelCell.col) - 1),
210
+ row: Math.max(0, XEUtils.toNumber(excelCell.row) - 1)
211
+ },
212
+ ext: {
213
+ width: XEUtils.toNumber(width || height) || 24,
214
+ height: XEUtils.toNumber(height || width) || 24
215
+ }
216
+ });
217
+ }
218
+ }
219
+ }
220
+ });
221
+ }
222
+ }
223
+ }
224
+ }
225
+ }
226
+ function getDefaultBorderStyle() {
227
+ return {
228
+ top: {
229
+ style: defaultCellBorderStyle,
230
+ color: {
231
+ argb: defaultCellBorderColor
232
+ }
233
+ },
234
+ left: {
235
+ style: defaultCellBorderStyle,
236
+ color: {
237
+ argb: defaultCellBorderColor
238
+ }
239
+ },
240
+ bottom: {
241
+ style: defaultCellBorderStyle,
242
+ color: {
243
+ argb: defaultCellBorderColor
244
+ }
245
+ },
246
+ right: {
247
+ style: defaultCellBorderStyle,
248
+ color: {
249
+ argb: defaultCellBorderColor
250
+ }
251
+ }
252
+ };
253
+ }
254
+ function handleParseColumnImageUrl(params) {
255
+ const { columns, datas } = params;
256
+ const urlList = [];
257
+ columns.forEach((column) => {
258
+ const { cellRender, editRender } = column;
259
+ const renderOpts = editRender || cellRender || {};
260
+ const { name, props = {} } = renderOpts;
261
+ if (name === "VxeImage" || name === "VxeImageGroup") {
262
+ datas.forEach((rowRest) => {
263
+ const row = rowRest._row;
264
+ const cellValue = XEUtils.get(row, column.field);
265
+ if (cellValue) {
266
+ (XEUtils.isArray(cellValue) ? cellValue : [cellValue]).forEach((item) => {
267
+ if (item) {
268
+ const imgUrl = item.url ? item.url : `${item || ""}`;
269
+ if (imgUrl) {
270
+ urlList.push(imgUrl);
271
+ }
272
+ }
273
+ });
274
+ }
275
+ });
276
+ } else if (name === "VxeUpload" && props.mode === "image") {
277
+ const { urlField } = props;
278
+ datas.forEach((rowRest) => {
279
+ const row = rowRest._row;
280
+ const cellValue = XEUtils.get(row, column.field);
281
+ if (cellValue) {
282
+ (XEUtils.isArray(cellValue) ? cellValue : [cellValue]).forEach((item) => {
283
+ if (item) {
284
+ const imgUrl = XEUtils.isString(item) ? item : item[urlField || "url"];
285
+ if (imgUrl) {
286
+ urlList.push(imgUrl);
287
+ }
288
+ }
289
+ });
290
+ }
291
+ });
292
+ }
293
+ });
294
+ if (urlList.length) {
295
+ return handleFetchImage(urlList);
296
+ }
297
+ }
298
+ function handleFetchImage(urlList) {
299
+ let fIndex = 0;
300
+ const handleStartFetch = () => {
301
+ if (fIndex < urlList.length) {
302
+ const restList = [];
303
+ let count = 1;
304
+ for (; fIndex < urlList.length; fIndex++) {
305
+ const url = urlList[fIndex];
306
+ if (!httpBufferMaps[url]) {
307
+ if (!httpPromiseMaps[url]) {
308
+ count++;
309
+ httpPromiseMaps[url] = fetch(url).then((res) => res.arrayBuffer()).then((arrayBuffer) => {
310
+ httpBufferMaps[url] = arrayBuffer;
311
+ delete httpPromiseMaps[url];
312
+ }).catch(() => {
313
+ delete httpPromiseMaps[url];
314
+ });
315
+ }
316
+ restList.push(httpPromiseMaps[url]);
317
+ }
318
+ if (count >= 4) {
319
+ break;
320
+ }
321
+ }
322
+ return Promise.all(restList).then(() => {
323
+ if (fIndex < urlList.length) {
324
+ return handleStartFetch();
325
+ }
326
+ });
327
+ }
328
+ return Promise.resolve();
329
+ };
330
+ return handleStartFetch();
331
+ }
332
+ function exportXLSX(params) {
333
+ const msgKey = XEUtils.uniqueId("xlsx");
334
+ const { modal, getI18n } = VxeUI;
335
+ const { $table, $grid, options, columns, colgroups, datas } = params;
336
+ const tableProps = $table.props;
337
+ const tableReactData = $table.reactData;
338
+ const { computeSize, computeColumnOpts } = $table.getComputeMaps();
339
+ const { headerAlign: allHeaderAlign, align: allAlign, footerAlign: allFooterAlign } = tableProps;
340
+ const { rowHeight } = tableReactData;
341
+ const { message, download, sheetName, isHeader, isFooter, isMerge, isColgroup, isTitle, useStyle, sheetMethod } = options;
342
+ const vSize = computeSize.value;
343
+ const columnOpts = computeColumnOpts.value;
344
+ const showMsg = message !== false;
345
+ const mergeCells = $table.getMergeCells();
346
+ const fontSize = defaultFontSizeMaps[vSize || ""] || 14;
347
+ const colList = [];
348
+ let footList = [];
349
+ const footArr = [];
350
+ const sheetCols = [];
351
+ const sheetMerges = [];
352
+ let beforeRowCount = 0;
353
+ columns.forEach((column) => {
354
+ const { id, renderWidth } = column;
355
+ sheetCols.push({
356
+ key: id,
357
+ width: XEUtils.ceil(renderWidth / 7.2, 1)
358
+ });
359
+ });
360
+ if (isHeader) {
361
+ if (isColgroup && colgroups) {
362
+ colgroups.forEach((cols, rIndex) => {
363
+ const groupHead = {};
364
+ columns.forEach((column) => {
365
+ groupHead[column.id] = null;
366
+ });
367
+ cols.forEach((column) => {
368
+ const { _colSpan, _rowSpan } = column;
369
+ const validColumn = getValidColumn(column);
370
+ const columnIndex = columns.indexOf(validColumn);
371
+ const headExportMethod = column.headerExportMethod || columnOpts.headerExportMethod;
372
+ groupHead[validColumn.id] = headExportMethod ? headExportMethod({ column, options, $table }) : isTitle ? column.getTitle() : validColumn.field;
373
+ if (_colSpan > 1 || _rowSpan > 1) {
374
+ sheetMerges.push({
375
+ s: { r: rIndex, c: columnIndex },
376
+ e: { r: rIndex + _rowSpan - 1, c: columnIndex + _colSpan - 1 }
377
+ });
378
+ }
379
+ });
380
+ colList.push(groupHead);
381
+ });
382
+ } else {
383
+ const colHead = {};
384
+ columns.forEach((column) => {
385
+ const { id, field } = column;
386
+ const headExportMethod = column.headerExportMethod || columnOpts.headerExportMethod;
387
+ colHead[id] = headExportMethod ? headExportMethod({ column, options, $table }) : isTitle ? column.getTitle() : field;
388
+ });
389
+ colList.push(colHead);
390
+ }
391
+ beforeRowCount += colList.length;
392
+ }
393
+ if (isMerge) {
394
+ mergeCells.forEach((mergeItem) => {
395
+ const { row: mergeRowIndex, rowspan: mergeRowspan, col: mergeColIndex, colspan: mergeColspan } = mergeItem;
396
+ sheetMerges.push({
397
+ s: { r: mergeRowIndex + beforeRowCount, c: mergeColIndex },
398
+ e: { r: mergeRowIndex + beforeRowCount + mergeRowspan - 1, c: mergeColIndex + mergeColspan - 1 }
399
+ });
400
+ });
401
+ }
402
+ const rowList = datas;
403
+ const rowArr = rowList.map((item) => {
404
+ const rest = {};
405
+ columns.forEach((column) => {
406
+ rest[column.id] = getCellLabel($table, column, item[column.id]);
407
+ });
408
+ return rest;
409
+ });
410
+ beforeRowCount += rowList.length;
411
+ if (isFooter) {
412
+ const { footerData } = $table.getTableData();
413
+ footList = getFooterData($table, options, footerData);
414
+ const mergeFooterItems = $table.getMergeFooterItems();
415
+ if (isMerge) {
416
+ mergeFooterItems.forEach((mergeItem) => {
417
+ const { row: mergeRowIndex, rowspan: mergeRowspan, col: mergeColIndex, colspan: mergeColspan } = mergeItem;
418
+ sheetMerges.push({
419
+ s: { r: mergeRowIndex + beforeRowCount, c: mergeColIndex },
420
+ e: { r: mergeRowIndex + beforeRowCount + mergeRowspan - 1, c: mergeColIndex + mergeColspan - 1 }
421
+ });
422
+ });
423
+ }
424
+ footList.forEach((row) => {
425
+ const item = {};
426
+ columns.forEach((column) => {
427
+ item[column.id] = getFooterCellValue($table, options, row, column);
428
+ });
429
+ footArr.push(item);
430
+ });
431
+ }
432
+ const exportMethod = () => {
433
+ const ExcelObj = getExcelJS();
434
+ if (!ExcelObj) {
435
+ if (modal) {
436
+ modal.close(msgKey);
437
+ }
438
+ return Promise.resolve({
439
+ status: false
440
+ });
441
+ }
442
+ const workbook = new ExcelObj.Workbook();
443
+ const sheet = workbook.addWorksheet(sheetName || "Sheet1");
444
+ workbook.creator = "vxe-table";
445
+ sheet.columns = sheetCols;
446
+ if (isHeader) {
447
+ sheet.addRows(colList).forEach((excelRow) => {
448
+ if (useStyle) {
449
+ setExcelRowHeight(excelRow, rowHeight);
450
+ }
451
+ excelRow.eachCell((excelCell) => {
452
+ const excelCol = sheet.getColumn(excelCell.col);
453
+ const column = $table.getColumnById(excelCol.key);
454
+ const { headerAlign, align } = column;
455
+ setExcelCellStyle(excelCell, headerAlign || align || allHeaderAlign || allAlign);
456
+ if (useStyle) {
457
+ Object.assign(excelCell, {
458
+ font: {
459
+ bold: true,
460
+ size: fontSize,
461
+ color: {
462
+ argb: defaultCellFontColor
463
+ }
464
+ },
465
+ fill: {
466
+ type: "pattern",
467
+ pattern: "solid",
468
+ fgColor: {
469
+ argb: defaultHeaderBackgroundColor
470
+ }
471
+ },
472
+ border: getDefaultBorderStyle()
473
+ });
474
+ }
475
+ });
476
+ });
477
+ }
478
+ sheet.addRows(rowArr).forEach((excelRow, rIndex) => {
479
+ const row = rowList[rIndex]._row;
480
+ if (useStyle) {
481
+ setExcelRowHeight(excelRow, rowHeight);
482
+ }
483
+ excelRow.eachCell((excelCell) => {
484
+ const excelCol = sheet.getColumn(excelCell.col);
485
+ const column = $table.getColumnById(excelCol.key);
486
+ if (column) {
487
+ const { align } = column;
488
+ setExcelCellStyle(excelCell, align || allAlign);
489
+ settExcelCellFormat(workbook, sheet, excelCell, column, excelRow, row);
490
+ if (useStyle) {
491
+ Object.assign(excelCell, {
492
+ font: {
493
+ size: fontSize,
494
+ color: {
495
+ argb: defaultCellFontColor
496
+ }
497
+ },
498
+ border: getDefaultBorderStyle()
499
+ });
500
+ }
501
+ }
502
+ });
503
+ });
504
+ if (isFooter) {
505
+ sheet.addRows(footArr).forEach((excelRow, rIndex) => {
506
+ const row = footList[rIndex];
507
+ if (useStyle) {
508
+ setExcelRowHeight(excelRow, rowHeight);
509
+ }
510
+ excelRow.eachCell((excelCell) => {
511
+ const excelCol = sheet.getColumn(excelCell.col);
512
+ const column = $table.getColumnById(excelCol.key);
513
+ if (column) {
514
+ const { footerAlign, align } = column;
515
+ setExcelCellStyle(excelCell, footerAlign || align || allFooterAlign || allAlign);
516
+ settExcelCellFormat(workbook, sheet, excelCell, column, excelRow, row);
517
+ if (useStyle) {
518
+ Object.assign(excelCell, {
519
+ font: {
520
+ size: fontSize,
521
+ color: {
522
+ argb: defaultCellFontColor
523
+ }
524
+ },
525
+ border: getDefaultBorderStyle()
526
+ });
527
+ }
528
+ }
529
+ });
530
+ });
531
+ }
532
+ return Promise.resolve(
533
+ // 自定义处理
534
+ sheetMethod ? sheetMethod({
535
+ options,
536
+ workbook,
537
+ worksheet: sheet,
538
+ columns,
539
+ colgroups,
540
+ datas,
541
+ $grid,
542
+ $table
543
+ }) : null
544
+ ).then(() => {
545
+ sheetMerges.forEach(({ s, e }) => {
546
+ sheet.mergeCells(s.r + 1, s.c + 1, e.r + 1, e.c + 1);
547
+ });
548
+ return workbook.xlsx.writeBuffer().then((buffer) => {
549
+ const type = "application/octet-stream";
550
+ const blob = new Blob([buffer], { type });
551
+ if (modal) {
552
+ modal.close(msgKey);
553
+ }
554
+ if (showMsg && modal) {
555
+ modal.message({
556
+ content: getI18n("vxe.table.expSuccess"),
557
+ status: "success"
558
+ });
559
+ }
560
+ if (download) {
561
+ downloadFile(params, blob, options);
562
+ return {
563
+ status: true
564
+ };
565
+ }
566
+ return { type, content: "", blob };
567
+ });
568
+ }).catch(() => {
569
+ if (modal) {
570
+ modal.close(msgKey);
571
+ }
572
+ if (showMsg && modal) {
573
+ modal.message({
574
+ content: getI18n("vxe.table.expError"),
575
+ status: "error"
576
+ });
577
+ }
578
+ return {
579
+ status: false
580
+ };
581
+ });
582
+ };
583
+ return Promise.all([
584
+ handleParseColumnImageUrl(params)
585
+ ]).then(() => {
586
+ if (showMsg && modal) {
587
+ modal.message({
588
+ id: msgKey,
589
+ content: getI18n("vxe.table.expLoading"),
590
+ status: "loading",
591
+ duration: -1
592
+ });
593
+ return new Promise((resolve) => {
594
+ setTimeout(() => {
595
+ resolve(exportMethod());
596
+ }, 1500);
597
+ });
598
+ }
599
+ return exportMethod();
600
+ });
601
+ }
602
+ function downloadFile(params, blob, options) {
603
+ const { modal, t } = VxeUI;
604
+ const { message, filename, type } = options;
605
+ const showMsg = message !== false;
606
+ if (window.Blob) {
607
+ if (navigator.msSaveBlob) {
608
+ navigator.msSaveBlob(blob, `${filename}.${type}`);
609
+ } else {
610
+ const linkElem = document.createElement("a");
611
+ linkElem.target = "_blank";
612
+ linkElem.download = `${filename}.${type}`;
613
+ linkElem.href = URL.createObjectURL(blob);
614
+ document.body.appendChild(linkElem);
615
+ linkElem.click();
616
+ document.body.removeChild(linkElem);
617
+ }
618
+ } else {
619
+ if (showMsg && modal) {
620
+ modal.alert({ content: t("vxe.error.notExp"), status: "error" });
621
+ }
622
+ }
623
+ }
624
+ function importError(params) {
625
+ const { modal, t } = VxeUI;
626
+ const { $table, options } = params;
627
+ const tableInternalData = $table.internalData;
628
+ const { _importReject } = tableInternalData;
629
+ const showMsg = options.message !== false;
630
+ if (showMsg && modal) {
631
+ modal.message({ content: t("vxe.error.impFields"), status: "error" });
632
+ }
633
+ if (_importReject) {
634
+ _importReject({ status: false });
635
+ }
636
+ }
637
+ function importXLSX(params) {
638
+ const { modal, getI18n } = VxeUI;
639
+ const { $table, columns, options, file } = params;
640
+ const tableInternalData = $table.internalData;
641
+ const { _importResolve } = tableInternalData;
642
+ const ExcelObj = getExcelJS();
643
+ if (!ExcelObj) {
644
+ if (_importResolve) {
645
+ _importResolve({
646
+ status: false
647
+ });
648
+ }
649
+ return;
650
+ }
651
+ const showMsg = options.message !== false;
652
+ const fileReader = new FileReader();
653
+ fileReader.onerror = () => {
654
+ importError(params);
655
+ };
656
+ fileReader.onload = (evnt) => {
657
+ const tableFieldMaps = {};
658
+ const tableTitleMaps = {};
659
+ columns.forEach((column) => {
660
+ const field = column.field;
661
+ const title = column.getTitle();
662
+ if (field) {
663
+ tableFieldMaps[field] = column;
664
+ }
665
+ if (title) {
666
+ tableTitleMaps[column.getTitle()] = column;
667
+ }
668
+ });
669
+ const workbook = new ExcelObj.Workbook();
670
+ const readerTarget = evnt.target;
671
+ if (readerTarget) {
672
+ workbook.xlsx.load(readerTarget.result).then((wb) => {
673
+ const firstSheet = wb.worksheets[0];
674
+ if (firstSheet) {
675
+ const sheetValues = Array.from(firstSheet.getSheetValues());
676
+ const fieldIndex = XEUtils.findIndexOf(sheetValues, (list) => list && list.length > 0);
677
+ const heads = sheetValues[fieldIndex];
678
+ let status = false;
679
+ const fields = heads.map((key) => {
680
+ if (tableFieldMaps[key]) {
681
+ if (!status) {
682
+ status = true;
683
+ }
684
+ return key;
685
+ }
686
+ if (tableTitleMaps[key]) {
687
+ if (!status) {
688
+ status = true;
689
+ }
690
+ return tableTitleMaps[key].field;
691
+ }
692
+ return null;
693
+ });
694
+ if (status) {
695
+ const records = sheetValues.slice(fieldIndex + 1).map((list) => {
696
+ const record = {};
697
+ fields.forEach((field, cIndex) => {
698
+ if (field) {
699
+ record[field] = XEUtils.isUndefined(list[cIndex]) ? null : list[cIndex];
700
+ }
701
+ });
702
+ return record;
703
+ });
704
+ $table.createData(records).then((data) => {
705
+ let loadRest;
706
+ if (options.mode === "insertTop") {
707
+ loadRest = $table.insertAt(data, 0);
708
+ } else if (options.mode === "insertBottom" || options.mode === "insert") {
709
+ loadRest = $table.insertAt(data, -1);
710
+ } else {
711
+ const { visibleData } = $table.getTableData();
712
+ loadRest = $table.remove(visibleData).then(() => $table.insertAt(data, -1));
713
+ }
714
+ return loadRest.then(() => {
715
+ if (_importResolve) {
716
+ _importResolve({ status: true });
717
+ }
718
+ });
719
+ });
720
+ if (showMsg && modal) {
721
+ modal.message({ content: getI18n("vxe.table.impSuccess", [records.length]), status: "success" });
722
+ }
723
+ } else {
724
+ importError(params);
725
+ }
726
+ } else {
727
+ importError(params);
728
+ }
729
+ });
730
+ } else {
731
+ importError(params);
732
+ }
733
+ };
734
+ fileReader.readAsArrayBuffer(file);
735
+ }
736
+ function hasAdvancedVersion(tableVersion) {
737
+ const vRest = tableVersion ? `${tableVersion}`.match(/(\d+)\.(\d+)\./) : null;
738
+ return vRest && XEUtils.toNumber(vRest[1]) >= 4 && XEUtils.toNumber(vRest[2]) >= 12;
739
+ }
740
+ function handleImportEvent(params) {
741
+ if (params.options.type === "xlsx") {
742
+ if (VxeUI && hasAdvancedVersion(VxeUI.tableVersion || "")) {
743
+ return {
744
+ result: importXLSX(params),
745
+ status: false
746
+ };
747
+ }
748
+ return false;
749
+ }
750
+ }
751
+ function handleExportEvent(params) {
752
+ if (params.options.type === "xlsx") {
753
+ if (VxeUI && hasAdvancedVersion(VxeUI.tableVersion || "")) {
754
+ return {
755
+ result: exportXLSX(params),
756
+ status: false
757
+ };
758
+ }
759
+ return false;
760
+ }
761
+ }
762
+ function pluginSetup(options) {
763
+ globalExcelJS = options ? options.ExcelJS : null;
764
+ }
765
+ const VxeUIPluginExportXLSX = {
766
+ setConfig: pluginSetup,
767
+ install(core, options) {
768
+ VxeUI = core;
769
+ if (VxeUI.checkVersion) {
770
+ const pVersion = 4;
771
+ const sVersion = 11;
772
+ if (!VxeUI.checkVersion(VxeUI.tableVersion, pVersion, sVersion)) {
773
+ console.error(`[@vxe-ui/plugin-export-xlsx 4.5.2] ${VxeUI.getI18n("vxe.error.errorVersion", [`vxe-table@${VxeUI.tableVersion || "?"}`, `vxe-table v${pVersion}.${sVersion}+`])} https://vxeui.com/other4/#/plugin-export-xlsx/install`);
774
+ }
775
+ } else {
776
+ if (!/^(4)\./.test(VxeUI.uiVersion || VxeUI.tableVersion)) {
777
+ console.error("[@vxe-ui/plugin-export-xlsx 4.5.2] Requires vxe-table 4.7.0+ version. https://vxeui.com/other4/#/plugin-export-xlsx/install");
778
+ }
779
+ }
780
+ if (options) {
781
+ pluginSetup(options);
782
+ }
783
+ VxeUI.setConfig({
784
+ table: {
785
+ importConfig: {
786
+ _typeMaps: {
787
+ xlsx: 1
788
+ }
789
+ },
790
+ exportConfig: {
791
+ _typeMaps: {
792
+ xlsx: 1
793
+ }
794
+ }
795
+ }
796
+ });
797
+ VxeUI.interceptor.mixin({
798
+ "event.import": handleImportEvent,
799
+ "event.export": handleExportEvent
800
+ });
801
+ }
802
+ };
803
+ if (typeof window !== "undefined" && window.VxeUI && window.VxeUI.use) {
804
+ window.VxeUI.use(VxeUIPluginExportXLSX);
805
+ }
806
+ export {
807
+ VxeUIPluginExportXLSX,
808
+ VxeUIPluginExportXLSX as default
809
+ };