vxe-table 4.23.18 → 4.23.20

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 (135) hide show
  1. package/dist/all.esm.js +301 -274
  2. package/dist/all.esm.min.js +3 -3
  3. package/dist/style.css +4 -1
  4. package/dist/style.mini.css +1 -1
  5. package/es/components.d.ts +1 -3
  6. package/es/components.js +1 -2
  7. package/es/esm.index.d.ts +7 -0
  8. package/es/esm.index.js +8 -0
  9. package/es/style.css +4 -1
  10. package/es/style.mini.css +1 -1
  11. package/es/table/module/edit/hook.js +2 -4
  12. package/es/table/module/export/export-panel.js +5 -5
  13. package/es/table/module/export/hook.js +8 -10
  14. package/es/table/module/export/import-panel.js +5 -5
  15. package/es/table/src/table.js +0 -1
  16. package/es/table/style.css +4 -1
  17. package/es/table/style.mini.css +1 -1
  18. package/es/ui/abandon.d.ts +82 -0
  19. package/es/ui/abandon.js +90 -0
  20. package/es/ui/index.d.ts +1 -82
  21. package/es/ui/index.js +2 -88
  22. package/es/ui/src/log.js +1 -1
  23. package/es/vxe-table/style.css +4 -1
  24. package/es/vxe-table/style.mini.css +1 -1
  25. package/lib/components.d.ts +1 -3
  26. package/lib/components.js +1 -2
  27. package/lib/esm.index.d.ts +7 -0
  28. package/lib/esm.index.js +39 -0
  29. package/lib/index.umd.js +266 -270
  30. package/lib/index.umd.min.js +3 -3
  31. package/lib/style.css +4 -1
  32. package/lib/style.mini.css +1 -1
  33. package/lib/table/module/edit/hook.js +2 -4
  34. package/lib/table/module/export/export-panel.js +5 -5
  35. package/lib/table/module/export/hook.js +8 -10
  36. package/lib/table/module/export/import-panel.js +5 -5
  37. package/lib/table/src/table.js +0 -1
  38. package/lib/table/style/style.css +4 -1
  39. package/lib/table/style/style.mini.css +1 -1
  40. package/lib/ui/abandon.d.ts +82 -0
  41. package/lib/ui/abandon.js +110 -0
  42. package/lib/ui/index.d.ts +1 -82
  43. package/lib/ui/index.js +3 -88
  44. package/lib/ui/src/log.js +1 -1
  45. package/lib/vxe-table/style/style.css +4 -1
  46. package/lib/vxe-table/style/style.mini.css +1 -1
  47. package/package.json +2 -2
  48. package/packages/colgroup/index.ts +22 -22
  49. package/packages/column/index.ts +22 -22
  50. package/packages/components.ts +42 -45
  51. package/packages/esm.index.ts +10 -0
  52. package/packages/grid/index.ts +18 -18
  53. package/packages/grid/src/emits.ts +5 -5
  54. package/packages/grid/src/grid.ts +2220 -2220
  55. package/packages/grid/src/props.ts +22 -22
  56. package/packages/index.ts +13 -13
  57. package/packages/locale/lang/ar-EG.ts +914 -914
  58. package/packages/locale/lang/de-DE.ts +914 -914
  59. package/packages/locale/lang/en-US.ts +914 -914
  60. package/packages/locale/lang/es-ES.ts +914 -914
  61. package/packages/locale/lang/fr-FR.ts +914 -914
  62. package/packages/locale/lang/hu-HU.ts +914 -914
  63. package/packages/locale/lang/hy-AM.ts +914 -914
  64. package/packages/locale/lang/id-ID.ts +914 -914
  65. package/packages/locale/lang/it-IT.ts +914 -914
  66. package/packages/locale/lang/ja-JP.ts +914 -914
  67. package/packages/locale/lang/ko-KR.ts +914 -914
  68. package/packages/locale/lang/ms-MY.ts +914 -914
  69. package/packages/locale/lang/nb-NO.ts +914 -914
  70. package/packages/locale/lang/pt-BR.ts +914 -914
  71. package/packages/locale/lang/ru-RU.ts +914 -914
  72. package/packages/locale/lang/th-TH.ts +914 -914
  73. package/packages/locale/lang/ug-CN.ts +914 -914
  74. package/packages/locale/lang/uk-UA.ts +914 -914
  75. package/packages/locale/lang/uz-UZ.ts +914 -914
  76. package/packages/locale/lang/vi-VN.ts +914 -914
  77. package/packages/locale/lang/zh-CHT.ts +914 -914
  78. package/packages/locale/lang/zh-CN.ts +914 -914
  79. package/packages/locale/lang/zh-HK.ts +914 -914
  80. package/packages/locale/lang/zh-MO.ts +914 -914
  81. package/packages/locale/lang/zh-TC.ts +914 -914
  82. package/packages/locale/lang/zh-TW.ts +914 -914
  83. package/packages/table/index.ts +26 -26
  84. package/packages/table/module/custom/hook.ts +510 -510
  85. package/packages/table/module/custom/panel.ts +2002 -2002
  86. package/packages/table/module/edit/hook.ts +1232 -1235
  87. package/packages/table/module/export/export-panel.ts +697 -697
  88. package/packages/table/module/export/hook.ts +2158 -2160
  89. package/packages/table/module/export/import-panel.ts +319 -319
  90. package/packages/table/module/export/util.ts +25 -25
  91. package/packages/table/module/filter/hook.ts +505 -505
  92. package/packages/table/module/filter/panel.ts +368 -368
  93. package/packages/table/module/keyboard/hook.ts +498 -498
  94. package/packages/table/module/menu/hook.ts +330 -330
  95. package/packages/table/module/menu/panel.ts +272 -272
  96. package/packages/table/module/validator/hook.ts +653 -653
  97. package/packages/table/render/index.ts +1819 -1819
  98. package/packages/table/src/body.ts +1078 -1078
  99. package/packages/table/src/cell.ts +1524 -1524
  100. package/packages/table/src/column.ts +192 -192
  101. package/packages/table/src/columnInfo.ts +232 -232
  102. package/packages/table/src/emits.ts +134 -134
  103. package/packages/table/src/footer.ts +425 -425
  104. package/packages/table/src/group.ts +67 -67
  105. package/packages/table/src/header.ts +661 -661
  106. package/packages/table/src/props.ts +336 -336
  107. package/packages/table/src/store.ts +14 -14
  108. package/packages/table/src/table.ts +0 -1
  109. package/packages/table/src/use/cell-view.ts +41 -41
  110. package/packages/table/src/use/index.ts +1 -1
  111. package/packages/table/src/util.ts +1206 -1206
  112. package/packages/toolbar/index.ts +18 -18
  113. package/packages/toolbar/src/toolbar.ts +768 -768
  114. package/packages/ui/abandon.ts +136 -0
  115. package/packages/ui/index.ts +404 -520
  116. package/packages/ui/src/anime.ts +51 -51
  117. package/packages/ui/src/comp.ts +3 -3
  118. package/packages/ui/src/dom.ts +466 -466
  119. package/packages/ui/src/log.ts +19 -19
  120. package/packages/ui/src/utils.ts +66 -66
  121. package/packages/ui/src/vn.ts +55 -55
  122. package/packages/v-x-e-table/index.d.ts +3 -3
  123. package/packages/v-x-e-table/index.ts +3 -3
  124. package/styles/components/table.scss +2 -1
  125. package/types/all.d.ts +76 -76
  126. package/types/index.d.ts +4 -4
  127. /package/dist/{iconfont.1794366305845.ttf → iconfont.1794633824975.ttf} +0 -0
  128. /package/dist/{iconfont.1794366305845.woff → iconfont.1794633824975.woff} +0 -0
  129. /package/dist/{iconfont.1794366305845.woff2 → iconfont.1794633824975.woff2} +0 -0
  130. /package/es/{iconfont.1794366305845.ttf → iconfont.1794633824975.ttf} +0 -0
  131. /package/es/{iconfont.1794366305845.woff → iconfont.1794633824975.woff} +0 -0
  132. /package/es/{iconfont.1794366305845.woff2 → iconfont.1794633824975.woff2} +0 -0
  133. /package/lib/{iconfont.1794366305845.ttf → iconfont.1794633824975.ttf} +0 -0
  134. /package/lib/{iconfont.1794366305845.woff → iconfont.1794633824975.woff} +0 -0
  135. /package/lib/{iconfont.1794366305845.woff2 → iconfont.1794633824975.woff2} +0 -0
@@ -1,2160 +1,2158 @@
1
- import { nextTick } from 'vue'
2
- import XEUtils from 'xe-utils'
3
- import { VxeUI } from '@vxe-ui/core'
4
- import { isColumnInfo, getCellValue, createHandleGetRowId } from '../../src/util'
5
- import { parseFile, formatText, eqEmptyValue, hasEnableConf } from '../../../ui/src/utils'
6
- import { hasClass, toCssUnit } from '../../../ui/src/dom'
7
- import { createHtmlPage, getExportBlobByContent } from './util'
8
- import { createComponentLog } from '../../../ui/src/log'
9
-
10
- import type { VxeTablePropTypes, VxeColumnPropTypes, TableExportMethods, VxeGridPropTypes, VxeTableDefines, VxeTableConstructor, VxeTablePrivateMethods } from '../../../../types'
11
-
12
- const { warnLog, errLog } = createComponentLog('table')
13
-
14
- const { getI18n, hooks, renderer } = VxeUI
15
-
16
- let htmlCellElem: any
17
-
18
- const csvBOM = '\ufeff'
19
- const enterSymbol = '\r\n'
20
-
21
- function defaultFilterExportColumn(column: VxeTableDefines.ColumnInfo) {
22
- return !!column.field || ['seq', 'checkbox', 'radio'].indexOf(column.type || '') === -1
23
- }
24
-
25
- const getConvertColumns = (columns: any) => {
26
- const result: any = []
27
- columns.forEach((column: any) => {
28
- if (column.childNodes && column.childNodes.length) {
29
- result.push(column)
30
- result.push(...getConvertColumns(column.childNodes))
31
- } else {
32
- result.push(column)
33
- }
34
- })
35
- return result
36
- }
37
-
38
- const convertToRows = (originColumns: any): any[][] => {
39
- let maxLevel = 1
40
- const traverse = (column: any, parent?: any) => {
41
- if (parent) {
42
- column._level = parent._level + 1
43
- if (maxLevel < column._level) {
44
- maxLevel = column._level
45
- }
46
- }
47
- if (column.childNodes && column.childNodes.length) {
48
- let colSpan = 0
49
- column.childNodes.forEach((subColumn: any) => {
50
- traverse(subColumn, column)
51
- colSpan += subColumn._colSpan
52
- })
53
- column._colSpan = colSpan
54
- } else {
55
- column._colSpan = 1
56
- }
57
- }
58
-
59
- originColumns.forEach((column: any) => {
60
- column._level = 1
61
- traverse(column)
62
- })
63
-
64
- const rows: any = []
65
- for (let i = 0; i < maxLevel; i++) {
66
- rows.push([])
67
- }
68
-
69
- const allColumns = getConvertColumns(originColumns)
70
-
71
- allColumns.forEach((column: any) => {
72
- if (column.childNodes && column.childNodes.length) {
73
- column._rowSpan = 1
74
- } else {
75
- column._rowSpan = maxLevel - column._level + 1
76
- }
77
- rows[column._level - 1].push(column)
78
- })
79
-
80
- return rows
81
- }
82
-
83
- function toTableBorder(border: VxeTablePropTypes.Border | undefined) {
84
- if (border === true) {
85
- return 'full'
86
- }
87
- if (border) {
88
- return border
89
- }
90
- return 'default'
91
- }
92
-
93
- function getBooleanValue(cellValue: any) {
94
- return cellValue === 'TRUE' || cellValue === 'true' || cellValue === true
95
- }
96
-
97
- function getFooterData($xeTable: VxeTableConstructor & VxeTablePrivateMethods, opts: VxeTablePropTypes.ExportHandleOptions, footerTableData: any[]) {
98
- const $xeGrid = $xeTable.xeGrid
99
- const $xeGantt = $xeTable.xeGantt
100
-
101
- const { footerFilterMethod } = opts
102
- return footerFilterMethod ? footerTableData.filter((items, index) => footerFilterMethod({ $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt, items, $rowIndex: index })) : footerTableData
103
- }
104
-
105
- function getCsvCellTypeLabel(column: any, cellValue: any) {
106
- if (cellValue) {
107
- if (column.type === 'seq') {
108
- return `\t${cellValue}`
109
- }
110
- switch (column.cellType) {
111
- case 'string':
112
- if (!isNaN(cellValue)) {
113
- return `\t${cellValue}`
114
- }
115
- break
116
- case 'number':
117
- break
118
- default:
119
- if (cellValue.length >= 12 && !isNaN(cellValue)) {
120
- return `\t${cellValue}`
121
- }
122
- break
123
- }
124
- }
125
- return cellValue
126
- }
127
-
128
- function toTxtCellLabel(val: any) {
129
- if (/[",\s\n]/.test(val)) {
130
- return `"${val.replace(/"/g, '""')}"`
131
- }
132
- return XEUtils.eqNull(val) ? '' : val
133
- }
134
-
135
- function getElementsByTagName(elem: any, qualifiedName: any) {
136
- return elem.getElementsByTagName(qualifiedName) as HTMLElement[]
137
- }
138
-
139
- function getTxtCellKey(now: number) {
140
- return `#${now}@${XEUtils.uniqueId()}`
141
- }
142
-
143
- function replaceTxtCell(cell: any, vMaps: any) {
144
- return cell.replace(/#\d+@\d+/g, (key: any) => (XEUtils.hasOwnProp(vMaps, key) ? vMaps[key] : key))
145
- }
146
-
147
- function getTxtCellValue(val: any, vMaps: any) {
148
- const rest = replaceTxtCell(val, vMaps)
149
- return rest.replace(/^"+$/g, (qVal: any) => '"'.repeat(Math.ceil(qVal.length / 2)))
150
- }
151
-
152
- function toExportField(
153
- tableConf: {
154
- fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
155
- titleMaps: Record<string, VxeTableDefines.ColumnInfo>
156
- },
157
- field: string
158
- ) {
159
- const { fieldMaps, titleMaps } = tableConf
160
- // title 转 field
161
- if (!fieldMaps[field]) {
162
- const teCol = titleMaps[field]
163
- if (teCol && teCol.field) {
164
- field = teCol.field
165
- }
166
- }
167
- return field
168
- }
169
-
170
- function parseCsvAndTxt(
171
- tableConf: {
172
- fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
173
- titleMaps: Record<string, VxeTableDefines.ColumnInfo>
174
- },
175
- content: string,
176
- cellSeparator: string
177
- ) {
178
- const list = content.split(enterSymbol)
179
- const rows: any[] = []
180
- let fields: string[] = []
181
- if (list.length) {
182
- const vMaps: any = {}
183
- const now = Date.now()
184
- list.forEach((rVal) => {
185
- if (rVal) {
186
- const item: any = {}
187
- rVal = rVal
188
- .replace(/("")|(\n)/g, (text: string, dVal: string) => {
189
- const key = getTxtCellKey(now)
190
- vMaps[key] = dVal ? '"' : '\n'
191
- return key
192
- })
193
- .replace(/"(.*?)"/g, (text: string, cVal: string) => {
194
- const key = getTxtCellKey(now)
195
- vMaps[key] = replaceTxtCell(cVal, vMaps)
196
- return key
197
- })
198
- const cells: string[] = rVal.split(cellSeparator)
199
- if (!fields.length) {
200
- fields = cells.map((val: string) => toExportField(tableConf, getTxtCellValue(val.trim(), vMaps)))
201
- } else {
202
- cells.forEach((val, colIndex) => {
203
- if (colIndex < fields.length) {
204
- item[fields[colIndex]] = getTxtCellValue(val.trim(), vMaps)
205
- }
206
- })
207
- rows.push(item)
208
- }
209
- }
210
- })
211
- }
212
- return { fields, rows }
213
- }
214
-
215
- function parseCsv(
216
- tableConf: {
217
- fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
218
- titleMaps: Record<string, VxeTableDefines.ColumnInfo>
219
- },
220
- content: string
221
- ) {
222
- return parseCsvAndTxt(tableConf, content, ',')
223
- }
224
-
225
- function parseTxt(
226
- tableConf: {
227
- fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
228
- titleMaps: Record<string, VxeTableDefines.ColumnInfo>
229
- },
230
- content: string
231
- ) {
232
- return parseCsvAndTxt(tableConf, content, '\t')
233
- }
234
-
235
- function parseHTML(
236
- tableConf: {
237
- fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
238
- titleMaps: Record<string, VxeTableDefines.ColumnInfo>
239
- },
240
- content: string
241
- ) {
242
- const domParser = new DOMParser()
243
- const xmlDoc = domParser.parseFromString(content, 'text/html')
244
- const bodyNodes = getElementsByTagName(xmlDoc, 'body')
245
- const rows: any[] = []
246
- const fields: string[] = []
247
- if (bodyNodes.length) {
248
- const tableNodes = getElementsByTagName(bodyNodes[0], 'table')
249
- if (tableNodes.length) {
250
- const theadNodes = getElementsByTagName(tableNodes[0], 'thead')
251
- if (theadNodes.length) {
252
- XEUtils.arrayEach(getElementsByTagName(theadNodes[0], 'tr'), (rowNode) => {
253
- XEUtils.arrayEach(getElementsByTagName(rowNode, 'th'), (cellNode) => {
254
- fields.push(toExportField(tableConf, cellNode.textContent || ''))
255
- })
256
- })
257
- const tbodyNodes = getElementsByTagName(tableNodes[0], 'tbody')
258
- if (tbodyNodes.length) {
259
- XEUtils.arrayEach(getElementsByTagName(tbodyNodes[0], 'tr'), (rowNode) => {
260
- const item: any = {}
261
- XEUtils.arrayEach(getElementsByTagName(rowNode, 'td'), (cellNode, colIndex) => {
262
- if (fields[colIndex]) {
263
- item[fields[colIndex]] = cellNode.textContent || ''
264
- }
265
- })
266
- rows.push(item)
267
- })
268
- }
269
- }
270
- }
271
- }
272
- return { fields, rows }
273
- }
274
-
275
- function parseXML(
276
- tableConf: {
277
- fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
278
- titleMaps: Record<string, VxeTableDefines.ColumnInfo>
279
- },
280
- content: string
281
- ) {
282
- const domParser = new DOMParser()
283
- const xmlDoc = domParser.parseFromString(content, 'application/xml')
284
- const sheetNodes = getElementsByTagName(xmlDoc, 'Worksheet')
285
- const rows: any[] = []
286
- const fields: string[] = []
287
- if (sheetNodes.length) {
288
- const tableNodes = getElementsByTagName(sheetNodes[0], 'Table')
289
- if (tableNodes.length) {
290
- const rowNodes = getElementsByTagName(tableNodes[0], 'Row')
291
- if (rowNodes.length) {
292
- XEUtils.arrayEach(getElementsByTagName(rowNodes[0], 'Cell'), (cellNode) => {
293
- fields.push(toExportField(tableConf, cellNode.textContent || ''))
294
- })
295
- XEUtils.arrayEach(rowNodes, (rowNode, index) => {
296
- if (index) {
297
- const item: any = {}
298
- const cellNodes = getElementsByTagName(rowNode, 'Cell')
299
- XEUtils.arrayEach(cellNodes, (cellNode, colIndex) => {
300
- if (fields[colIndex]) {
301
- item[fields[colIndex]] = cellNode.textContent
302
- }
303
- })
304
- rows.push(item)
305
- }
306
- })
307
- }
308
- }
309
- }
310
- return { fields, rows }
311
- }
312
-
313
- function clearColumnConvert(columns: any) {
314
- XEUtils.eachTree(
315
- columns,
316
- (column: any) => {
317
- delete column._level
318
- delete column._colSpan
319
- delete column._rowSpan
320
- delete column._children
321
- delete column.childNodes
322
- },
323
- { children: 'children' }
324
- )
325
- }
326
-
327
- const tableExportMethodKeys: (keyof TableExportMethods)[] = ['exportData', 'importByFile', 'importData', 'saveFile', 'readFile', 'print', 'getPrintHtml', 'openImport', 'closeImport', 'openExport', 'closeExport', 'openPrint', 'closePrint']
328
-
329
- hooks.add('tableExportModule', {
330
- setupTable($xeTable) {
331
- const { props, reactData, internalData } = $xeTable
332
- const { computeTreeOpts, computePrintOpts, computeExportOpts, computeImportOpts, computeSeqOpts, computeRadioOpts, computeCheckboxOpts, computeColumnOpts, computeAggregateOpts, computeRendererOpts } = $xeTable.getComputeMaps()
333
-
334
- const getSeq = (cellValue: any, row: any, $rowIndex: number, column: VxeTableDefines.ColumnInfo, $columnIndex: number) => {
335
- const seqOpts = computeSeqOpts.value
336
- const seqMd = seqOpts.seqMethod || (column as any).seqMethod
337
- if (seqMd) {
338
- return seqMd({
339
- $table: $xeTable,
340
- row,
341
- rowIndex: $xeTable.getRowIndex(row),
342
- _rowIndex: $xeTable.getVTRowIndex(row),
343
- $rowIndex,
344
- column,
345
- columnIndex: $xeTable.getColumnIndex(column),
346
- _columnIndex: $xeTable.getVTColumnIndex(column),
347
- $columnIndex
348
- })
349
- }
350
- return cellValue
351
- }
352
-
353
- function getHeaderTitle(opts: VxeTablePropTypes.ExportHandleOptions, column: VxeTableDefines.ColumnInfo) {
354
- const columnOpts = computeColumnOpts.value
355
- const headExportMethod = column.headerExportMethod || columnOpts.headerExportMethod
356
- return headExportMethod ? headExportMethod({ column, options: opts, $table: $xeTable }) : (opts.isTitle ? $xeTable.getHeaderCellLabel(column) : column.field) || ''
357
- }
358
-
359
- const toBooleanValue = (cellValue: any) => {
360
- return XEUtils.isBoolean(cellValue) ? (cellValue ? 'TRUE' : 'FALSE') : cellValue
361
- }
362
-
363
- const toStringValue = (cellValue: any) => {
364
- return eqEmptyValue(cellValue) ? '' : `${cellValue}`
365
- }
366
-
367
- const getBodyLabelData = (opts: VxeTablePropTypes.ExportHandleOptions, columns: VxeTableDefines.ColumnInfo[], datas: any[]) => {
368
- const { isTreeAllExpanded, isRowGroupAllExpanded, mode: expMode } = opts
369
- const { treeConfig } = props
370
- const { isRowGroupStatus } = reactData
371
- const { fullColumnFieldData, fullAllDataRowIdData } = internalData
372
- const radioOpts = computeRadioOpts.value
373
- const checkboxOpts = computeCheckboxOpts.value
374
- const treeOpts = computeTreeOpts.value
375
- const columnOpts = computeColumnOpts.value
376
- const aggregateOpts = computeAggregateOpts.value
377
- const rendererOpts = computeRendererOpts.value
378
- if (!htmlCellElem) {
379
- htmlCellElem = document.createElement('div')
380
- }
381
- const { handleGetRowId } = createHandleGetRowId($xeTable)
382
- if (isRowGroupStatus) {
383
- // 如果是数据分组
384
- const { mode: aggMode, showTotal, totalMethod, countFields, contentMethod, formatValuesMethod, mapChildrenField } = aggregateOpts
385
- const rest: any[] = []
386
- const expandMaps: Record<string, boolean> = {}
387
- const useMaps: Record<string, boolean> = {}
388
- XEUtils.eachTree(
389
- datas,
390
- (item, $rowIndex, items, path, parentItem, nodes) => {
391
- const row = item._row || item
392
- const rowid = handleGetRowId(row)
393
- if (useMaps[rowid]) {
394
- return
395
- }
396
- const parentRow = parentItem && parentItem._row ? parentItem._row : parentItem
397
- const pRowid = parentRow ? handleGetRowId(parentRow) : ''
398
- if (isRowGroupAllExpanded || !parentRow || (expandMaps[pRowid] && $xeTable.isRowExpandByRow(parentRow))) {
399
- const hasRowChild = mapChildrenField && row[mapChildrenField] && row[mapChildrenField].length
400
- const item: any = {
401
- _row: row,
402
- _level: nodes.length - 1,
403
- _hasChild: hasRowChild,
404
- _expand: hasRowChild && $xeTable.isRowExpandByRow(row)
405
- }
406
- columns.forEach((column, $columnIndex) => {
407
- const { field, editRender, cellRender, aggFunc, rowGroupNode } = column
408
- let cellValue: string | number | boolean | null = ''
409
- const renderOpts = editRender || cellRender
410
- let bodyExportMethod: VxeColumnPropTypes.ExportMethod | undefined = column.exportMethod || columnOpts.exportMethod
411
- if (!bodyExportMethod && renderOpts && renderOpts.name) {
412
- const compConf = rendererOpts[renderOpts.name] || renderer.get(renderOpts.name)
413
- if (compConf) {
414
- bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod
415
- }
416
- }
417
- if (!bodyExportMethod) {
418
- bodyExportMethod = columnOpts.exportMethod
419
- }
420
- if (bodyExportMethod) {
421
- cellValue = bodyExportMethod({ $table: $xeTable, row, column, options: opts })
422
- } else {
423
- switch (column.type) {
424
- case 'seq': {
425
- const seqVal = path.map((num, i) => (i % 2 === 0 ? Number(num) + 1 : '.')).join('')
426
- cellValue = expMode === 'all' ? seqVal : getSeq(seqVal, row, $rowIndex, column, $columnIndex)
427
- break
428
- }
429
- case 'checkbox': {
430
- cellValue = toBooleanValue($xeTable.isCheckedByCheckboxRow(row))
431
- item._checkboxLabel = checkboxOpts.labelField ? XEUtils.get(row, checkboxOpts.labelField) : ''
432
- item._checkboxDisabled = checkboxOpts.checkMethod && !checkboxOpts.checkMethod({ $table: $xeTable, row })
433
- break
434
- }
435
- case 'radio': {
436
- cellValue = toBooleanValue($xeTable.isCheckedByRadioRow(row))
437
- item._radioLabel = radioOpts.labelField ? XEUtils.get(row, radioOpts.labelField) : ''
438
- item._radioDisabled = radioOpts.checkMethod && !radioOpts.checkMethod({ $table: $xeTable, row })
439
- break
440
- }
441
- default: {
442
- if (field && row.isAggregate) {
443
- const aggRow: VxeTableDefines.AggregateRowInfo = row
444
- const aggData = aggRow.aggData
445
- const currAggData = aggData ? aggData[field] : null
446
- const groupField = aggRow.groupField
447
- const groupContent = aggRow.groupContent
448
- const childList = mapChildrenField ? aggRow[mapChildrenField] || [] : []
449
- const childCount = aggRow.childCount
450
- const colRest = fullColumnFieldData[groupField] || {}
451
- const ctParams = {
452
- $table: $xeTable,
453
- groupField,
454
- groupColumn: (colRest ? colRest.column : null) as VxeTableDefines.ColumnInfo,
455
- column,
456
- groupValue: groupContent,
457
- childList,
458
- childCount,
459
- aggValue: null as any,
460
-
461
- /**
462
- * 已废弃
463
- * @deprecated
464
- */
465
- children: childList,
466
- /**
467
- * 已废弃
468
- * @deprecated
469
- */
470
- totalValue: childCount
471
- }
472
- if (aggMode === 'column' ? field === aggRow.groupField : rowGroupNode) {
473
- cellValue = groupContent
474
- if (contentMethod) {
475
- cellValue = `${contentMethod(ctParams)}`
476
- }
477
- if (showTotal) {
478
- cellValue = getI18n('vxe.table.rowGroupContentTotal', [cellValue, totalMethod ? totalMethod(ctParams) : childCount, childCount])
479
- }
480
- } else if ($xeTable.getPivotTableAggregateCellAggValue) {
481
- const aggParams = {
482
- $table: $xeTable,
483
- row,
484
- column
485
- }
486
- cellValue = $xeTable.getPivotTableAggregateCellAggValue(aggParams)
487
- } else if (aggFunc === true || (countFields && countFields.includes(field))) {
488
- cellValue = currAggData ? currAggData.value : childCount
489
- ctParams.aggValue = cellValue
490
- if (formatValuesMethod) {
491
- cellValue = formatValuesMethod(ctParams)
492
- }
493
- }
494
- } else if (opts.original) {
495
- cellValue = getCellValue(row, column)
496
- } else {
497
- cellValue = $xeTable.getCellLabel(row, column)
498
- if (column.type === 'html') {
499
- htmlCellElem.innerHTML = cellValue
500
- cellValue = htmlCellElem.innerText.trim()
501
- } else {
502
- const cell = $xeTable.getCellElement(row, column)
503
- if (cell && !hasClass(cell, 'is--progress')) {
504
- cellValue = cell.innerText.trim()
505
- }
506
- }
507
- }
508
- break
509
- }
510
- }
511
- }
512
- item[column.id] = toStringValue(cellValue)
513
- })
514
- useMaps[rowid] = true
515
- if (pRowid) {
516
- expandMaps[pRowid] = true
517
- }
518
- rest.push(Object.assign(item, row))
519
- }
520
- },
521
- { children: mapChildrenField }
522
- )
523
- return rest
524
- }
525
- if (treeConfig) {
526
- // 如果是树结构
527
- const { seqMode } = treeOpts
528
- const childrenField = treeOpts.children || treeOpts.childrenField
529
- const rest: any[] = []
530
- const expandMaps: Record<string, boolean> = {}
531
- const useMaps: Record<string, boolean> = {}
532
- XEUtils.eachTree(
533
- datas,
534
- (item, $rowIndex, items, path, parentItem, nodes) => {
535
- const row = item._row || item
536
- const rowid = handleGetRowId(row)
537
- if (useMaps[rowid]) {
538
- return
539
- }
540
- const parentRow = parentItem && parentItem._row ? parentItem._row : parentItem
541
- const pRowid = parentRow ? handleGetRowId(parentRow) : ''
542
- if (isTreeAllExpanded || !parentRow || (expandMaps[pRowid] && $xeTable.isTreeExpandByRow(parentRow))) {
543
- const hasRowChild = row[childrenField] && row[childrenField].length
544
- const item: any = {
545
- _row: row,
546
- _level: nodes.length - 1,
547
- _hasChild: hasRowChild,
548
- _expand: hasRowChild && $xeTable.isTreeExpandByRow(row)
549
- }
550
- const rowRest = fullAllDataRowIdData[rowid] || {}
551
- columns.forEach((column, $columnIndex) => {
552
- let cellValue: string | number | boolean | null = ''
553
- const renderOpts = column.editRender || column.cellRender
554
- let bodyExportMethod: VxeColumnPropTypes.ExportMethod | undefined = column.exportMethod || columnOpts.exportMethod
555
- if (!bodyExportMethod && renderOpts && renderOpts.name) {
556
- const compConf = rendererOpts[renderOpts.name] || renderer.get(renderOpts.name)
557
- if (compConf) {
558
- bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod
559
- }
560
- }
561
- if (!bodyExportMethod) {
562
- bodyExportMethod = columnOpts.exportMethod
563
- }
564
- if (bodyExportMethod) {
565
- cellValue = bodyExportMethod({ $table: $xeTable, row, column, options: opts })
566
- } else {
567
- switch (column.type) {
568
- case 'seq': {
569
- let seqVal: number | string = path.map((num, i) => (i % 2 === 0 ? Number(num) + 1 : '.')).join('')
570
- if (seqMode === 'increasing') {
571
- seqVal = rowRest ? rowRest._index + 1 : -1
572
- }
573
- cellValue = expMode === 'all' ? seqVal : getSeq(seqVal, row, $rowIndex, column, $columnIndex)
574
- break
575
- }
576
- case 'checkbox':
577
- cellValue = toBooleanValue($xeTable.isCheckedByCheckboxRow(row))
578
- item._checkboxLabel = checkboxOpts.labelField ? XEUtils.get(row, checkboxOpts.labelField) : ''
579
- item._checkboxDisabled = checkboxOpts.checkMethod && !checkboxOpts.checkMethod({ $table: $xeTable, row })
580
- break
581
- case 'radio':
582
- cellValue = toBooleanValue($xeTable.isCheckedByRadioRow(row))
583
- item._radioLabel = radioOpts.labelField ? XEUtils.get(row, radioOpts.labelField) : ''
584
- item._radioDisabled = radioOpts.checkMethod && !radioOpts.checkMethod({ $table: $xeTable, row })
585
- break
586
- default:
587
- if (opts.original) {
588
- cellValue = getCellValue(row, column)
589
- } else {
590
- cellValue = $xeTable.getCellLabel(row, column)
591
- if (column.type === 'html') {
592
- htmlCellElem.innerHTML = cellValue
593
- cellValue = htmlCellElem.innerText.trim()
594
- } else {
595
- const cell = $xeTable.getCellElement(row, column)
596
- if (cell && !hasClass(cell, 'is--progress')) {
597
- cellValue = cell.innerText.trim()
598
- }
599
- }
600
- }
601
- }
602
- }
603
- item[column.id] = toStringValue(cellValue)
604
- })
605
- useMaps[rowid] = true
606
- if (pRowid) {
607
- expandMaps[pRowid] = true
608
- }
609
- rest.push(Object.assign(item, row))
610
- }
611
- },
612
- { children: childrenField }
613
- )
614
- return rest
615
- }
616
- return datas.map((row, $rowIndex) => {
617
- const item: any = {
618
- _row: row
619
- }
620
- columns.forEach((column, $columnIndex) => {
621
- let cellValue: string | number | boolean | null = ''
622
- const renderOpts = column.editRender || column.cellRender
623
- let bodyExportMethod: VxeColumnPropTypes.ExportMethod | undefined = column.exportMethod || columnOpts.exportMethod
624
- if (!bodyExportMethod && renderOpts && renderOpts.name) {
625
- const compConf = rendererOpts[renderOpts.name] || renderer.get(renderOpts.name)
626
- if (compConf) {
627
- bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod
628
- }
629
- }
630
- if (bodyExportMethod) {
631
- cellValue = bodyExportMethod({ $table: $xeTable, row, column, options: opts })
632
- } else {
633
- switch (column.type) {
634
- case 'seq': {
635
- const seqValue = $rowIndex + 1
636
- cellValue = expMode === 'all' ? seqValue : getSeq(seqValue, row, $rowIndex, column, $columnIndex)
637
- break
638
- }
639
- case 'checkbox':
640
- cellValue = toBooleanValue($xeTable.isCheckedByCheckboxRow(row))
641
- item._checkboxLabel = checkboxOpts.labelField ? XEUtils.get(row, checkboxOpts.labelField) : ''
642
- item._checkboxDisabled = checkboxOpts.checkMethod && !checkboxOpts.checkMethod({ $table: $xeTable, row })
643
- break
644
- case 'radio':
645
- cellValue = toBooleanValue($xeTable.isCheckedByRadioRow(row))
646
- item._radioLabel = radioOpts.labelField ? XEUtils.get(row, radioOpts.labelField) : ''
647
- item._radioDisabled = radioOpts.checkMethod && !radioOpts.checkMethod({ $table: $xeTable, row })
648
- break
649
- default:
650
- if (opts.original) {
651
- cellValue = getCellValue(row, column)
652
- } else {
653
- cellValue = $xeTable.getCellLabel(row, column)
654
- if (column.type === 'html') {
655
- htmlCellElem.innerHTML = cellValue
656
- cellValue = htmlCellElem.innerText.trim()
657
- } else {
658
- const cell = $xeTable.getCellElement(row, column)
659
- if (cell && !hasClass(cell, 'is--progress')) {
660
- cellValue = cell.innerText.trim()
661
- }
662
- }
663
- }
664
- }
665
- }
666
- item[column.id] = toStringValue(cellValue)
667
- })
668
- return item
669
- })
670
- }
671
-
672
- const getExportData = (opts: VxeTablePropTypes.ExportHandleOptions) => {
673
- const $xeGrid = $xeTable.xeGrid
674
- const $xeGantt = $xeTable.xeGantt
675
-
676
- const { columns, dataFilterMethod } = opts
677
- let datas = opts.data
678
- if (dataFilterMethod) {
679
- datas = datas.filter((row, index) => dataFilterMethod({ $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt, row, $rowIndex: index }))
680
- }
681
- return getBodyLabelData(opts, columns, datas)
682
- }
683
-
684
- const getFooterCellValue = (opts: VxeTablePropTypes.ExportHandleOptions, row: any, column: VxeTableDefines.ColumnInfo) => {
685
- const columnOpts = computeColumnOpts.value
686
- const rendererOpts = computeRendererOpts.value
687
- const renderOpts = column.editRender || column.cellRender
688
- let footLabelMethod: VxeColumnPropTypes.FooterExportMethod | undefined = column.footerExportMethod
689
- if (!footLabelMethod && renderOpts && renderOpts.name) {
690
- const compConf = rendererOpts[renderOpts.name] || renderer.get(renderOpts.name)
691
- if (compConf) {
692
- footLabelMethod = compConf.tableFooterExportMethod || compConf.footerExportMethod
693
- }
694
- }
695
- if (!footLabelMethod) {
696
- footLabelMethod = columnOpts.footerExportMethod
697
- }
698
- if (footLabelMethod) {
699
- const _columnIndex = $xeTable.getVTColumnIndex(column)
700
- return footLabelMethod({ $table: $xeTable, items: row, itemIndex: _columnIndex, row, _columnIndex, column, options: opts })
701
- }
702
- const cellValue = $xeTable.getFooterCellLabel(row, column)
703
- return cellValue
704
- }
705
-
706
- const toCsv = ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, opts: VxeTablePropTypes.ExportHandleOptions, columns: VxeTableDefines.ColumnInfo[], datas: any[]) => {
707
- let content = csvBOM
708
- if (opts.isHeader) {
709
- content += columns.map((column) => toTxtCellLabel(getHeaderTitle(opts, column))).join(',') + enterSymbol
710
- }
711
- datas.forEach((row) => {
712
- content += columns.map((column) => toTxtCellLabel(getCsvCellTypeLabel(column, row[column.id]))).join(',') + enterSymbol
713
- })
714
- if (opts.isFooter) {
715
- const { footerTableData } = reactData
716
- const footers = getFooterData($xeTable, opts, footerTableData)
717
- footers.forEach((row) => {
718
- content += columns.map((column: any) => toTxtCellLabel(getFooterCellValue(opts, row, column))).join(',') + enterSymbol
719
- })
720
- }
721
- return content
722
- }
723
-
724
- const toTxt = ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, opts: VxeTablePropTypes.ExportHandleOptions, columns: VxeTableDefines.ColumnInfo[], datas: any[]) => {
725
- let content = ''
726
- if (opts.isHeader) {
727
- content += columns.map((column) => toTxtCellLabel(getHeaderTitle(opts, column))).join('\t') + enterSymbol
728
- }
729
- datas.forEach((row) => {
730
- content += columns.map((column) => toTxtCellLabel(row[column.id])).join('\t') + enterSymbol
731
- })
732
- if (opts.isFooter) {
733
- const { footerTableData } = reactData
734
- const footers = getFooterData($xeTable, opts, footerTableData)
735
- footers.forEach((row) => {
736
- content += columns.map((column: any) => toTxtCellLabel(getFooterCellValue(opts, row, column))).join('\t') + enterSymbol
737
- })
738
- }
739
- return content
740
- }
741
-
742
- const hasEllipsis = (column: VxeTableDefines.ColumnInfo, property: 'showOverflow' | 'showHeaderOverflow', allColumnOverflow: VxeTablePropTypes.ShowOverflow | undefined) => {
743
- const columnOverflow = column[property]
744
- const headOverflow = XEUtils.isUndefined(columnOverflow) || XEUtils.isNull(columnOverflow) ? allColumnOverflow : columnOverflow
745
- const showEllipsis = headOverflow === 'ellipsis'
746
- const showTitle = headOverflow === 'title'
747
- const showTooltip = headOverflow === true || headOverflow === 'tooltip'
748
- let isEllipsis = showTitle || showTooltip || showEllipsis
749
- // 虚拟滚动不支持动态高度
750
- const { scrollXLoad, scrollYLoad } = reactData
751
- if ((scrollXLoad || scrollYLoad) && !isEllipsis) {
752
- isEllipsis = true
753
- }
754
- return isEllipsis
755
- }
756
-
757
- const getCustomColKey = (conf: VxeTableDefines.ColumnInfo<any> | VxeTablePropTypes.ExportOrPrintColumnOption) => {
758
- return `${conf.field || ''}:${conf.type || ''}`
759
- }
760
-
761
- const toHtml = (opts: VxeTablePropTypes.ExportHandleOptions, columns: VxeTableDefines.ColumnInfo[], datas: any[]) => {
762
- const { id, border, treeConfig, headerAlign: allHeaderAlign, align: allAlign, footerAlign: allFooterAlign, showOverflow: allColumnOverflow, showHeaderOverflow: allColumnHeaderOverflow } = props
763
- const { isAllSelected, isIndeterminate } = reactData
764
- const { mergeBodyCellMaps, mergeFooterCellMaps } = internalData
765
- const treeOpts = computeTreeOpts.value
766
- const { print: isPrint, widthMode, isHeader, isFooter, isColgroup, isMerge, colgroups, _columnConfs, original } = opts
767
- const isAutoWidth = widthMode === 'auto'
768
- const isScaleWidth = widthMode === 'scale'
769
- const isDefaultWidth = !isAutoWidth && !isScaleWidth
770
-
771
- const customWidthMaps: Record<string, number | string> = {}
772
- if (_columnConfs) {
773
- _columnConfs.forEach((conf) => {
774
- if (!isColumnInfo(conf)) {
775
- if ((conf.field || conf.type) && conf.width) {
776
- customWidthMaps[getCustomColKey(conf)] = conf.width
777
- }
778
- }
779
- })
780
- }
781
-
782
- // 计算宽度
783
- const colWidthMaps: Record<string, number> = {}
784
- const printWidthMaps: Record<string, number> = {}
785
- if (isPrint) {
786
- let tableWidth = 0
787
- columns.forEach((column) => {
788
- tableWidth += column.renderWidth
789
- })
790
- if (colgroups) {
791
- colgroups.forEach((cols) => {
792
- cols.forEach((column: any) => {
793
- if (!column.childNodes || !column.childNodes.length) {
794
- return
795
- }
796
- let childWidth = 0
797
- let countChild = 0
798
- XEUtils.eachTree(
799
- [column],
800
- (item) => {
801
- if (!item.childNodes || !column.childNodes.length) {
802
- countChild++
803
- }
804
- const ptWidth = printWidthMaps[item.id]
805
- childWidth += ptWidth || 0
806
- },
807
- { children: 'childNodes' }
808
- )
809
- const colWidth = childWidth - countChild
810
- colWidthMaps[column.id] = colWidth
811
- printWidthMaps[column.id] = XEUtils.floor((colWidth / tableWidth) * 180, 2)
812
- })
813
- })
814
- }
815
- columns.forEach((column) => {
816
- const colWidth = column.renderWidth
817
- if (column.width) {
818
- colWidthMaps[column.id] = colWidth
819
- }
820
- printWidthMaps[column.id] = XEUtils.floor((colWidth / tableWidth) * 180, 2)
821
- })
822
- }
823
-
824
- const getHeaderWidthStyle = (column: VxeTableDefines.ColumnInfo) => {
825
- const cmColKey = getCustomColKey(column)
826
- const cmWidthMaps = customWidthMaps[cmColKey]
827
- if (cmWidthMaps) {
828
- return 'width:' + toCssUnit(cmWidthMaps)
829
- }
830
- if (isAutoWidth) {
831
- return ''
832
- }
833
- if (isScaleWidth) {
834
- return printWidthMaps[column.id] ? 'width:' + printWidthMaps[column.id] + 'mm' : ''
835
- }
836
- return colWidthMaps[column.id] ? 'width:' + toCssUnit(colWidthMaps[column.id]) : ''
837
- }
838
-
839
- const getCellWidthStyle = (column: VxeTableDefines.ColumnInfo) => {
840
- const cmColKey = getCustomColKey(column)
841
- const cmWidthMaps = customWidthMaps[cmColKey]
842
- if (cmWidthMaps) {
843
- return 'width:' + toCssUnit(cmWidthMaps)
844
- }
845
- if (isAutoWidth || isDefaultWidth) {
846
- return ''
847
- }
848
- if (isScaleWidth) {
849
- return printWidthMaps[column.id] ? 'width:' + printWidthMaps[column.id] + 'mm' : ''
850
- }
851
- return colWidthMaps[column.id] ? 'width:' + toCssUnit(colWidthMaps[column.id]) : ''
852
- }
853
-
854
- const allCls = 'check-all'
855
- const clss = ['vxe-table', `border--${toTableBorder(border)}`, isPrint ? 'is--print' : '', isAutoWidth ? 'is--auto-width' : '', isScaleWidth ? 'is--scale-width' : '', isDefaultWidth ? 'is--default-width' : '', isHeader ? 'is--header' : ''].filter((cls) => cls)
856
- const tables = [`<table class="${clss.join(' ')}" border="0" cellspacing="0" cellpadding="0">`, `<colgroup>${columns.map((column) => `<col style="${getHeaderWidthStyle(column)}">`).join('')}</colgroup>`]
857
- if (isHeader) {
858
- tables.push('<thead>')
859
- if (isColgroup && !original) {
860
- colgroups.forEach((cols) => {
861
- tables.push(
862
- `<tr>${cols
863
- .map((column: any) => {
864
- const headAlign = column.headerAlign || column.align || allHeaderAlign || allAlign
865
- const classNames = hasEllipsis(column, 'showHeaderOverflow', allColumnHeaderOverflow) ? ['col--ellipsis'] : []
866
- const cellTitle = getHeaderTitle(opts, column)
867
- if (headAlign) {
868
- classNames.push(`col--${headAlign}`)
869
- }
870
- if (column.type === 'checkbox') {
871
- return `<th class="${classNames.join(' ')}" colspan="${column._colSpan}" rowspan="${column._rowSpan}"><div style="${getCellWidthStyle(column)}"><input type="checkbox" class="${allCls}" ${isAllSelected ? 'checked' : ''}><span>${cellTitle}</span></div></th>`
872
- }
873
- return `<th class="${classNames.join(' ')}" colspan="${column._colSpan}" rowspan="${column._rowSpan}" title="${cellTitle}"><div style="${getCellWidthStyle(column)}"><span>${formatText(cellTitle, true)}</span></div></th>`
874
- })
875
- .join('')}</tr>`
876
- )
877
- })
878
- } else {
879
- tables.push(
880
- `<tr>${columns
881
- .map((column: any) => {
882
- const headAlign = column.headerAlign || column.align || allHeaderAlign || allAlign
883
- const classNames = hasEllipsis(column, 'showHeaderOverflow', allColumnHeaderOverflow) ? ['col--ellipsis'] : []
884
- const cellTitle = getHeaderTitle(opts, column)
885
- if (headAlign) {
886
- classNames.push(`col--${headAlign}`)
887
- }
888
- if (column.type === 'checkbox') {
889
- return `<th class="${classNames.join(' ')}"><div style="${getCellWidthStyle(column)}"><input type="checkbox" class="${allCls}" ${isAllSelected ? 'checked' : ''}><span>${cellTitle}</span></div></th>`
890
- }
891
- return `<th class="${classNames.join(' ')}" title="${cellTitle}"><div style="${getCellWidthStyle(column)}"><span>${formatText(cellTitle, true)}</span></div></th>`
892
- })
893
- .join('')}</tr>`
894
- )
895
- }
896
- tables.push('</thead>')
897
- }
898
- if (datas.length) {
899
- tables.push('<tbody>')
900
- if (treeConfig) {
901
- datas.forEach((item: any) => {
902
- tables.push(
903
- '<tr>' +
904
- columns
905
- .map((column: any) => {
906
- const colid = column.id
907
- const cellAlign = column.align || allAlign
908
- const classNames = hasEllipsis(column, 'showOverflow', allColumnOverflow) ? ['col--ellipsis'] : []
909
- const cellValue = item[colid]
910
- if (cellAlign) {
911
- classNames.push(`col--${cellAlign}`)
912
- }
913
- if (column.treeNode) {
914
- let treeIcon = ''
915
- if (item._hasChild) {
916
- treeIcon = `<i class="${item._expand ? 'vxe-table--tree-fold-icon' : 'vxe-table--tree-unfold-icon'}"></i>`
917
- }
918
- classNames.push('vxe-table--tree-node')
919
- if (column.type === 'radio') {
920
- return `<td class="${classNames.join(' ')}" title="${cellValue}"><div style="${getCellWidthStyle(column)}"><div class="vxe-table--tree-node-wrapper" style="padding-left: ${item._level * treeOpts.indent}px"><div class="vxe-table--tree-icon-wrapper">${treeIcon}</div><div class="vxe-table--tree-cell"><input type="radio" name="radio_${id}" ${item._radioDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._radioLabel}</span></div></div></div></td>`
921
- } else if (column.type === 'checkbox') {
922
- return `<td class="${classNames.join(' ')}" title="${cellValue}"><div style="${getCellWidthStyle(column)}"><div class="vxe-table--tree-node-wrapper" style="padding-left: ${item._level * treeOpts.indent}px"><div class="vxe-table--tree-icon-wrapper">${treeIcon}</div><div class="vxe-table--tree-cell"><input type="checkbox" ${item._checkboxDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._checkboxLabel}</span></div></div></div></td>`
923
- }
924
- return `<td class="${classNames.join(' ')}" title="${cellValue}"><div style="${getCellWidthStyle(column)}"><div class="vxe-table--tree-node-wrapper" style="padding-left: ${item._level * treeOpts.indent}px"><div class="vxe-table--tree-icon-wrapper">${treeIcon}</div><div class="vxe-table--tree-cell">${cellValue}</div></div></div></td>`
925
- }
926
- if (column.type === 'radio') {
927
- return `<td class="${classNames.join(' ')}"><div style="${getCellWidthStyle(column)}"><input type="radio" name="radio_${id}" ${item._radioDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._radioLabel}</span></div></td>`
928
- } else if (column.type === 'checkbox') {
929
- return `<td class="${classNames.join(' ')}"><div style="${getCellWidthStyle(column)}"><input type="checkbox" ${item._checkboxDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._checkboxLabel}</span></div></td>`
930
- }
931
- return `<td class="${classNames.join(' ')}" title="${cellValue}"><div style="${getCellWidthStyle(column)}">${formatText(cellValue, true)}</div></td>`
932
- })
933
- .join('') +
934
- '</tr>'
935
- )
936
- })
937
- } else {
938
- datas.forEach((item) => {
939
- tables.push(
940
- '<tr>' +
941
- columns
942
- .map((column) => {
943
- const cellAlign = column.align || allAlign
944
- const classNames = hasEllipsis(column, 'showOverflow', allColumnOverflow) ? ['col--ellipsis'] : []
945
- const cellValue = item[column.id]
946
- let rowSpan = 1
947
- let colSpan = 1
948
- if (isMerge) {
949
- const _rowIndex = $xeTable.getVTRowIndex(item._row)
950
- const _columnIndex = $xeTable.getVTColumnIndex(column)
951
- const spanRest = mergeBodyCellMaps[`${_rowIndex}:${_columnIndex}`]
952
- if (spanRest) {
953
- const { rowspan, colspan } = spanRest
954
- if (!rowspan || !colspan) {
955
- return ''
956
- }
957
- if (rowspan > 1) {
958
- rowSpan = rowspan
959
- }
960
- if (colspan > 1) {
961
- colSpan = colspan
962
- }
963
- }
964
- }
965
- if (cellAlign) {
966
- classNames.push(`col--${cellAlign}`)
967
- }
968
- if (column.type === 'radio') {
969
- return `<td class="${classNames.join(' ')}" rowspan="${rowSpan}" colspan="${colSpan}"><div style="${getCellWidthStyle(column)}"><input type="radio" name="radio_${id}" ${item._radioDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._radioLabel}</span></div></td>`
970
- } else if (column.type === 'checkbox') {
971
- return `<td class="${classNames.join(' ')}" rowspan="${rowSpan}" colspan="${colSpan}"><div style="${getCellWidthStyle(column)}"><input type="checkbox" ${item._checkboxDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._checkboxLabel}</span></div></td>`
972
- }
973
- return `<td class="${classNames.join(' ')}" rowspan="${rowSpan}" colspan="${colSpan}" title="${cellValue}"><div style="${getCellWidthStyle(column)}">${formatText(cellValue, true)}</div></td>`
974
- })
975
- .join('') +
976
- '</tr>'
977
- )
978
- })
979
- }
980
- tables.push('</tbody>')
981
- }
982
- if (isFooter) {
983
- const { footerTableData } = reactData
984
- const footers = getFooterData($xeTable, opts, footerTableData)
985
- if (footers.length) {
986
- tables.push('<tfoot>')
987
- footers.forEach((row, rIndex) => {
988
- tables.push(
989
- `<tr>${columns
990
- .map((column) => {
991
- const footAlign = column.footerAlign || column.align || allFooterAlign || allAlign
992
- const classNames = hasEllipsis(column, 'showOverflow', allColumnOverflow) ? ['col--ellipsis'] : []
993
- const cellValue = getFooterCellValue(opts, row, column)
994
- let rowSpan = 1
995
- let colSpan = 1
996
- if (isMerge) {
997
- const _rowIndex = rIndex
998
- const _columnIndex = $xeTable.getVTColumnIndex(column)
999
- const spanRest = mergeFooterCellMaps[`${_rowIndex}:${_columnIndex}`]
1000
- if (spanRest) {
1001
- const { rowspan, colspan } = spanRest
1002
- if (!rowspan || !colspan) {
1003
- return ''
1004
- }
1005
- if (rowspan > 1) {
1006
- rowSpan = rowspan
1007
- }
1008
- if (colspan > 1) {
1009
- colSpan = colspan
1010
- }
1011
- }
1012
- }
1013
- if (footAlign) {
1014
- classNames.push(`col--${footAlign}`)
1015
- }
1016
- return `<td class="${classNames.join(' ')}" rowspan="${rowSpan}" colspan="${colSpan}" title="${cellValue}"><div style="${getCellWidthStyle(column)}">${formatText(cellValue, true)}</div></td>`
1017
- })
1018
- .join('')}</tr>`
1019
- )
1020
- })
1021
- tables.push('</tfoot>')
1022
- }
1023
- }
1024
- // 是否半选状态
1025
- const script = !isAllSelected && isIndeterminate ? `<script>(function(){var a=document.querySelector(".${allCls}");if(a){a.indeterminate=true}})()</script>` : ''
1026
- tables.push('</table>', script)
1027
- return isPrint ? tables.join('') : createHtmlPage(opts, tables.join(''))
1028
- }
1029
-
1030
- const toXML = (opts: any, columns: any, datas: any) => {
1031
- let xml = [
1032
- '<?xml version="1.0"?>',
1033
- '<?mso-application progid="Excel.Sheet"?>',
1034
- '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">',
1035
- '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">',
1036
- '<Version>16.00</Version>',
1037
- '</DocumentProperties>',
1038
- '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">',
1039
- '<WindowHeight>7920</WindowHeight>',
1040
- '<WindowWidth>21570</WindowWidth>',
1041
- '<WindowTopX>32767</WindowTopX>',
1042
- '<WindowTopY>32767</WindowTopY>',
1043
- '<ProtectStructure>False</ProtectStructure>',
1044
- '<ProtectWindows>False</ProtectWindows>',
1045
- '</ExcelWorkbook>',
1046
- `<Worksheet ss:Name="${opts.sheetName}">`,
1047
- '<Table>',
1048
- columns.map((column: any) => `<Column ss:Width="${column.renderWidth}"/>`).join('')
1049
- ].join('')
1050
- if (opts.isHeader) {
1051
- xml += `<Row>${columns.map((column: any) => `<Cell><Data ss:Type="String">${getHeaderTitle(opts, column)}</Data></Cell>`).join('')}</Row>`
1052
- }
1053
- datas.forEach((row: any) => {
1054
- xml += '<Row>' + columns.map((column: any) => `<Cell><Data ss:Type="String">${row[column.id]}</Data></Cell>`).join('') + '</Row>'
1055
- })
1056
- if (opts.isFooter) {
1057
- const { footerTableData } = reactData
1058
- const footers = getFooterData($xeTable, opts, footerTableData)
1059
- footers.forEach((row: any) => {
1060
- xml += `<Row>${columns.map((column: any) => `<Cell><Data ss:Type="String">${getFooterCellValue(opts, row, column)}</Data></Cell>`).join('')}</Row>`
1061
- })
1062
- }
1063
- return `${xml}</Table></Worksheet></Workbook>`
1064
- }
1065
-
1066
- const getContent = ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, opts: VxeTablePropTypes.ExportHandleOptions, columns: VxeTableDefines.ColumnInfo[], datas: any[]) => {
1067
- if (columns.length) {
1068
- switch (opts.type) {
1069
- case 'csv':
1070
- return toCsv($xeTable, opts, columns, datas)
1071
- case 'txt':
1072
- return toTxt($xeTable, opts, columns, datas)
1073
- case 'html':
1074
- return toHtml(opts, columns, datas)
1075
- case 'xml':
1076
- return toXML(opts, columns, datas)
1077
- }
1078
- }
1079
- return ''
1080
- }
1081
-
1082
- const downloadFile = (opts: any, content: any) => {
1083
- const { filename, type, download } = opts
1084
- if (!download) {
1085
- const blob = getExportBlobByContent(content, opts)
1086
- return Promise.resolve({ type, content, blob })
1087
- }
1088
- if (VxeUI.saveFile) {
1089
- VxeUI.saveFile({ filename, type, content }).then(() => {
1090
- if (opts.message !== false) {
1091
- if (VxeUI.modal) {
1092
- VxeUI.modal.message({ content: getI18n('vxe.table.expSuccess'), status: 'success' })
1093
- }
1094
- }
1095
- })
1096
- }
1097
- }
1098
-
1099
- const handleExport = (opts: VxeTablePropTypes.ExportHandleOptions) => {
1100
- const $xeGrid = $xeTable.xeGrid
1101
- const $xeGantt = $xeTable.xeGantt
1102
-
1103
- const { remote, columns, colgroups, exportMethod, afterExportMethod } = opts
1104
- return new Promise((resolve) => {
1105
- if (remote) {
1106
- const params = { options: opts, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt }
1107
- resolve(exportMethod ? exportMethod(params) : params)
1108
- } else {
1109
- const datas = getExportData(opts)
1110
- resolve(
1111
- $xeTable.preventEvent(null, 'event.export', { options: opts, columns, colgroups, datas }, () => {
1112
- return downloadFile(opts, getContent($xeTable, opts, columns, datas))
1113
- })
1114
- )
1115
- }
1116
- })
1117
- .then((params: any) => {
1118
- clearColumnConvert(columns)
1119
- if (!opts.print) {
1120
- if (afterExportMethod) {
1121
- afterExportMethod({ status: true, options: opts, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt })
1122
- }
1123
- }
1124
- return Object.assign({ status: true }, params)
1125
- })
1126
- .catch(() => {
1127
- clearColumnConvert(columns)
1128
- if (!opts.print) {
1129
- if (afterExportMethod) {
1130
- afterExportMethod({ status: false, options: opts, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt })
1131
- }
1132
- }
1133
- const params = { status: false }
1134
- return Promise.reject(params)
1135
- })
1136
- }
1137
-
1138
- const handleImport = (content: any, opts: any) => {
1139
- const { tableFullColumn, _importResolve, _importReject } = internalData
1140
- let rest: {
1141
- fields: string[]
1142
- rows: any[]
1143
- } = { fields: [], rows: [] }
1144
- const tableFieldMaps: Record<string, VxeTableDefines.ColumnInfo> = {}
1145
- const tableTitleMaps: Record<string, VxeTableDefines.ColumnInfo> = {}
1146
- tableFullColumn.forEach((column) => {
1147
- const field = column.field
1148
- const title = $xeTable.getHeaderCellLabel(column)
1149
- if (field) {
1150
- tableFieldMaps[field] = column
1151
- }
1152
- if (title) {
1153
- tableTitleMaps[title] = column
1154
- }
1155
- })
1156
- const tableConf = {
1157
- fieldMaps: tableFieldMaps,
1158
- titleMaps: tableTitleMaps
1159
- }
1160
- switch (opts.type) {
1161
- case 'csv':
1162
- rest = parseCsv(tableConf, content)
1163
- break
1164
- case 'txt':
1165
- rest = parseTxt(tableConf, content)
1166
- break
1167
- case 'html':
1168
- rest = parseHTML(tableConf, content)
1169
- break
1170
- case 'xml':
1171
- rest = parseXML(tableConf, content)
1172
- break
1173
- }
1174
- const { fields, rows } = rest
1175
- const status = fields.some((field) => tableFieldMaps[field] || tableTitleMaps[field])
1176
- if (status) {
1177
- $xeTable.createData(rows).then((data: any) => {
1178
- let loadRest
1179
- if (opts.mode === 'insert' || opts.mode === 'insertBottom') {
1180
- loadRest = $xeTable.insertAt(data, -1)
1181
- } else if (opts.mode === 'insertTop') {
1182
- loadRest = $xeTable.insert(data)
1183
- } else {
1184
- loadRest = $xeTable.reloadData(data)
1185
- }
1186
- if (opts.message !== false) {
1187
- if (VxeUI.modal) {
1188
- VxeUI.modal.message({ content: getI18n('vxe.table.impSuccess', [rows.length]), status: 'success' })
1189
- }
1190
- }
1191
- return loadRest.then(() => {
1192
- if (_importResolve) {
1193
- _importResolve({ status: true })
1194
- }
1195
- })
1196
- })
1197
- } else if (opts.message !== false) {
1198
- if (VxeUI.modal) {
1199
- VxeUI.modal.message({ content: getI18n('vxe.error.impFields'), status: 'error' })
1200
- }
1201
- if (_importReject) {
1202
- _importReject({ status: false, msg: 'field mismatching' })
1203
- }
1204
- }
1205
- }
1206
-
1207
- const handleFileImport = (file: File, opts: any) => {
1208
- const { importMethod, afterImportMethod } = opts
1209
- const { type, filename } = parseFile(file)
1210
- const importOpts = computeImportOpts.value
1211
-
1212
- // 检查类型,如果为自定义导出,则不需要校验类型
1213
- if (!importMethod && !XEUtils.includes(XEUtils.keys(importOpts._typeMaps), type)) {
1214
- if (opts.message !== false) {
1215
- if (VxeUI.modal) {
1216
- VxeUI.modal.message({ content: getI18n('vxe.error.notType', [type]), status: 'error' })
1217
- }
1218
- }
1219
- const params = { status: false, msg: 'type error' }
1220
- return Promise.reject(params)
1221
- }
1222
-
1223
- const rest = new Promise((resolve, reject) => {
1224
- const _importResolve = (params?: any) => {
1225
- resolve(params)
1226
- internalData._importResolve = null
1227
- internalData._importReject = null
1228
- }
1229
- const _importReject = (params?: any) => {
1230
- reject(params)
1231
- internalData._importResolve = null
1232
- internalData._importReject = null
1233
- }
1234
- internalData._importResolve = _importResolve
1235
- internalData._importReject = _importReject
1236
- if (window.FileReader) {
1237
- const options = Object.assign({ mode: 'insertTop' }, opts, { type, filename })
1238
- if (options.remote) {
1239
- if (importMethod) {
1240
- Promise.resolve(importMethod({ file, options, $table: $xeTable }))
1241
- .then(() => {
1242
- _importResolve({ status: true })
1243
- })
1244
- .catch(() => {
1245
- _importResolve({ status: true })
1246
- })
1247
- } else {
1248
- _importResolve({ status: true })
1249
- }
1250
- } else {
1251
- const { tableFullColumn } = internalData
1252
- $xeTable.preventEvent(null, 'event.import', { file, options, columns: tableFullColumn }, () => {
1253
- const reader = new FileReader()
1254
- reader.onerror = () => {
1255
- errLog('vxe.error.notType', [type])
1256
- _importReject({ status: false, msg: 'reading file error' })
1257
- }
1258
- reader.onload = (e: any) => {
1259
- handleImport(e.target.result, options)
1260
- }
1261
- reader.readAsText(file, options.encoding || 'UTF-8')
1262
- })
1263
- }
1264
- } else {
1265
- // 不支持的浏览器
1266
- errLog('vxe.error.notExp')
1267
- _importResolve({ status: false, msg: 'unsupported browser' })
1268
- }
1269
- })
1270
-
1271
- return rest
1272
- .then(() => {
1273
- if (afterImportMethod) {
1274
- afterImportMethod({ status: true, options: opts, $table: $xeTable })
1275
- }
1276
- })
1277
- .catch((e) => {
1278
- if (afterImportMethod) {
1279
- afterImportMethod({ status: false, options: opts, $table: $xeTable })
1280
- }
1281
- return Promise.reject(e)
1282
- })
1283
- }
1284
-
1285
- const handleFilterColumns = (exportOpts: VxeTablePropTypes.ExportConfig, column: VxeTableDefines.ColumnInfo, columns: VxeTableDefines.ColumnInfo[] | VxeTablePropTypes.ExportOrPrintColumnOption[]) => {
1286
- return columns.some((item: any) => {
1287
- if (isColumnInfo(item)) {
1288
- return column.id === (item as any).id
1289
- } else if (XEUtils.isString(item)) {
1290
- return column.field === item
1291
- } else {
1292
- const colid = item.id || item.colId
1293
- const type = item.type
1294
- const field = item.field
1295
- if (colid) {
1296
- return column.id === colid
1297
- } else if (field && type) {
1298
- return column.field === field && column.type === type
1299
- } else if (field) {
1300
- return column.field === field
1301
- } else if (type) {
1302
- return column.type === type
1303
- }
1304
- }
1305
- return false
1306
- })
1307
- }
1308
-
1309
- const handleFilterFields = (exportOpts: VxeTablePropTypes.ExportConfig, column: VxeTableDefines.ColumnInfo, includeFields: string[] | undefined, includeFdMaps: Record<string, number>, excludeFdMaps: Record<string, number>, extraFdMaps: Record<string, number>) => {
1310
- const { field } = column
1311
- if (excludeFdMaps[field]) {
1312
- return false
1313
- }
1314
- if (includeFields) {
1315
- if (includeFdMaps[field]) {
1316
- return true
1317
- }
1318
- return false
1319
- }
1320
- if (extraFdMaps[field]) {
1321
- return true
1322
- }
1323
- return exportOpts.original ? !!field : defaultFilterExportColumn(column)
1324
- }
1325
-
1326
- const handleExportAndPrint = (options: VxeTablePropTypes.ExportOpts | VxeTablePropTypes.ExportConfig, isPrint?: boolean) => {
1327
- const $xeGrid = $xeTable.xeGrid
1328
- const $xeGantt = $xeTable.xeGantt
1329
- const $xeGGWrapper = $xeGrid || $xeGantt
1330
-
1331
- const { treeConfig, showHeader, showFooter } = props
1332
- const { initStore, isGroup, rowGroupList, footerTableData, exportStore, exportParams } = reactData
1333
- const { collectColumn, mergeBodyList, mergeFooterList } = internalData
1334
- const exportOpts = computeExportOpts.value
1335
- const printOpts = computePrintOpts.value
1336
- const hasTree = !!treeConfig
1337
- const hasRowGroup = rowGroupList.length > 0
1338
- const selectRecords = $xeTable.getCheckboxRecords()
1339
- const proxyOpts = $xeGGWrapper ? $xeGGWrapper.getComputeMaps().computeProxyOpts.value : ({} as VxeGridPropTypes.ProxyOpts)
1340
- const hasFooter = !!footerTableData.length
1341
- const hasMerge = !!(mergeBodyList.length || mergeFooterList.length)
1342
- const defOpts = Object.assign(
1343
- {
1344
- message: true,
1345
- isHeader: showHeader,
1346
- isTitle: showHeader,
1347
- isFooter: showFooter,
1348
- isColgroup: isGroup,
1349
- isMerge: hasMerge,
1350
- useStyle: true,
1351
- current: 'current',
1352
- modes: (proxyOpts.ajax && proxyOpts.ajax.queryAll ? ['all'] : []).concat(['current', 'selected', 'empty'])
1353
- },
1354
- options
1355
- )
1356
-
1357
- // 已废弃,参数 isAllExpand
1358
- if (XEUtils.isBoolean((defOpts as any).isAllExpand)) {
1359
- warnLog('vxe.error.delProp', ['isAllExpand', 'isTreeAllExpanded'])
1360
- defOpts.isTreeAllExpanded = (defOpts as any).isAllExpand
1361
- }
1362
-
1363
- const types: string[] = isPrint ? [] : defOpts.types || XEUtils.keys(exportOpts._typeMaps)
1364
- const modes: string[] = defOpts.modes || []
1365
- const checkMethod = (isPrint ? printOpts : exportOpts).checkMethod
1366
- const exportColumns = collectColumn.slice(0)
1367
- const { columns, excludeFields, includeFields, extraFields } = defOpts
1368
- // 处理类型
1369
- const typeList = types.map((value) => {
1370
- return {
1371
- value,
1372
- label: getI18n(`vxe.export.types.${value}`)
1373
- }
1374
- })
1375
- const modeList = modes.map((item: any) => {
1376
- if (item && item.value) {
1377
- return {
1378
- value: item.value,
1379
- label: item.label || item.value
1380
- }
1381
- }
1382
- return {
1383
- value: item,
1384
- label: getI18n(`vxe.export.modes.${item}`)
1385
- }
1386
- })
1387
-
1388
- const excludeFdMaps: Record<string, number> = {}
1389
- if (excludeFields && excludeFields.length) {
1390
- excludeFields.forEach((field) => {
1391
- excludeFdMaps[field] = 1
1392
- })
1393
- }
1394
- const includeFdMaps: Record<string, number> = {}
1395
- if (includeFields && includeFields.length) {
1396
- includeFields.forEach((field) => {
1397
- includeFdMaps[field] = 1
1398
- })
1399
- }
1400
- const extraFdMaps: Record<string, number> = {}
1401
- if (extraFields) {
1402
- extraFields.forEach((field) => {
1403
- extraFdMaps[field] = 1
1404
- })
1405
- }
1406
-
1407
- // 默认选中
1408
- // 优先级 columns > excludeFields > (includeFields || extraFields)
1409
- XEUtils.eachTree(exportColumns, (column, index, items, path, parentColumn) => {
1410
- const isColGroup = column.children && column.children.length > 0
1411
- let isChecked = false
1412
- const isExtraChecked = extraFdMaps[column.field]
1413
- if (columns) {
1414
- isChecked = handleFilterColumns(defOpts, column, columns)
1415
- } else if (excludeFields || includeFields) {
1416
- isChecked = handleFilterFields(defOpts, column, includeFields, includeFdMaps, excludeFdMaps, extraFdMaps)
1417
- } else {
1418
- if (isExtraChecked) {
1419
- isChecked = true
1420
- } else {
1421
- isChecked = column.visible && (isColGroup || defaultFilterExportColumn(column))
1422
- }
1423
- }
1424
- column.checked = isChecked
1425
- column.halfChecked = false
1426
- column.disabled = (parentColumn && parentColumn.disabled) || (checkMethod ? !checkMethod({ $table: $xeTable, column }) : false)
1427
- })
1428
- // 更新条件
1429
- exportStore.columns = exportColumns
1430
- exportStore.typeList = typeList
1431
- exportStore.modeList = modeList
1432
- exportStore.hasFooter = hasFooter
1433
- exportStore.hasMerge = hasMerge
1434
- exportStore.hasTree = hasTree
1435
- exportStore.hasRowGroup = hasRowGroup
1436
- exportStore.isPrint = !!isPrint
1437
- exportStore.hasColgroup = isGroup
1438
- exportStore.visible = true
1439
- // 默认参数
1440
- Object.assign(
1441
- exportParams,
1442
- {
1443
- mode: selectRecords.length ? 'selected' : 'current'
1444
- },
1445
- defOpts
1446
- )
1447
- const { filename, sheetName, mode, type } = exportParams
1448
- if (filename) {
1449
- if (XEUtils.isFunction(filename)) {
1450
- exportParams.filename = filename({
1451
- options: defOpts,
1452
- $table: $xeTable,
1453
- $grid: $xeGrid,
1454
- $gantt: $xeGantt
1455
- })
1456
- } else {
1457
- exportParams.filename = `${filename}`
1458
- }
1459
- }
1460
- if (sheetName) {
1461
- if (XEUtils.isFunction(sheetName)) {
1462
- exportParams.sheetName = sheetName({
1463
- options: defOpts,
1464
- $table: $xeTable,
1465
- $grid: $xeGrid,
1466
- $gantt: $xeGantt
1467
- })
1468
- } else {
1469
- exportParams.sheetName = `${sheetName}`
1470
- }
1471
- }
1472
- if (!modeList.some((item) => item.value === mode)) {
1473
- exportParams.mode = modeList.length ? modeList[0].value : ''
1474
- }
1475
- if (!typeList.some((item) => item.value === type)) {
1476
- exportParams.type = typeList.length ? typeList[0].value : ''
1477
- }
1478
- if (!exportParams.widthMode) {
1479
- exportParams.widthMode = ''
1480
- }
1481
- initStore.export = true
1482
- return nextTick()
1483
- }
1484
-
1485
- const handleCloseExport = () => {
1486
- if (VxeUI.modal) {
1487
- return VxeUI.modal.close('VXE_EXPORT_MODAL')
1488
- }
1489
- return Promise.resolve()
1490
- }
1491
-
1492
- const exportMethods: TableExportMethods = {
1493
- /**
1494
- * 导出文件,支持 csv/html/xml/txt
1495
- * 如果是树表格,则默认是导出所有节点
1496
- * 如果是启用了虚拟滚动,则只能导出数据源,可以配合 dataFilterMethod 函数转换数据
1497
- * @param {Object} options 参数
1498
- */
1499
- exportData(options) {
1500
- const $xeGrid = $xeTable.xeGrid
1501
- const $xeGantt = $xeTable.xeGantt
1502
- const $xeGGWrapper = $xeGrid || $xeGantt
1503
-
1504
- const { treeConfig, showHeader, showFooter } = props
1505
- const { isGroup } = reactData
1506
- const { tableFullColumn, afterFullData, afterTreeFullData, collectColumn, mergeBodyList, mergeFooterList } = internalData
1507
- const exportOpts = computeExportOpts.value
1508
- const treeOpts = computeTreeOpts.value
1509
- const proxyOpts = $xeGGWrapper ? $xeGGWrapper.getComputeMaps().computeProxyOpts.value : ({} as VxeGridPropTypes.ProxyOpts)
1510
- const hasMerge = !!(mergeBodyList.length || mergeFooterList.length)
1511
- const opts = Object.assign(
1512
- {
1513
- message: true,
1514
- isHeader: showHeader,
1515
- isTitle: showHeader,
1516
- isFooter: showFooter,
1517
- isColgroup: isGroup,
1518
- isMerge: hasMerge,
1519
- useStyle: true,
1520
- current: 'current',
1521
- modes: (proxyOpts.ajax && proxyOpts.ajax.queryAll ? ['all'] : []).concat(['current', 'selected', 'empty']),
1522
- download: true,
1523
- type: 'csv'
1524
- // filename: '',
1525
- // sheetName: '',
1526
- // original: false,
1527
- // isTreeAllExpanded: false,
1528
- // isRowGroupAllExpanded: false,
1529
- // data: null,
1530
- // remote: false,
1531
- // dataFilterMethod: null,
1532
- // footerFilterMethod: null,
1533
- // exportMethod: null,
1534
- // columnFilterMethod: null,
1535
- // beforeExportMethod: null,
1536
- // afterExportMethod: null
1537
- },
1538
- exportOpts,
1539
- options
1540
- )
1541
-
1542
- // 已废弃,参数 isAllExpand
1543
- if (XEUtils.isBoolean((opts as any).isAllExpand)) {
1544
- warnLog('vxe.error.delProp', ['isAllExpand', 'isTreeAllExpanded'])
1545
- opts.isTreeAllExpanded = (opts as any).isAllExpand
1546
- }
1547
-
1548
- let { filename, sheetName, type, mode, columns, columnFilterMethod, beforeExportMethod, includeFields, excludeFields, extraFields } = opts
1549
- let groups: any[] = []
1550
- const selectRecords = $xeTable.getCheckboxRecords()
1551
- if (!mode) {
1552
- mode = selectRecords.length ? 'selected' : 'current'
1553
- }
1554
-
1555
- const excludeFdMaps: Record<string, number> = {}
1556
- if (excludeFields && excludeFields.length) {
1557
- excludeFields.forEach((field) => {
1558
- excludeFdMaps[field] = 1
1559
- })
1560
- }
1561
- const includeFdMaps: Record<string, number> = {}
1562
- if (includeFields && includeFields.length) {
1563
- includeFields.forEach((field) => {
1564
- includeFdMaps[field] = 1
1565
- })
1566
- }
1567
- const extraFdMaps: Record<string, number> = {}
1568
- if (extraFields) {
1569
- extraFields.forEach((field) => {
1570
- extraFdMaps[field] = 1
1571
- })
1572
- }
1573
-
1574
- let isCustomCol = false
1575
- let customCols = []
1576
- const _columns = (opts as any)._columns
1577
- if (_columns) {
1578
- // 内部导出使用 _columns -> _children 为自定义子集
1579
- isCustomCol = true
1580
- customCols = XEUtils.searchTree(_columns, () => true, { children: '_children', mapChildren: 'childNodes', original: true })
1581
- } else if (columns) {
1582
- isCustomCol = true
1583
- customCols = XEUtils.searchTree(columns, () => true, { children: 'children', mapChildren: 'childNodes', original: true })
1584
- } else {
1585
- customCols = XEUtils.searchTree(
1586
- collectColumn,
1587
- (column) => {
1588
- const isColGroup = column.children && column.children.length > 0
1589
- let isChecked = false
1590
- const isExtraChecked = extraFdMaps[column.field]
1591
- if (columns) {
1592
- isChecked = handleFilterColumns(opts, column, columns)
1593
- } else if (excludeFields || includeFields) {
1594
- isChecked = handleFilterFields(opts, column, includeFields, includeFdMaps, excludeFdMaps, extraFdMaps)
1595
- } else {
1596
- if (isExtraChecked) {
1597
- isChecked = true
1598
- } else {
1599
- isChecked = column.visible && (isColGroup || defaultFilterExportColumn(column))
1600
- }
1601
- }
1602
- return isChecked
1603
- },
1604
- { children: 'children', mapChildren: 'childNodes', original: true }
1605
- )
1606
- }
1607
- const handleOptions: VxeTablePropTypes.ExportHandleOptions = Object.assign({} as { data: any[]; colgroups: any[]; columns: any[] }, opts, { filename: '', sheetName: '', _columnConfs: columns })
1608
- // 如果设置源数据,则默认导出设置了字段的列
1609
- if (!isCustomCol && !columnFilterMethod) {
1610
- columnFilterMethod = ({ column }) => handleFilterFields(handleOptions, column, includeFields, includeFdMaps, excludeFdMaps, extraFdMaps)
1611
- handleOptions.columnFilterMethod = columnFilterMethod
1612
- }
1613
- if (customCols) {
1614
- handleOptions._isCustomColumn = true
1615
- groups = XEUtils.searchTree(
1616
- XEUtils.mapTree(
1617
- customCols,
1618
- (item) => {
1619
- let targetColumn
1620
- if (item) {
1621
- if (isColumnInfo(item)) {
1622
- targetColumn = item
1623
- } else if (XEUtils.isString(item)) {
1624
- targetColumn = $xeTable.getColumnByField(item)
1625
- } else {
1626
- const colid = item.id || item.colId
1627
- const type = item.type
1628
- const field = item.field
1629
- if (colid) {
1630
- targetColumn = $xeTable.getColumnById(colid)
1631
- } else if (field && type) {
1632
- targetColumn = tableFullColumn.find((column) => column.field === field && column.type === type)
1633
- } else if (field) {
1634
- targetColumn = $xeTable.getColumnByField(field)
1635
- } else if (type) {
1636
- targetColumn = tableFullColumn.find((column) => column.type === type)
1637
- }
1638
- }
1639
- return targetColumn || {}
1640
- }
1641
- },
1642
- {
1643
- children: 'childNodes',
1644
- mapChildren: '_children'
1645
- }
1646
- ),
1647
- (column, index) => isColumnInfo(column) && (!columnFilterMethod || columnFilterMethod({ $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt, column: column as any, $columnIndex: index })),
1648
- {
1649
- children: '_children',
1650
- mapChildren: 'childNodes',
1651
- original: true
1652
- }
1653
- )
1654
- } else {
1655
- groups = XEUtils.searchTree(isGroup ? collectColumn : tableFullColumn, (column, index) => column.visible && (!columnFilterMethod || columnFilterMethod({ $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt, column, $columnIndex: index })), {
1656
- children: 'children',
1657
- mapChildren: 'childNodes',
1658
- original: true
1659
- })
1660
- }
1661
- // 获取所有列
1662
- const cols: VxeTableDefines.ColumnInfo[] = []
1663
- XEUtils.eachTree(
1664
- groups,
1665
- (column) => {
1666
- const isColGroup = column.children && column.children.length
1667
- if (!isColGroup) {
1668
- cols.push(column)
1669
- }
1670
- },
1671
- { children: 'childNodes' }
1672
- )
1673
- // 构建分组层级
1674
- handleOptions.columns = cols
1675
- handleOptions.colgroups = convertToRows(groups)
1676
- if (filename) {
1677
- if (XEUtils.isFunction(filename)) {
1678
- handleOptions.filename = filename({
1679
- options: opts,
1680
- $table: $xeTable,
1681
- $grid: $xeGrid,
1682
- $gantt: $xeGantt
1683
- })
1684
- } else {
1685
- handleOptions.filename = `${filename}`
1686
- }
1687
- }
1688
- if (!handleOptions.filename) {
1689
- handleOptions.filename = getI18n(handleOptions.original ? 'vxe.table.expOriginFilename' : 'vxe.table.expFilename', [XEUtils.toDateString(Date.now(), 'yyyyMMddHHmmss')])
1690
- }
1691
-
1692
- if (sheetName) {
1693
- if (XEUtils.isFunction(sheetName)) {
1694
- handleOptions.sheetName = sheetName({
1695
- options: opts,
1696
- $table: $xeTable,
1697
- $grid: $xeGrid,
1698
- $gantt: $xeGantt
1699
- })
1700
- } else {
1701
- handleOptions.sheetName = `${sheetName}`
1702
- }
1703
- }
1704
- if (!handleOptions.sheetName) {
1705
- handleOptions.sheetName = document.title || ''
1706
- }
1707
-
1708
- // 检查类型,如果为自定义导出,则不需要校验类型
1709
- if (!handleOptions.exportMethod && !XEUtils.includes(XEUtils.keys(exportOpts._typeMaps), type)) {
1710
- errLog('vxe.error.notType', [type])
1711
- if (['xlsx', 'pdf'].includes(type)) {
1712
- warnLog('vxe.error.reqPlugin', [4, 'plugin-export-xlsx'])
1713
- }
1714
- const params = { status: false, msg: 'type error' }
1715
- return Promise.reject(params)
1716
- }
1717
-
1718
- if (!handleOptions.print) {
1719
- if (beforeExportMethod) {
1720
- const beRest = beforeExportMethod({ options: handleOptions, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt })
1721
- if (XEUtils.isBoolean(beRest)) {
1722
- if (!beRest) {
1723
- const params = { status: false, msg: 'before prevent' }
1724
- return Promise.reject(params)
1725
- }
1726
- } else {
1727
- warnLog('vxe.error.returnErr', ['beforeExportMethod', 'boolean', beRest])
1728
- }
1729
- }
1730
- }
1731
- if (!handleOptions.data) {
1732
- handleOptions.data = []
1733
- if (mode === 'selected') {
1734
- if (['html', 'pdf'].indexOf(type) > -1 && treeConfig) {
1735
- handleOptions.data = XEUtils.searchTree($xeTable.getTableData().fullData, (item) => $xeTable.findRowIndexOf(selectRecords, item) > -1, Object.assign({}, treeOpts, { data: '_row' }))
1736
- } else {
1737
- handleOptions.data = selectRecords
1738
- }
1739
- } else if (mode === 'all') {
1740
- if (!$xeGGWrapper) {
1741
- errLog('vxe.error.errProp', ['all', 'mode=current,selected'])
1742
- }
1743
-
1744
- if ($xeGGWrapper && !handleOptions.remote) {
1745
- const gridReactData = $xeGGWrapper.reactData
1746
- const { computeProxyOpts } = $xeGGWrapper.getComputeMaps()
1747
- const proxyOpts = computeProxyOpts.value
1748
- const { sortData } = gridReactData
1749
- const { beforeQueryAll: oldBeforeQueryAll, afterQueryAll: oldAfterQueryAll, ajax = {} } = proxyOpts
1750
- const resConfigs = proxyOpts.response || proxyOpts.props || {}
1751
- const beforeQueryAllMethod = ajax.beforeQueryAll
1752
- const queryAllMethod = ajax.queryAll
1753
- const afterQueryAllMethod = ajax.afterQueryAll
1754
- const queryAllSuccessMethod = ajax.queryAllSuccess
1755
- const queryAllErrorMethod = ajax.queryAllError
1756
-
1757
- if (!queryAllMethod) {
1758
- errLog('vxe.error.notFunc', ['proxy-config.ajax.queryAll'])
1759
- }
1760
-
1761
- if (queryAllMethod) {
1762
- const params = {
1763
- $table: $xeTable,
1764
- $grid: $xeGrid,
1765
- $gantt: $xeGantt,
1766
- sort: sortData.length ? sortData[0] : ({} as any),
1767
- sorts: sortData as any[],
1768
- filters: gridReactData.filterData,
1769
- form: gridReactData.formData,
1770
- options: handleOptions
1771
- }
1772
-
1773
- const handleQueryAll = () => {
1774
- return Promise.resolve((oldBeforeQueryAll || queryAllMethod)(params))
1775
- .then((rest) => {
1776
- if (afterQueryAllMethod) {
1777
- afterQueryAllMethod({ ...params, response: rest, status: 'success' })
1778
- } else {
1779
- const listProp = resConfigs.list
1780
- let tdData: any[] = []
1781
- if (listProp) {
1782
- if (XEUtils.isFunction(listProp)) {
1783
- tdData = listProp({ data: rest, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt })
1784
- } else {
1785
- tdData = XEUtils.isArray(rest) ? rest : XEUtils.get(rest, listProp)
1786
- }
1787
- } else {
1788
- if (XEUtils.isArray(rest)) {
1789
- tdData = rest
1790
- }
1791
- }
1792
- handleOptions.data = tdData
1793
- if (oldAfterQueryAll) {
1794
- oldAfterQueryAll({ ...params, response: rest })
1795
- }
1796
- }
1797
- if (queryAllSuccessMethod) {
1798
- queryAllSuccessMethod({ ...params, response: rest })
1799
- }
1800
- return handleExport(handleOptions)
1801
- })
1802
- .catch((rest) => {
1803
- if (afterQueryAllMethod) {
1804
- afterQueryAllMethod({ ...params, response: rest, status: 'error' })
1805
- }
1806
- if (queryAllErrorMethod) {
1807
- queryAllErrorMethod({ ...params, response: rest })
1808
- }
1809
- })
1810
- }
1811
-
1812
- if (beforeQueryAllMethod) {
1813
- return Promise.resolve(beforeQueryAllMethod(params)).then((status) => {
1814
- if (status !== false) {
1815
- return handleQueryAll()
1816
- }
1817
- })
1818
- }
1819
- return handleQueryAll()
1820
- }
1821
- }
1822
- }
1823
- if (mode === 'current') {
1824
- handleOptions.data = treeConfig ? afterTreeFullData : afterFullData
1825
- }
1826
- } else {
1827
- handleOptions._isCustomData = true
1828
- }
1829
- return handleExport(handleOptions)
1830
- },
1831
- importByFile(file, options) {
1832
- const opts = Object.assign({}, options)
1833
- const { beforeImportMethod } = opts
1834
- if (beforeImportMethod) {
1835
- const biRest = beforeImportMethod({ options: opts, $table: $xeTable })
1836
- if (XEUtils.isBoolean(biRest)) {
1837
- if (!biRest) {
1838
- const params = { status: false, mas: 'before prevent' }
1839
- return Promise.reject(params)
1840
- }
1841
- } else {
1842
- warnLog('vxe.error.returnErr', ['beforeImportMethod', 'boolean', biRest])
1843
- }
1844
- }
1845
- return handleFileImport(file, opts)
1846
- },
1847
- importData(options) {
1848
- const importOpts = computeImportOpts.value
1849
- const opts = Object.assign(
1850
- {
1851
- types: XEUtils.keys(importOpts._typeMaps)
1852
- // beforeImportMethod: null,
1853
- // afterImportMethod: null
1854
- },
1855
- importOpts,
1856
- options
1857
- )
1858
- const { beforeImportMethod, afterImportMethod } = opts
1859
- if (beforeImportMethod) {
1860
- const biRest = beforeImportMethod({ options: opts, $table: $xeTable })
1861
- if (XEUtils.isBoolean(biRest)) {
1862
- if (!biRest) {
1863
- const params = { status: false, mas: 'before prevent' }
1864
- return Promise.reject(params)
1865
- }
1866
- } else {
1867
- warnLog('vxe.error.returnErr', ['beforeImportMethod', 'boolean', biRest])
1868
- }
1869
- }
1870
- return VxeUI.readFile(opts)
1871
- .catch((e) => {
1872
- if (afterImportMethod) {
1873
- afterImportMethod({ status: false, options: opts, $table: $xeTable })
1874
- }
1875
- return Promise.reject(e)
1876
- })
1877
- .then((params) => {
1878
- const { file } = params
1879
- return handleFileImport(file, opts)
1880
- })
1881
- },
1882
- saveFile(options) {
1883
- return VxeUI.saveFile(options)
1884
- },
1885
- readFile(options) {
1886
- return VxeUI.readFile(options)
1887
- },
1888
- print(options) {
1889
- const $xeGrid = $xeTable.xeGrid
1890
- const $xeGantt = $xeTable.xeGantt
1891
-
1892
- const printOpts = computePrintOpts.value
1893
- const opts = Object.assign(
1894
- {
1895
- original: false
1896
- // beforePrintMethod
1897
- },
1898
- printOpts,
1899
- options,
1900
- {
1901
- type: 'html',
1902
- download: false,
1903
- remote: false,
1904
- print: true
1905
- }
1906
- )
1907
- const { sheetName } = opts
1908
- let printTitle = ''
1909
- if (sheetName) {
1910
- if (XEUtils.isFunction(sheetName)) {
1911
- printTitle = sheetName({
1912
- options: opts,
1913
- $table: $xeTable,
1914
- $grid: $xeGrid,
1915
- $gantt: $xeGantt
1916
- })
1917
- } else {
1918
- printTitle = `${sheetName}`
1919
- }
1920
- }
1921
- if (!printTitle) {
1922
- printTitle = document.title || ''
1923
- }
1924
-
1925
- const beforePrintMethod = opts.beforePrintMethod
1926
- const printMethod = opts.printMethod
1927
- const tableHtml = opts.html || opts.content
1928
- return new Promise((resolve, reject) => {
1929
- if (VxeUI.print) {
1930
- if (tableHtml) {
1931
- resolve(
1932
- VxeUI.print({
1933
- title: printTitle,
1934
- html: tableHtml,
1935
- customStyle: opts.style,
1936
- beforeMethod: beforePrintMethod
1937
- ? ({ html }) => {
1938
- return beforePrintMethod({
1939
- html,
1940
- content: html,
1941
- options: opts,
1942
- $table: $xeTable,
1943
- $grid: $xeGrid,
1944
- $gantt: $xeGantt
1945
- })
1946
- }
1947
- : undefined,
1948
- beforePrintMethod: beforePrintMethod
1949
- ? ({ html }) => {
1950
- return beforePrintMethod({
1951
- html,
1952
- content: html,
1953
- options: opts,
1954
- $table: $xeTable,
1955
- $grid: $xeGrid,
1956
- $gantt: $xeGantt
1957
- })
1958
- }
1959
- : undefined,
1960
- printMethod: printMethod
1961
- ? ({ html }) => {
1962
- return printMethod({
1963
- html,
1964
- content: html,
1965
- options: opts,
1966
- $table: $xeTable,
1967
- $grid: $xeGrid,
1968
- $gantt: $xeGantt
1969
- })
1970
- }
1971
- : undefined
1972
- })
1973
- )
1974
- } else {
1975
- resolve(
1976
- exportMethods.exportData(opts).then(({ content }: any) => {
1977
- return VxeUI.print({
1978
- title: printTitle,
1979
- html: content,
1980
- customStyle: opts.style,
1981
- beforeMethod: beforePrintMethod
1982
- ? ({ html }) => {
1983
- return beforePrintMethod({
1984
- html,
1985
- content: html,
1986
- options: opts,
1987
- $table: $xeTable,
1988
- $grid: $xeGrid,
1989
- $gantt: $xeGantt
1990
- })
1991
- }
1992
- : undefined,
1993
- beforePrintMethod: beforePrintMethod
1994
- ? ({ html }) => {
1995
- return beforePrintMethod({
1996
- html,
1997
- content: html,
1998
- options: opts,
1999
- $table: $xeTable,
2000
- $grid: $xeGrid,
2001
- $gantt: $xeGantt
2002
- })
2003
- }
2004
- : undefined,
2005
- printMethod: printMethod
2006
- ? ({ html }) => {
2007
- return printMethod({
2008
- html,
2009
- content: html,
2010
- options: opts,
2011
- $table: $xeTable,
2012
- $grid: $xeGrid,
2013
- $gantt: $xeGantt
2014
- })
2015
- }
2016
- : undefined
2017
- })
2018
- })
2019
- )
2020
- }
2021
- } else {
2022
- errLog('vxe.error.reqComp', ['vxe-print'])
2023
- const e = { status: false, msg: 'print not exist' }
2024
- reject(e)
2025
- }
2026
- })
2027
- },
2028
- getPrintHtml(options) {
2029
- const printOpts = computePrintOpts.value
2030
- const opts = Object.assign(
2031
- {
2032
- original: false
2033
- // beforePrintMethod
2034
- },
2035
- printOpts,
2036
- options,
2037
- {
2038
- type: 'html',
2039
- download: false,
2040
- remote: false,
2041
- print: true
2042
- }
2043
- )
2044
- return $xeTable.exportData(opts).then(({ content }) => {
2045
- return {
2046
- html: content
2047
- }
2048
- })
2049
- },
2050
- closeImport() {
2051
- if (VxeUI.modal) {
2052
- return VxeUI.modal.close('VXE_IMPORT_MODAL')
2053
- }
2054
- return Promise.resolve()
2055
- },
2056
- openImport(options) {
2057
- const { treeConfig, importConfig } = props
2058
- const { initStore, importStore, importParams } = reactData
2059
- const importOpts = computeImportOpts.value
2060
- const defOpts = Object.assign(
2061
- {
2062
- mode: 'insertTop',
2063
- message: true,
2064
- types: XEUtils.keys(importOpts._typeMaps),
2065
- modes: ['insertTop', 'covering']
2066
- },
2067
- importOpts,
2068
- options
2069
- )
2070
- const types = defOpts.types || []
2071
- const modes = defOpts.modes || []
2072
- const isTree = !!treeConfig
2073
- if (isTree) {
2074
- if (defOpts.message) {
2075
- if (VxeUI.modal) {
2076
- VxeUI.modal.message({ content: getI18n('vxe.error.treeNotImp'), status: 'error' })
2077
- }
2078
- }
2079
- return
2080
- }
2081
- if (!hasEnableConf(importConfig, importOpts)) {
2082
- errLog('vxe.error.reqProp', ['import-config'])
2083
- }
2084
- // 处理类型
2085
- const typeList = types.map((value) => {
2086
- return {
2087
- value,
2088
- label: getI18n(`vxe.export.types.${value}`)
2089
- }
2090
- })
2091
- const modeList = modes.map((item: any) => {
2092
- if (item && item.value) {
2093
- return {
2094
- value: item.value,
2095
- label: item.label || item.value
2096
- }
2097
- }
2098
- return {
2099
- value: item,
2100
- label: getI18n(`vxe.import.modes.${item}`)
2101
- }
2102
- })
2103
- Object.assign(importStore, {
2104
- file: null,
2105
- type: '',
2106
- filename: '',
2107
- modeList,
2108
- typeList,
2109
- visible: true
2110
- })
2111
- Object.assign(importParams, defOpts)
2112
- if (!modeList.some((item) => item.value === importParams.mode)) {
2113
- importParams.mode = modeList[0].value
2114
- }
2115
- initStore.import = true
2116
- },
2117
- closeExport: handleCloseExport,
2118
- openExport(options) {
2119
- const { exportConfig } = props
2120
- const exportOpts = computeExportOpts.value
2121
- const defOpts = Object.assign(
2122
- {
2123
- message: true,
2124
- types: XEUtils.keys(exportOpts._typeMaps)
2125
- },
2126
- exportOpts,
2127
- options
2128
- )
2129
- if (!hasEnableConf(exportConfig, exportOpts)) {
2130
- errLog('vxe.error.reqProp', ['export-config'])
2131
- }
2132
- return handleExportAndPrint(defOpts)
2133
- },
2134
- closePrint: handleCloseExport,
2135
- openPrint(options) {
2136
- const { printConfig } = props
2137
- const printOpts = computePrintOpts.value
2138
- const defOpts = Object.assign(
2139
- {
2140
- message: true
2141
- },
2142
- printOpts,
2143
- options
2144
- )
2145
- if (!hasEnableConf(printConfig, printOpts)) {
2146
- errLog('vxe.error.reqProp', ['print-config'])
2147
- }
2148
- return handleExportAndPrint(defOpts, true)
2149
- }
2150
- }
2151
-
2152
- return exportMethods
2153
- },
2154
- setupGrid($xeGrid) {
2155
- return $xeGrid.extendTableMethods(tableExportMethodKeys)
2156
- },
2157
- setupGantt($xeGantt) {
2158
- return $xeGantt.extendTableMethods(tableExportMethodKeys)
2159
- }
2160
- })
1
+ import { nextTick } from 'vue'
2
+ import XEUtils from 'xe-utils'
3
+ import { VxeUI } from '@vxe-ui/core'
4
+ import { isColumnInfo, getCellValue, createHandleGetRowId } from '../../src/util'
5
+ import { parseFile, formatText, eqEmptyValue, hasEnableConf } from '../../../ui/src/utils'
6
+ import { hasClass, toCssUnit } from '../../../ui/src/dom'
7
+ import { createHtmlPage, getExportBlobByContent } from './util'
8
+ import { createComponentLog } from '../../../ui/src/log'
9
+
10
+ import type { VxeTablePropTypes, VxeColumnPropTypes, TableExportMethods, VxeGridPropTypes, VxeTableDefines, VxeTableConstructor, VxeTablePrivateMethods } from '../../../../types'
11
+
12
+ const { warnLog, errLog } = createComponentLog('table')
13
+
14
+ const { getI18n, hooks, renderer } = VxeUI
15
+
16
+ let htmlCellElem: any
17
+
18
+ const csvBOM = '\ufeff'
19
+ const enterSymbol = '\r\n'
20
+
21
+ function defaultFilterExportColumn(column: VxeTableDefines.ColumnInfo) {
22
+ return !!column.field || ['seq', 'checkbox', 'radio'].indexOf(column.type || '') === -1
23
+ }
24
+
25
+ const getConvertColumns = (columns: any) => {
26
+ const result: any = []
27
+ columns.forEach((column: any) => {
28
+ if (column.childNodes && column.childNodes.length) {
29
+ result.push(column)
30
+ result.push(...getConvertColumns(column.childNodes))
31
+ } else {
32
+ result.push(column)
33
+ }
34
+ })
35
+ return result
36
+ }
37
+
38
+ const convertToRows = (originColumns: any): any[][] => {
39
+ let maxLevel = 1
40
+ const traverse = (column: any, parent?: any) => {
41
+ if (parent) {
42
+ column._level = parent._level + 1
43
+ if (maxLevel < column._level) {
44
+ maxLevel = column._level
45
+ }
46
+ }
47
+ if (column.childNodes && column.childNodes.length) {
48
+ let colSpan = 0
49
+ column.childNodes.forEach((subColumn: any) => {
50
+ traverse(subColumn, column)
51
+ colSpan += subColumn._colSpan
52
+ })
53
+ column._colSpan = colSpan
54
+ } else {
55
+ column._colSpan = 1
56
+ }
57
+ }
58
+
59
+ originColumns.forEach((column: any) => {
60
+ column._level = 1
61
+ traverse(column)
62
+ })
63
+
64
+ const rows: any = []
65
+ for (let i = 0; i < maxLevel; i++) {
66
+ rows.push([])
67
+ }
68
+
69
+ const allColumns = getConvertColumns(originColumns)
70
+
71
+ allColumns.forEach((column: any) => {
72
+ if (column.childNodes && column.childNodes.length) {
73
+ column._rowSpan = 1
74
+ } else {
75
+ column._rowSpan = maxLevel - column._level + 1
76
+ }
77
+ rows[column._level - 1].push(column)
78
+ })
79
+
80
+ return rows
81
+ }
82
+
83
+ function toTableBorder(border: VxeTablePropTypes.Border | undefined) {
84
+ if (border === true) {
85
+ return 'full'
86
+ }
87
+ if (border) {
88
+ return border
89
+ }
90
+ return 'default'
91
+ }
92
+
93
+ function getBooleanValue(cellValue: any) {
94
+ return cellValue === 'TRUE' || cellValue === 'true' || cellValue === true
95
+ }
96
+
97
+ function getFooterData($xeTable: VxeTableConstructor & VxeTablePrivateMethods, opts: VxeTablePropTypes.ExportHandleOptions, footerTableData: any[]) {
98
+ const $xeGrid = $xeTable.xeGrid
99
+ const $xeGantt = $xeTable.xeGantt
100
+
101
+ const { footerFilterMethod } = opts
102
+ return footerFilterMethod ? footerTableData.filter((items, index) => footerFilterMethod({ $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt, items, $rowIndex: index })) : footerTableData
103
+ }
104
+
105
+ function getCsvCellTypeLabel(column: any, cellValue: any) {
106
+ if (cellValue) {
107
+ if (column.type === 'seq') {
108
+ return `\t${cellValue}`
109
+ }
110
+ switch (column.cellType) {
111
+ case 'string':
112
+ if (!isNaN(cellValue)) {
113
+ return `\t${cellValue}`
114
+ }
115
+ break
116
+ case 'number':
117
+ break
118
+ default:
119
+ if (cellValue.length >= 12 && !isNaN(cellValue)) {
120
+ return `\t${cellValue}`
121
+ }
122
+ break
123
+ }
124
+ }
125
+ return cellValue
126
+ }
127
+
128
+ function toTxtCellLabel(val: any) {
129
+ if (/[",\s\n]/.test(val)) {
130
+ return `"${val.replace(/"/g, '""')}"`
131
+ }
132
+ return XEUtils.eqNull(val) ? '' : val
133
+ }
134
+
135
+ function getElementsByTagName(elem: any, qualifiedName: any) {
136
+ return elem.getElementsByTagName(qualifiedName) as HTMLElement[]
137
+ }
138
+
139
+ function getTxtCellKey(now: number) {
140
+ return `#${now}@${XEUtils.uniqueId()}`
141
+ }
142
+
143
+ function replaceTxtCell(cell: any, vMaps: any) {
144
+ return cell.replace(/#\d+@\d+/g, (key: any) => (XEUtils.hasOwnProp(vMaps, key) ? vMaps[key] : key))
145
+ }
146
+
147
+ function getTxtCellValue(val: any, vMaps: any) {
148
+ const rest = replaceTxtCell(val, vMaps)
149
+ return rest.replace(/^"+$/g, (qVal: any) => '"'.repeat(Math.ceil(qVal.length / 2)))
150
+ }
151
+
152
+ function toExportField(
153
+ tableConf: {
154
+ fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
155
+ titleMaps: Record<string, VxeTableDefines.ColumnInfo>
156
+ },
157
+ field: string
158
+ ) {
159
+ const { fieldMaps, titleMaps } = tableConf
160
+ // title 转 field
161
+ if (!fieldMaps[field]) {
162
+ const teCol = titleMaps[field]
163
+ if (teCol && teCol.field) {
164
+ field = teCol.field
165
+ }
166
+ }
167
+ return field
168
+ }
169
+
170
+ function parseCsvAndTxt(
171
+ tableConf: {
172
+ fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
173
+ titleMaps: Record<string, VxeTableDefines.ColumnInfo>
174
+ },
175
+ content: string,
176
+ cellSeparator: string
177
+ ) {
178
+ const list = content.split(enterSymbol)
179
+ const rows: any[] = []
180
+ let fields: string[] = []
181
+ if (list.length) {
182
+ const vMaps: any = {}
183
+ const now = Date.now()
184
+ list.forEach((rVal) => {
185
+ if (rVal) {
186
+ const item: any = {}
187
+ rVal = rVal
188
+ .replace(/("")|(\n)/g, (text: string, dVal: string) => {
189
+ const key = getTxtCellKey(now)
190
+ vMaps[key] = dVal ? '"' : '\n'
191
+ return key
192
+ })
193
+ .replace(/"(.*?)"/g, (text: string, cVal: string) => {
194
+ const key = getTxtCellKey(now)
195
+ vMaps[key] = replaceTxtCell(cVal, vMaps)
196
+ return key
197
+ })
198
+ const cells: string[] = rVal.split(cellSeparator)
199
+ if (!fields.length) {
200
+ fields = cells.map((val: string) => toExportField(tableConf, getTxtCellValue(val.trim(), vMaps)))
201
+ } else {
202
+ cells.forEach((val, colIndex) => {
203
+ if (colIndex < fields.length) {
204
+ item[fields[colIndex]] = getTxtCellValue(val.trim(), vMaps)
205
+ }
206
+ })
207
+ rows.push(item)
208
+ }
209
+ }
210
+ })
211
+ }
212
+ return { fields, rows }
213
+ }
214
+
215
+ function parseCsv(
216
+ tableConf: {
217
+ fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
218
+ titleMaps: Record<string, VxeTableDefines.ColumnInfo>
219
+ },
220
+ content: string
221
+ ) {
222
+ return parseCsvAndTxt(tableConf, content, ',')
223
+ }
224
+
225
+ function parseTxt(
226
+ tableConf: {
227
+ fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
228
+ titleMaps: Record<string, VxeTableDefines.ColumnInfo>
229
+ },
230
+ content: string
231
+ ) {
232
+ return parseCsvAndTxt(tableConf, content, '\t')
233
+ }
234
+
235
+ function parseHTML(
236
+ tableConf: {
237
+ fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
238
+ titleMaps: Record<string, VxeTableDefines.ColumnInfo>
239
+ },
240
+ content: string
241
+ ) {
242
+ const domParser = new DOMParser()
243
+ const xmlDoc = domParser.parseFromString(content, 'text/html')
244
+ const bodyNodes = getElementsByTagName(xmlDoc, 'body')
245
+ const rows: any[] = []
246
+ const fields: string[] = []
247
+ if (bodyNodes.length) {
248
+ const tableNodes = getElementsByTagName(bodyNodes[0], 'table')
249
+ if (tableNodes.length) {
250
+ const theadNodes = getElementsByTagName(tableNodes[0], 'thead')
251
+ if (theadNodes.length) {
252
+ XEUtils.arrayEach(getElementsByTagName(theadNodes[0], 'tr'), (rowNode) => {
253
+ XEUtils.arrayEach(getElementsByTagName(rowNode, 'th'), (cellNode) => {
254
+ fields.push(toExportField(tableConf, cellNode.textContent || ''))
255
+ })
256
+ })
257
+ const tbodyNodes = getElementsByTagName(tableNodes[0], 'tbody')
258
+ if (tbodyNodes.length) {
259
+ XEUtils.arrayEach(getElementsByTagName(tbodyNodes[0], 'tr'), (rowNode) => {
260
+ const item: any = {}
261
+ XEUtils.arrayEach(getElementsByTagName(rowNode, 'td'), (cellNode, colIndex) => {
262
+ if (fields[colIndex]) {
263
+ item[fields[colIndex]] = cellNode.textContent || ''
264
+ }
265
+ })
266
+ rows.push(item)
267
+ })
268
+ }
269
+ }
270
+ }
271
+ }
272
+ return { fields, rows }
273
+ }
274
+
275
+ function parseXML(
276
+ tableConf: {
277
+ fieldMaps: Record<string, VxeTableDefines.ColumnInfo>
278
+ titleMaps: Record<string, VxeTableDefines.ColumnInfo>
279
+ },
280
+ content: string
281
+ ) {
282
+ const domParser = new DOMParser()
283
+ const xmlDoc = domParser.parseFromString(content, 'application/xml')
284
+ const sheetNodes = getElementsByTagName(xmlDoc, 'Worksheet')
285
+ const rows: any[] = []
286
+ const fields: string[] = []
287
+ if (sheetNodes.length) {
288
+ const tableNodes = getElementsByTagName(sheetNodes[0], 'Table')
289
+ if (tableNodes.length) {
290
+ const rowNodes = getElementsByTagName(tableNodes[0], 'Row')
291
+ if (rowNodes.length) {
292
+ XEUtils.arrayEach(getElementsByTagName(rowNodes[0], 'Cell'), (cellNode) => {
293
+ fields.push(toExportField(tableConf, cellNode.textContent || ''))
294
+ })
295
+ XEUtils.arrayEach(rowNodes, (rowNode, index) => {
296
+ if (index) {
297
+ const item: any = {}
298
+ const cellNodes = getElementsByTagName(rowNode, 'Cell')
299
+ XEUtils.arrayEach(cellNodes, (cellNode, colIndex) => {
300
+ if (fields[colIndex]) {
301
+ item[fields[colIndex]] = cellNode.textContent
302
+ }
303
+ })
304
+ rows.push(item)
305
+ }
306
+ })
307
+ }
308
+ }
309
+ }
310
+ return { fields, rows }
311
+ }
312
+
313
+ function clearColumnConvert(columns: any) {
314
+ XEUtils.eachTree(
315
+ columns,
316
+ (column: any) => {
317
+ delete column._level
318
+ delete column._colSpan
319
+ delete column._rowSpan
320
+ delete column._children
321
+ delete column.childNodes
322
+ },
323
+ { children: 'children' }
324
+ )
325
+ }
326
+
327
+ const tableExportMethodKeys: (keyof TableExportMethods)[] = ['exportData', 'importByFile', 'importData', 'saveFile', 'readFile', 'print', 'getPrintHtml', 'openImport', 'closeImport', 'openExport', 'closeExport', 'openPrint', 'closePrint']
328
+
329
+ hooks.add('tableExportModule', {
330
+ setupTable($xeTable) {
331
+ const { props, reactData, internalData } = $xeTable
332
+ const { computeTreeOpts, computePrintOpts, computeExportOpts, computeImportOpts, computeSeqOpts, computeRadioOpts, computeCheckboxOpts, computeColumnOpts, computeAggregateOpts, computeRendererOpts } = $xeTable.getComputeMaps()
333
+
334
+ const getSeq = (cellValue: any, row: any, $rowIndex: number, column: VxeTableDefines.ColumnInfo, $columnIndex: number) => {
335
+ const seqOpts = computeSeqOpts.value
336
+ const seqMd = seqOpts.seqMethod || (column as any).seqMethod
337
+ if (seqMd) {
338
+ return seqMd({
339
+ $table: $xeTable,
340
+ row,
341
+ rowIndex: $xeTable.getRowIndex(row),
342
+ _rowIndex: $xeTable.getVTRowIndex(row),
343
+ $rowIndex,
344
+ column,
345
+ columnIndex: $xeTable.getColumnIndex(column),
346
+ _columnIndex: $xeTable.getVTColumnIndex(column),
347
+ $columnIndex
348
+ })
349
+ }
350
+ return cellValue
351
+ }
352
+
353
+ function getHeaderTitle(opts: VxeTablePropTypes.ExportHandleOptions, column: VxeTableDefines.ColumnInfo) {
354
+ const columnOpts = computeColumnOpts.value
355
+ const headExportMethod = column.headerExportMethod || columnOpts.headerExportMethod
356
+ return headExportMethod ? headExportMethod({ column, options: opts, $table: $xeTable }) : (opts.isTitle ? $xeTable.getHeaderCellLabel(column) : column.field) || ''
357
+ }
358
+
359
+ const toBooleanValue = (cellValue: any) => {
360
+ return XEUtils.isBoolean(cellValue) ? (cellValue ? 'TRUE' : 'FALSE') : cellValue
361
+ }
362
+
363
+ const toStringValue = (cellValue: any) => {
364
+ return eqEmptyValue(cellValue) ? '' : `${cellValue}`
365
+ }
366
+
367
+ const getBodyLabelData = (opts: VxeTablePropTypes.ExportHandleOptions, columns: VxeTableDefines.ColumnInfo[], datas: any[]) => {
368
+ const { isTreeAllExpanded, isRowGroupAllExpanded, mode: expMode } = opts
369
+ const { treeConfig } = props
370
+ const { isRowGroupStatus } = reactData
371
+ const { fullColumnFieldData, fullAllDataRowIdData } = internalData
372
+ const radioOpts = computeRadioOpts.value
373
+ const checkboxOpts = computeCheckboxOpts.value
374
+ const treeOpts = computeTreeOpts.value
375
+ const columnOpts = computeColumnOpts.value
376
+ const aggregateOpts = computeAggregateOpts.value
377
+ const rendererOpts = computeRendererOpts.value
378
+ if (!htmlCellElem) {
379
+ htmlCellElem = document.createElement('div')
380
+ }
381
+ const { handleGetRowId } = createHandleGetRowId($xeTable)
382
+ if (isRowGroupStatus) {
383
+ // 如果是数据分组
384
+ const { mode: aggMode, showTotal, totalMethod, countFields, contentMethod, formatValuesMethod, mapChildrenField } = aggregateOpts
385
+ const rest: any[] = []
386
+ const expandMaps: Record<string, boolean> = {}
387
+ const useMaps: Record<string, boolean> = {}
388
+ XEUtils.eachTree(
389
+ datas,
390
+ (item, $rowIndex, items, path, parentItem, nodes) => {
391
+ const row = item._row || item
392
+ const rowid = handleGetRowId(row)
393
+ if (useMaps[rowid]) {
394
+ return
395
+ }
396
+ const parentRow = parentItem && parentItem._row ? parentItem._row : parentItem
397
+ const pRowid = parentRow ? handleGetRowId(parentRow) : ''
398
+ if (isRowGroupAllExpanded || !parentRow || (expandMaps[pRowid] && $xeTable.isRowExpandByRow(parentRow))) {
399
+ const hasRowChild = mapChildrenField && row[mapChildrenField] && row[mapChildrenField].length
400
+ const item: any = {
401
+ _row: row,
402
+ _level: nodes.length - 1,
403
+ _hasChild: hasRowChild,
404
+ _expand: hasRowChild && $xeTable.isRowExpandByRow(row)
405
+ }
406
+ columns.forEach((column, $columnIndex) => {
407
+ const { field, editRender, cellRender, aggFunc, rowGroupNode } = column
408
+ let cellValue: string | number | boolean | null = ''
409
+ const renderOpts = editRender || cellRender
410
+ let bodyExportMethod: VxeColumnPropTypes.ExportMethod | undefined = column.exportMethod || columnOpts.exportMethod
411
+ if (!bodyExportMethod && renderOpts && renderOpts.name) {
412
+ const compConf = rendererOpts[renderOpts.name] || renderer.get(renderOpts.name)
413
+ if (compConf) {
414
+ bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod
415
+ }
416
+ }
417
+ if (!bodyExportMethod) {
418
+ bodyExportMethod = columnOpts.exportMethod
419
+ }
420
+ if (bodyExportMethod) {
421
+ cellValue = bodyExportMethod({ $table: $xeTable, row, column, options: opts })
422
+ } else {
423
+ switch (column.type) {
424
+ case 'seq': {
425
+ const seqVal = path.map((num, i) => (i % 2 === 0 ? Number(num) + 1 : '.')).join('')
426
+ cellValue = expMode === 'all' ? seqVal : getSeq(seqVal, row, $rowIndex, column, $columnIndex)
427
+ break
428
+ }
429
+ case 'checkbox': {
430
+ cellValue = toBooleanValue($xeTable.isCheckedByCheckboxRow(row))
431
+ item._checkboxLabel = checkboxOpts.labelField ? XEUtils.get(row, checkboxOpts.labelField) : ''
432
+ item._checkboxDisabled = checkboxOpts.checkMethod && !checkboxOpts.checkMethod({ $table: $xeTable, row })
433
+ break
434
+ }
435
+ case 'radio': {
436
+ cellValue = toBooleanValue($xeTable.isCheckedByRadioRow(row))
437
+ item._radioLabel = radioOpts.labelField ? XEUtils.get(row, radioOpts.labelField) : ''
438
+ item._radioDisabled = radioOpts.checkMethod && !radioOpts.checkMethod({ $table: $xeTable, row })
439
+ break
440
+ }
441
+ default: {
442
+ if (field && row.isAggregate) {
443
+ const aggRow: VxeTableDefines.AggregateRowInfo = row
444
+ const aggData = aggRow.aggData
445
+ const currAggData = aggData ? aggData[field] : null
446
+ const groupField = aggRow.groupField
447
+ const groupContent = aggRow.groupContent
448
+ const childList = mapChildrenField ? aggRow[mapChildrenField] || [] : []
449
+ const childCount = aggRow.childCount
450
+ const colRest = fullColumnFieldData[groupField] || {}
451
+ const ctParams = {
452
+ $table: $xeTable,
453
+ groupField,
454
+ groupColumn: (colRest ? colRest.column : null) as VxeTableDefines.ColumnInfo,
455
+ column,
456
+ groupValue: groupContent,
457
+ childList,
458
+ childCount,
459
+ aggValue: null as any,
460
+
461
+ /**
462
+ * 已废弃
463
+ * @deprecated
464
+ */
465
+ children: childList,
466
+ /**
467
+ * 已废弃
468
+ * @deprecated
469
+ */
470
+ totalValue: childCount
471
+ }
472
+ if (aggMode === 'column' ? field === aggRow.groupField : rowGroupNode) {
473
+ cellValue = groupContent
474
+ if (contentMethod) {
475
+ cellValue = `${contentMethod(ctParams)}`
476
+ }
477
+ if (showTotal) {
478
+ cellValue = getI18n('vxe.table.rowGroupContentTotal', [cellValue, totalMethod ? totalMethod(ctParams) : childCount, childCount])
479
+ }
480
+ } else if ($xeTable.getPivotTableAggregateCellAggValue) {
481
+ const aggParams = {
482
+ $table: $xeTable,
483
+ row,
484
+ column
485
+ }
486
+ cellValue = $xeTable.getPivotTableAggregateCellAggValue(aggParams)
487
+ } else if (aggFunc === true || (countFields && countFields.includes(field))) {
488
+ cellValue = currAggData ? currAggData.value : childCount
489
+ ctParams.aggValue = cellValue
490
+ if (formatValuesMethod) {
491
+ cellValue = formatValuesMethod(ctParams)
492
+ }
493
+ }
494
+ } else if (opts.original) {
495
+ cellValue = getCellValue(row, column)
496
+ } else {
497
+ cellValue = $xeTable.getCellLabel(row, column)
498
+ if (column.type === 'html') {
499
+ htmlCellElem.innerHTML = cellValue
500
+ cellValue = htmlCellElem.innerText.trim()
501
+ } else {
502
+ const cell = $xeTable.getCellElement(row, column)
503
+ if (cell && !hasClass(cell, 'is--progress')) {
504
+ cellValue = cell.innerText.trim()
505
+ }
506
+ }
507
+ }
508
+ break
509
+ }
510
+ }
511
+ }
512
+ item[column.id] = toStringValue(cellValue)
513
+ })
514
+ useMaps[rowid] = true
515
+ if (pRowid) {
516
+ expandMaps[pRowid] = true
517
+ }
518
+ rest.push(Object.assign(item, row))
519
+ }
520
+ },
521
+ { children: mapChildrenField }
522
+ )
523
+ return rest
524
+ }
525
+ if (treeConfig) {
526
+ // 如果是树结构
527
+ const { seqMode } = treeOpts
528
+ const childrenField = treeOpts.children || treeOpts.childrenField
529
+ const rest: any[] = []
530
+ const expandMaps: Record<string, boolean> = {}
531
+ const useMaps: Record<string, boolean> = {}
532
+ XEUtils.eachTree(
533
+ datas,
534
+ (item, $rowIndex, items, path, parentItem, nodes) => {
535
+ const row = item._row || item
536
+ const rowid = handleGetRowId(row)
537
+ if (useMaps[rowid]) {
538
+ return
539
+ }
540
+ const parentRow = parentItem && parentItem._row ? parentItem._row : parentItem
541
+ const pRowid = parentRow ? handleGetRowId(parentRow) : ''
542
+ if (isTreeAllExpanded || !parentRow || (expandMaps[pRowid] && $xeTable.isTreeExpandByRow(parentRow))) {
543
+ const hasRowChild = row[childrenField] && row[childrenField].length
544
+ const item: any = {
545
+ _row: row,
546
+ _level: nodes.length - 1,
547
+ _hasChild: hasRowChild,
548
+ _expand: hasRowChild && $xeTable.isTreeExpandByRow(row)
549
+ }
550
+ const rowRest = fullAllDataRowIdData[rowid] || {}
551
+ columns.forEach((column, $columnIndex) => {
552
+ let cellValue: string | number | boolean | null = ''
553
+ const renderOpts = column.editRender || column.cellRender
554
+ let bodyExportMethod: VxeColumnPropTypes.ExportMethod | undefined = column.exportMethod || columnOpts.exportMethod
555
+ if (!bodyExportMethod && renderOpts && renderOpts.name) {
556
+ const compConf = rendererOpts[renderOpts.name] || renderer.get(renderOpts.name)
557
+ if (compConf) {
558
+ bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod
559
+ }
560
+ }
561
+ if (!bodyExportMethod) {
562
+ bodyExportMethod = columnOpts.exportMethod
563
+ }
564
+ if (bodyExportMethod) {
565
+ cellValue = bodyExportMethod({ $table: $xeTable, row, column, options: opts })
566
+ } else {
567
+ switch (column.type) {
568
+ case 'seq': {
569
+ let seqVal: number | string = path.map((num, i) => (i % 2 === 0 ? Number(num) + 1 : '.')).join('')
570
+ if (seqMode === 'increasing') {
571
+ seqVal = rowRest ? rowRest._index + 1 : -1
572
+ }
573
+ cellValue = expMode === 'all' ? seqVal : getSeq(seqVal, row, $rowIndex, column, $columnIndex)
574
+ break
575
+ }
576
+ case 'checkbox':
577
+ cellValue = toBooleanValue($xeTable.isCheckedByCheckboxRow(row))
578
+ item._checkboxLabel = checkboxOpts.labelField ? XEUtils.get(row, checkboxOpts.labelField) : ''
579
+ item._checkboxDisabled = checkboxOpts.checkMethod && !checkboxOpts.checkMethod({ $table: $xeTable, row })
580
+ break
581
+ case 'radio':
582
+ cellValue = toBooleanValue($xeTable.isCheckedByRadioRow(row))
583
+ item._radioLabel = radioOpts.labelField ? XEUtils.get(row, radioOpts.labelField) : ''
584
+ item._radioDisabled = radioOpts.checkMethod && !radioOpts.checkMethod({ $table: $xeTable, row })
585
+ break
586
+ default:
587
+ if (opts.original) {
588
+ cellValue = getCellValue(row, column)
589
+ } else {
590
+ cellValue = $xeTable.getCellLabel(row, column)
591
+ if (column.type === 'html') {
592
+ htmlCellElem.innerHTML = cellValue
593
+ cellValue = htmlCellElem.innerText.trim()
594
+ } else {
595
+ const cell = $xeTable.getCellElement(row, column)
596
+ if (cell && !hasClass(cell, 'is--progress')) {
597
+ cellValue = cell.innerText.trim()
598
+ }
599
+ }
600
+ }
601
+ }
602
+ }
603
+ item[column.id] = toStringValue(cellValue)
604
+ })
605
+ useMaps[rowid] = true
606
+ if (pRowid) {
607
+ expandMaps[pRowid] = true
608
+ }
609
+ rest.push(Object.assign(item, row))
610
+ }
611
+ },
612
+ { children: childrenField }
613
+ )
614
+ return rest
615
+ }
616
+ return datas.map((row, $rowIndex) => {
617
+ const item: any = {
618
+ _row: row
619
+ }
620
+ columns.forEach((column, $columnIndex) => {
621
+ let cellValue: string | number | boolean | null = ''
622
+ const renderOpts = column.editRender || column.cellRender
623
+ let bodyExportMethod: VxeColumnPropTypes.ExportMethod | undefined = column.exportMethod || columnOpts.exportMethod
624
+ if (!bodyExportMethod && renderOpts && renderOpts.name) {
625
+ const compConf = rendererOpts[renderOpts.name] || renderer.get(renderOpts.name)
626
+ if (compConf) {
627
+ bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod
628
+ }
629
+ }
630
+ if (bodyExportMethod) {
631
+ cellValue = bodyExportMethod({ $table: $xeTable, row, column, options: opts })
632
+ } else {
633
+ switch (column.type) {
634
+ case 'seq': {
635
+ const seqValue = $rowIndex + 1
636
+ cellValue = expMode === 'all' ? seqValue : getSeq(seqValue, row, $rowIndex, column, $columnIndex)
637
+ break
638
+ }
639
+ case 'checkbox':
640
+ cellValue = toBooleanValue($xeTable.isCheckedByCheckboxRow(row))
641
+ item._checkboxLabel = checkboxOpts.labelField ? XEUtils.get(row, checkboxOpts.labelField) : ''
642
+ item._checkboxDisabled = checkboxOpts.checkMethod && !checkboxOpts.checkMethod({ $table: $xeTable, row })
643
+ break
644
+ case 'radio':
645
+ cellValue = toBooleanValue($xeTable.isCheckedByRadioRow(row))
646
+ item._radioLabel = radioOpts.labelField ? XEUtils.get(row, radioOpts.labelField) : ''
647
+ item._radioDisabled = radioOpts.checkMethod && !radioOpts.checkMethod({ $table: $xeTable, row })
648
+ break
649
+ default:
650
+ if (opts.original) {
651
+ cellValue = getCellValue(row, column)
652
+ } else {
653
+ cellValue = $xeTable.getCellLabel(row, column)
654
+ if (column.type === 'html') {
655
+ htmlCellElem.innerHTML = cellValue
656
+ cellValue = htmlCellElem.innerText.trim()
657
+ } else {
658
+ const cell = $xeTable.getCellElement(row, column)
659
+ if (cell && !hasClass(cell, 'is--progress')) {
660
+ cellValue = cell.innerText.trim()
661
+ }
662
+ }
663
+ }
664
+ }
665
+ }
666
+ item[column.id] = toStringValue(cellValue)
667
+ })
668
+ return item
669
+ })
670
+ }
671
+
672
+ const getExportData = (opts: VxeTablePropTypes.ExportHandleOptions) => {
673
+ const $xeGrid = $xeTable.xeGrid
674
+ const $xeGantt = $xeTable.xeGantt
675
+
676
+ const { columns, dataFilterMethod } = opts
677
+ let datas = opts.data
678
+ if (dataFilterMethod) {
679
+ datas = datas.filter((row, index) => dataFilterMethod({ $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt, row, $rowIndex: index }))
680
+ }
681
+ return getBodyLabelData(opts, columns, datas)
682
+ }
683
+
684
+ const getFooterCellValue = (opts: VxeTablePropTypes.ExportHandleOptions, row: any, column: VxeTableDefines.ColumnInfo) => {
685
+ const columnOpts = computeColumnOpts.value
686
+ const rendererOpts = computeRendererOpts.value
687
+ const renderOpts = column.editRender || column.cellRender
688
+ let footLabelMethod: VxeColumnPropTypes.FooterExportMethod | undefined = column.footerExportMethod
689
+ if (!footLabelMethod && renderOpts && renderOpts.name) {
690
+ const compConf = rendererOpts[renderOpts.name] || renderer.get(renderOpts.name)
691
+ if (compConf) {
692
+ footLabelMethod = compConf.tableFooterExportMethod || compConf.footerExportMethod
693
+ }
694
+ }
695
+ if (!footLabelMethod) {
696
+ footLabelMethod = columnOpts.footerExportMethod
697
+ }
698
+ if (footLabelMethod) {
699
+ const _columnIndex = $xeTable.getVTColumnIndex(column)
700
+ return footLabelMethod({ $table: $xeTable, items: row, itemIndex: _columnIndex, row, _columnIndex, column, options: opts })
701
+ }
702
+ const cellValue = $xeTable.getFooterCellLabel(row, column)
703
+ return cellValue
704
+ }
705
+
706
+ const toCsv = ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, opts: VxeTablePropTypes.ExportHandleOptions, columns: VxeTableDefines.ColumnInfo[], datas: any[]) => {
707
+ let content = csvBOM
708
+ if (opts.isHeader) {
709
+ content += columns.map((column) => toTxtCellLabel(getHeaderTitle(opts, column))).join(',') + enterSymbol
710
+ }
711
+ datas.forEach((row) => {
712
+ content += columns.map((column) => toTxtCellLabel(getCsvCellTypeLabel(column, row[column.id]))).join(',') + enterSymbol
713
+ })
714
+ if (opts.isFooter) {
715
+ const { footerTableData } = reactData
716
+ const footers = getFooterData($xeTable, opts, footerTableData)
717
+ footers.forEach((row) => {
718
+ content += columns.map((column: any) => toTxtCellLabel(getFooterCellValue(opts, row, column))).join(',') + enterSymbol
719
+ })
720
+ }
721
+ return content
722
+ }
723
+
724
+ const toTxt = ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, opts: VxeTablePropTypes.ExportHandleOptions, columns: VxeTableDefines.ColumnInfo[], datas: any[]) => {
725
+ let content = ''
726
+ if (opts.isHeader) {
727
+ content += columns.map((column) => toTxtCellLabel(getHeaderTitle(opts, column))).join('\t') + enterSymbol
728
+ }
729
+ datas.forEach((row) => {
730
+ content += columns.map((column) => toTxtCellLabel(row[column.id])).join('\t') + enterSymbol
731
+ })
732
+ if (opts.isFooter) {
733
+ const { footerTableData } = reactData
734
+ const footers = getFooterData($xeTable, opts, footerTableData)
735
+ footers.forEach((row) => {
736
+ content += columns.map((column: any) => toTxtCellLabel(getFooterCellValue(opts, row, column))).join('\t') + enterSymbol
737
+ })
738
+ }
739
+ return content
740
+ }
741
+
742
+ const hasEllipsis = (column: VxeTableDefines.ColumnInfo, property: 'showOverflow' | 'showHeaderOverflow', allColumnOverflow: VxeTablePropTypes.ShowOverflow | undefined) => {
743
+ const columnOverflow = column[property]
744
+ const headOverflow = XEUtils.isUndefined(columnOverflow) || XEUtils.isNull(columnOverflow) ? allColumnOverflow : columnOverflow
745
+ const showEllipsis = headOverflow === 'ellipsis'
746
+ const showTitle = headOverflow === 'title'
747
+ const showTooltip = headOverflow === true || headOverflow === 'tooltip'
748
+ let isEllipsis = showTitle || showTooltip || showEllipsis
749
+ // 虚拟滚动不支持动态高度
750
+ const { scrollXLoad, scrollYLoad } = reactData
751
+ if ((scrollXLoad || scrollYLoad) && !isEllipsis) {
752
+ isEllipsis = true
753
+ }
754
+ return isEllipsis
755
+ }
756
+
757
+ const getCustomColKey = (conf: VxeTableDefines.ColumnInfo<any> | VxeTablePropTypes.ExportOrPrintColumnOption) => {
758
+ return `${conf.field || ''}:${conf.type || ''}`
759
+ }
760
+
761
+ const toHtml = (opts: VxeTablePropTypes.ExportHandleOptions, columns: VxeTableDefines.ColumnInfo[], datas: any[]) => {
762
+ const { id, border, treeConfig, headerAlign: allHeaderAlign, align: allAlign, footerAlign: allFooterAlign, showOverflow: allColumnOverflow, showHeaderOverflow: allColumnHeaderOverflow } = props
763
+ const { isAllSelected, isIndeterminate } = reactData
764
+ const { mergeBodyCellMaps, mergeFooterCellMaps } = internalData
765
+ const treeOpts = computeTreeOpts.value
766
+ const { print: isPrint, widthMode, isHeader, isFooter, isColgroup, isMerge, colgroups, _columnConfs, original } = opts
767
+ const isAutoWidth = widthMode === 'auto'
768
+ const isScaleWidth = widthMode === 'scale'
769
+ const isDefaultWidth = !isAutoWidth && !isScaleWidth
770
+
771
+ const customWidthMaps: Record<string, number | string> = {}
772
+ if (_columnConfs) {
773
+ _columnConfs.forEach((conf) => {
774
+ if (!isColumnInfo(conf)) {
775
+ if ((conf.field || conf.type) && conf.width) {
776
+ customWidthMaps[getCustomColKey(conf)] = conf.width
777
+ }
778
+ }
779
+ })
780
+ }
781
+
782
+ // 计算宽度
783
+ const colWidthMaps: Record<string, number> = {}
784
+ const printWidthMaps: Record<string, number> = {}
785
+ if (isPrint) {
786
+ let tableWidth = 0
787
+ columns.forEach((column) => {
788
+ tableWidth += column.renderWidth
789
+ })
790
+ if (colgroups) {
791
+ colgroups.forEach((cols) => {
792
+ cols.forEach((column: any) => {
793
+ if (!column.childNodes || !column.childNodes.length) {
794
+ return
795
+ }
796
+ let childWidth = 0
797
+ let countChild = 0
798
+ XEUtils.eachTree(
799
+ [column],
800
+ (item) => {
801
+ if (!item.childNodes || !column.childNodes.length) {
802
+ countChild++
803
+ }
804
+ const ptWidth = printWidthMaps[item.id]
805
+ childWidth += ptWidth || 0
806
+ },
807
+ { children: 'childNodes' }
808
+ )
809
+ const colWidth = childWidth - countChild
810
+ colWidthMaps[column.id] = colWidth
811
+ printWidthMaps[column.id] = XEUtils.floor((colWidth / tableWidth) * 180, 2)
812
+ })
813
+ })
814
+ }
815
+ columns.forEach((column) => {
816
+ const colWidth = column.renderWidth
817
+ if (column.width) {
818
+ colWidthMaps[column.id] = colWidth
819
+ }
820
+ printWidthMaps[column.id] = XEUtils.floor((colWidth / tableWidth) * 180, 2)
821
+ })
822
+ }
823
+
824
+ const getHeaderWidthStyle = (column: VxeTableDefines.ColumnInfo) => {
825
+ const cmColKey = getCustomColKey(column)
826
+ const cmWidthMaps = customWidthMaps[cmColKey]
827
+ if (cmWidthMaps) {
828
+ return 'width:' + toCssUnit(cmWidthMaps)
829
+ }
830
+ if (isAutoWidth) {
831
+ return ''
832
+ }
833
+ if (isScaleWidth) {
834
+ return printWidthMaps[column.id] ? 'width:' + printWidthMaps[column.id] + 'mm' : ''
835
+ }
836
+ return colWidthMaps[column.id] ? 'width:' + toCssUnit(colWidthMaps[column.id]) : ''
837
+ }
838
+
839
+ const getCellWidthStyle = (column: VxeTableDefines.ColumnInfo) => {
840
+ const cmColKey = getCustomColKey(column)
841
+ const cmWidthMaps = customWidthMaps[cmColKey]
842
+ if (cmWidthMaps) {
843
+ return 'width:' + toCssUnit(cmWidthMaps)
844
+ }
845
+ if (isAutoWidth || isDefaultWidth) {
846
+ return ''
847
+ }
848
+ if (isScaleWidth) {
849
+ return printWidthMaps[column.id] ? 'width:' + printWidthMaps[column.id] + 'mm' : ''
850
+ }
851
+ return colWidthMaps[column.id] ? 'width:' + toCssUnit(colWidthMaps[column.id]) : ''
852
+ }
853
+
854
+ const allCls = 'check-all'
855
+ const clss = ['vxe-table', `border--${toTableBorder(border)}`, isPrint ? 'is--print' : '', isAutoWidth ? 'is--auto-width' : '', isScaleWidth ? 'is--scale-width' : '', isDefaultWidth ? 'is--default-width' : '', isHeader ? 'is--header' : ''].filter((cls) => cls)
856
+ const tables = [`<table class="${clss.join(' ')}" border="0" cellspacing="0" cellpadding="0">`, `<colgroup>${columns.map((column) => `<col style="${getHeaderWidthStyle(column)}">`).join('')}</colgroup>`]
857
+ if (isHeader) {
858
+ tables.push('<thead>')
859
+ if (isColgroup && !original) {
860
+ colgroups.forEach((cols) => {
861
+ tables.push(
862
+ `<tr>${cols
863
+ .map((column: any) => {
864
+ const headAlign = column.headerAlign || column.align || allHeaderAlign || allAlign
865
+ const classNames = hasEllipsis(column, 'showHeaderOverflow', allColumnHeaderOverflow) ? ['col--ellipsis'] : []
866
+ const cellTitle = getHeaderTitle(opts, column)
867
+ if (headAlign) {
868
+ classNames.push(`col--${headAlign}`)
869
+ }
870
+ if (column.type === 'checkbox') {
871
+ return `<th class="${classNames.join(' ')}" colspan="${column._colSpan}" rowspan="${column._rowSpan}"><div style="${getCellWidthStyle(column)}"><input type="checkbox" class="${allCls}" ${isAllSelected ? 'checked' : ''}><span>${cellTitle}</span></div></th>`
872
+ }
873
+ return `<th class="${classNames.join(' ')}" colspan="${column._colSpan}" rowspan="${column._rowSpan}" title="${cellTitle}"><div style="${getCellWidthStyle(column)}"><span>${formatText(cellTitle, true)}</span></div></th>`
874
+ })
875
+ .join('')}</tr>`
876
+ )
877
+ })
878
+ } else {
879
+ tables.push(
880
+ `<tr>${columns
881
+ .map((column: any) => {
882
+ const headAlign = column.headerAlign || column.align || allHeaderAlign || allAlign
883
+ const classNames = hasEllipsis(column, 'showHeaderOverflow', allColumnHeaderOverflow) ? ['col--ellipsis'] : []
884
+ const cellTitle = getHeaderTitle(opts, column)
885
+ if (headAlign) {
886
+ classNames.push(`col--${headAlign}`)
887
+ }
888
+ if (column.type === 'checkbox') {
889
+ return `<th class="${classNames.join(' ')}"><div style="${getCellWidthStyle(column)}"><input type="checkbox" class="${allCls}" ${isAllSelected ? 'checked' : ''}><span>${cellTitle}</span></div></th>`
890
+ }
891
+ return `<th class="${classNames.join(' ')}" title="${cellTitle}"><div style="${getCellWidthStyle(column)}"><span>${formatText(cellTitle, true)}</span></div></th>`
892
+ })
893
+ .join('')}</tr>`
894
+ )
895
+ }
896
+ tables.push('</thead>')
897
+ }
898
+ if (datas.length) {
899
+ tables.push('<tbody>')
900
+ if (treeConfig) {
901
+ datas.forEach((item: any) => {
902
+ tables.push(
903
+ '<tr>' +
904
+ columns
905
+ .map((column: any) => {
906
+ const colid = column.id
907
+ const cellAlign = column.align || allAlign
908
+ const classNames = hasEllipsis(column, 'showOverflow', allColumnOverflow) ? ['col--ellipsis'] : []
909
+ const cellValue = item[colid]
910
+ if (cellAlign) {
911
+ classNames.push(`col--${cellAlign}`)
912
+ }
913
+ if (column.treeNode) {
914
+ let treeIcon = ''
915
+ if (item._hasChild) {
916
+ treeIcon = `<i class="${item._expand ? 'vxe-table--tree-fold-icon' : 'vxe-table--tree-unfold-icon'}"></i>`
917
+ }
918
+ classNames.push('vxe-table--tree-node')
919
+ if (column.type === 'radio') {
920
+ return `<td class="${classNames.join(' ')}" title="${cellValue}"><div style="${getCellWidthStyle(column)}"><div class="vxe-table--tree-node-wrapper" style="padding-left: ${item._level * treeOpts.indent}px"><div class="vxe-table--tree-icon-wrapper">${treeIcon}</div><div class="vxe-table--tree-cell"><input type="radio" name="radio_${id}" ${item._radioDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._radioLabel}</span></div></div></div></td>`
921
+ } else if (column.type === 'checkbox') {
922
+ return `<td class="${classNames.join(' ')}" title="${cellValue}"><div style="${getCellWidthStyle(column)}"><div class="vxe-table--tree-node-wrapper" style="padding-left: ${item._level * treeOpts.indent}px"><div class="vxe-table--tree-icon-wrapper">${treeIcon}</div><div class="vxe-table--tree-cell"><input type="checkbox" ${item._checkboxDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._checkboxLabel}</span></div></div></div></td>`
923
+ }
924
+ return `<td class="${classNames.join(' ')}" title="${cellValue}"><div style="${getCellWidthStyle(column)}"><div class="vxe-table--tree-node-wrapper" style="padding-left: ${item._level * treeOpts.indent}px"><div class="vxe-table--tree-icon-wrapper">${treeIcon}</div><div class="vxe-table--tree-cell">${cellValue}</div></div></div></td>`
925
+ }
926
+ if (column.type === 'radio') {
927
+ return `<td class="${classNames.join(' ')}"><div style="${getCellWidthStyle(column)}"><input type="radio" name="radio_${id}" ${item._radioDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._radioLabel}</span></div></td>`
928
+ } else if (column.type === 'checkbox') {
929
+ return `<td class="${classNames.join(' ')}"><div style="${getCellWidthStyle(column)}"><input type="checkbox" ${item._checkboxDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._checkboxLabel}</span></div></td>`
930
+ }
931
+ return `<td class="${classNames.join(' ')}" title="${cellValue}"><div style="${getCellWidthStyle(column)}">${formatText(cellValue, true)}</div></td>`
932
+ })
933
+ .join('') +
934
+ '</tr>'
935
+ )
936
+ })
937
+ } else {
938
+ datas.forEach((item) => {
939
+ tables.push(
940
+ '<tr>' +
941
+ columns
942
+ .map((column) => {
943
+ const cellAlign = column.align || allAlign
944
+ const classNames = hasEllipsis(column, 'showOverflow', allColumnOverflow) ? ['col--ellipsis'] : []
945
+ const cellValue = item[column.id]
946
+ let rowSpan = 1
947
+ let colSpan = 1
948
+ if (isMerge) {
949
+ const _rowIndex = $xeTable.getVTRowIndex(item._row)
950
+ const _columnIndex = $xeTable.getVTColumnIndex(column)
951
+ const spanRest = mergeBodyCellMaps[`${_rowIndex}:${_columnIndex}`]
952
+ if (spanRest) {
953
+ const { rowspan, colspan } = spanRest
954
+ if (!rowspan || !colspan) {
955
+ return ''
956
+ }
957
+ if (rowspan > 1) {
958
+ rowSpan = rowspan
959
+ }
960
+ if (colspan > 1) {
961
+ colSpan = colspan
962
+ }
963
+ }
964
+ }
965
+ if (cellAlign) {
966
+ classNames.push(`col--${cellAlign}`)
967
+ }
968
+ if (column.type === 'radio') {
969
+ return `<td class="${classNames.join(' ')}" rowspan="${rowSpan}" colspan="${colSpan}"><div style="${getCellWidthStyle(column)}"><input type="radio" name="radio_${id}" ${item._radioDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._radioLabel}</span></div></td>`
970
+ } else if (column.type === 'checkbox') {
971
+ return `<td class="${classNames.join(' ')}" rowspan="${rowSpan}" colspan="${colSpan}"><div style="${getCellWidthStyle(column)}"><input type="checkbox" ${item._checkboxDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._checkboxLabel}</span></div></td>`
972
+ }
973
+ return `<td class="${classNames.join(' ')}" rowspan="${rowSpan}" colspan="${colSpan}" title="${cellValue}"><div style="${getCellWidthStyle(column)}">${formatText(cellValue, true)}</div></td>`
974
+ })
975
+ .join('') +
976
+ '</tr>'
977
+ )
978
+ })
979
+ }
980
+ tables.push('</tbody>')
981
+ }
982
+ if (isFooter) {
983
+ const { footerTableData } = reactData
984
+ const footers = getFooterData($xeTable, opts, footerTableData)
985
+ if (footers.length) {
986
+ tables.push('<tfoot>')
987
+ footers.forEach((row, rIndex) => {
988
+ tables.push(
989
+ `<tr>${columns
990
+ .map((column) => {
991
+ const footAlign = column.footerAlign || column.align || allFooterAlign || allAlign
992
+ const classNames = hasEllipsis(column, 'showOverflow', allColumnOverflow) ? ['col--ellipsis'] : []
993
+ const cellValue = getFooterCellValue(opts, row, column)
994
+ let rowSpan = 1
995
+ let colSpan = 1
996
+ if (isMerge) {
997
+ const _rowIndex = rIndex
998
+ const _columnIndex = $xeTable.getVTColumnIndex(column)
999
+ const spanRest = mergeFooterCellMaps[`${_rowIndex}:${_columnIndex}`]
1000
+ if (spanRest) {
1001
+ const { rowspan, colspan } = spanRest
1002
+ if (!rowspan || !colspan) {
1003
+ return ''
1004
+ }
1005
+ if (rowspan > 1) {
1006
+ rowSpan = rowspan
1007
+ }
1008
+ if (colspan > 1) {
1009
+ colSpan = colspan
1010
+ }
1011
+ }
1012
+ }
1013
+ if (footAlign) {
1014
+ classNames.push(`col--${footAlign}`)
1015
+ }
1016
+ return `<td class="${classNames.join(' ')}" rowspan="${rowSpan}" colspan="${colSpan}" title="${cellValue}"><div style="${getCellWidthStyle(column)}">${formatText(cellValue, true)}</div></td>`
1017
+ })
1018
+ .join('')}</tr>`
1019
+ )
1020
+ })
1021
+ tables.push('</tfoot>')
1022
+ }
1023
+ }
1024
+ // 是否半选状态
1025
+ const script = !isAllSelected && isIndeterminate ? `<script>(function(){var a=document.querySelector(".${allCls}");if(a){a.indeterminate=true}})()</script>` : ''
1026
+ tables.push('</table>', script)
1027
+ return isPrint ? tables.join('') : createHtmlPage(opts, tables.join(''))
1028
+ }
1029
+
1030
+ const toXML = (opts: any, columns: any, datas: any) => {
1031
+ let xml = [
1032
+ '<?xml version="1.0"?>',
1033
+ '<?mso-application progid="Excel.Sheet"?>',
1034
+ '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">',
1035
+ '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">',
1036
+ '<Version>16.00</Version>',
1037
+ '</DocumentProperties>',
1038
+ '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">',
1039
+ '<WindowHeight>7920</WindowHeight>',
1040
+ '<WindowWidth>21570</WindowWidth>',
1041
+ '<WindowTopX>32767</WindowTopX>',
1042
+ '<WindowTopY>32767</WindowTopY>',
1043
+ '<ProtectStructure>False</ProtectStructure>',
1044
+ '<ProtectWindows>False</ProtectWindows>',
1045
+ '</ExcelWorkbook>',
1046
+ `<Worksheet ss:Name="${opts.sheetName}">`,
1047
+ '<Table>',
1048
+ columns.map((column: any) => `<Column ss:Width="${column.renderWidth}"/>`).join('')
1049
+ ].join('')
1050
+ if (opts.isHeader) {
1051
+ xml += `<Row>${columns.map((column: any) => `<Cell><Data ss:Type="String">${getHeaderTitle(opts, column)}</Data></Cell>`).join('')}</Row>`
1052
+ }
1053
+ datas.forEach((row: any) => {
1054
+ xml += '<Row>' + columns.map((column: any) => `<Cell><Data ss:Type="String">${row[column.id]}</Data></Cell>`).join('') + '</Row>'
1055
+ })
1056
+ if (opts.isFooter) {
1057
+ const { footerTableData } = reactData
1058
+ const footers = getFooterData($xeTable, opts, footerTableData)
1059
+ footers.forEach((row: any) => {
1060
+ xml += `<Row>${columns.map((column: any) => `<Cell><Data ss:Type="String">${getFooterCellValue(opts, row, column)}</Data></Cell>`).join('')}</Row>`
1061
+ })
1062
+ }
1063
+ return `${xml}</Table></Worksheet></Workbook>`
1064
+ }
1065
+
1066
+ const getContent = ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, opts: VxeTablePropTypes.ExportHandleOptions, columns: VxeTableDefines.ColumnInfo[], datas: any[]) => {
1067
+ if (columns.length) {
1068
+ switch (opts.type) {
1069
+ case 'csv':
1070
+ return toCsv($xeTable, opts, columns, datas)
1071
+ case 'txt':
1072
+ return toTxt($xeTable, opts, columns, datas)
1073
+ case 'html':
1074
+ return toHtml(opts, columns, datas)
1075
+ case 'xml':
1076
+ return toXML(opts, columns, datas)
1077
+ }
1078
+ }
1079
+ return ''
1080
+ }
1081
+
1082
+ const downloadFile = (opts: any, content: any) => {
1083
+ const { filename, type, download } = opts
1084
+ if (!download) {
1085
+ const blob = getExportBlobByContent(content, opts)
1086
+ return Promise.resolve({ type, content, blob })
1087
+ }
1088
+ if (VxeUI.saveFile) {
1089
+ VxeUI.saveFile({ filename, type, content }).then(() => {
1090
+ if (opts.message !== false) {
1091
+ if (VxeUI.modal) {
1092
+ VxeUI.modal.message({ content: getI18n('vxe.table.expSuccess'), status: 'success' })
1093
+ }
1094
+ }
1095
+ })
1096
+ }
1097
+ }
1098
+
1099
+ const handleExport = (opts: VxeTablePropTypes.ExportHandleOptions) => {
1100
+ const $xeGrid = $xeTable.xeGrid
1101
+ const $xeGantt = $xeTable.xeGantt
1102
+
1103
+ const { remote, columns, colgroups, exportMethod, afterExportMethod } = opts
1104
+ return new Promise((resolve) => {
1105
+ if (remote) {
1106
+ const params = { options: opts, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt }
1107
+ resolve(exportMethod ? exportMethod(params) : params)
1108
+ } else {
1109
+ const datas = getExportData(opts)
1110
+ resolve(
1111
+ $xeTable.preventEvent(null, 'event.export', { options: opts, columns, colgroups, datas }, () => {
1112
+ return downloadFile(opts, getContent($xeTable, opts, columns, datas))
1113
+ })
1114
+ )
1115
+ }
1116
+ })
1117
+ .then((params: any) => {
1118
+ clearColumnConvert(columns)
1119
+ if (!opts.print) {
1120
+ if (afterExportMethod) {
1121
+ afterExportMethod({ status: true, options: opts, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt })
1122
+ }
1123
+ }
1124
+ return Object.assign({ status: true }, params)
1125
+ })
1126
+ .catch(() => {
1127
+ clearColumnConvert(columns)
1128
+ if (!opts.print) {
1129
+ if (afterExportMethod) {
1130
+ afterExportMethod({ status: false, options: opts, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt })
1131
+ }
1132
+ }
1133
+ const params = { status: false }
1134
+ return Promise.reject(params)
1135
+ })
1136
+ }
1137
+
1138
+ const handleImport = (content: any, opts: any) => {
1139
+ const { tableFullColumn, _importResolve, _importReject } = internalData
1140
+ let rest: {
1141
+ fields: string[]
1142
+ rows: any[]
1143
+ } = { fields: [], rows: [] }
1144
+ const tableFieldMaps: Record<string, VxeTableDefines.ColumnInfo> = {}
1145
+ const tableTitleMaps: Record<string, VxeTableDefines.ColumnInfo> = {}
1146
+ tableFullColumn.forEach((column) => {
1147
+ const field = column.field
1148
+ const title = $xeTable.getHeaderCellLabel(column)
1149
+ if (field) {
1150
+ tableFieldMaps[field] = column
1151
+ }
1152
+ if (title) {
1153
+ tableTitleMaps[title] = column
1154
+ }
1155
+ })
1156
+ const tableConf = {
1157
+ fieldMaps: tableFieldMaps,
1158
+ titleMaps: tableTitleMaps
1159
+ }
1160
+ switch (opts.type) {
1161
+ case 'csv':
1162
+ rest = parseCsv(tableConf, content)
1163
+ break
1164
+ case 'txt':
1165
+ rest = parseTxt(tableConf, content)
1166
+ break
1167
+ case 'html':
1168
+ rest = parseHTML(tableConf, content)
1169
+ break
1170
+ case 'xml':
1171
+ rest = parseXML(tableConf, content)
1172
+ break
1173
+ }
1174
+ const { fields, rows } = rest
1175
+ const status = fields.some((field) => tableFieldMaps[field] || tableTitleMaps[field])
1176
+ if (status) {
1177
+ $xeTable.createData(rows).then((data: any) => {
1178
+ let loadRest
1179
+ if (opts.mode === 'insert' || opts.mode === 'insertBottom') {
1180
+ loadRest = $xeTable.insertAt(data, -1)
1181
+ } else if (opts.mode === 'insertTop') {
1182
+ loadRest = $xeTable.insert(data)
1183
+ } else {
1184
+ loadRest = $xeTable.reloadData(data)
1185
+ }
1186
+ if (opts.message !== false) {
1187
+ if (VxeUI.modal) {
1188
+ VxeUI.modal.message({ content: getI18n('vxe.table.impSuccess', [rows.length]), status: 'success' })
1189
+ }
1190
+ }
1191
+ return loadRest.then(() => {
1192
+ if (_importResolve) {
1193
+ _importResolve({ status: true })
1194
+ }
1195
+ })
1196
+ })
1197
+ } else {
1198
+ if (opts.message !== false) {
1199
+ if (VxeUI.modal) {
1200
+ VxeUI.modal.message({ content: getI18n('vxe.error.impFields'), status: 'error' })
1201
+ }
1202
+ }
1203
+ if (_importReject) {
1204
+ _importReject({ status: false, msg: 'field mismatching' })
1205
+ }
1206
+ }
1207
+ }
1208
+
1209
+ const handleFileImport = (file: File, opts: any) => {
1210
+ const { importMethod, afterImportMethod } = opts
1211
+ const { type, filename } = parseFile(file)
1212
+ const importOpts = computeImportOpts.value
1213
+
1214
+ // 检查类型,如果为自定义导出,则不需要校验类型
1215
+ if (!importMethod && !XEUtils.includes(XEUtils.keys(importOpts._typeMaps), type)) {
1216
+ if (opts.message !== false) {
1217
+ if (VxeUI.modal) {
1218
+ VxeUI.modal.message({ content: getI18n('vxe.error.notType', [type]), status: 'error' })
1219
+ }
1220
+ }
1221
+ const params = { status: false, msg: 'type error' }
1222
+ return Promise.reject(params)
1223
+ }
1224
+
1225
+ const rest = new Promise((resolve, reject) => {
1226
+ const _importResolve = (params?: any) => {
1227
+ resolve(params)
1228
+ internalData._importResolve = null
1229
+ internalData._importReject = null
1230
+ }
1231
+ const _importReject = (params?: any) => {
1232
+ reject(params)
1233
+ internalData._importResolve = null
1234
+ internalData._importReject = null
1235
+ }
1236
+ internalData._importResolve = _importResolve
1237
+ internalData._importReject = _importReject
1238
+ if (window.FileReader) {
1239
+ const options = Object.assign({ mode: 'insertTop' }, opts, { type, filename })
1240
+ if (options.remote) {
1241
+ if (importMethod) {
1242
+ Promise.resolve(importMethod({ file, options, $table: $xeTable }))
1243
+ .then(() => {
1244
+ _importResolve({ status: true })
1245
+ })
1246
+ .catch(() => {
1247
+ _importResolve({ status: true })
1248
+ })
1249
+ } else {
1250
+ _importResolve({ status: true })
1251
+ }
1252
+ } else {
1253
+ const { tableFullColumn } = internalData
1254
+ $xeTable.preventEvent(null, 'event.import', { file, options, columns: tableFullColumn }, () => {
1255
+ const reader = new FileReader()
1256
+ reader.onerror = () => {
1257
+ errLog('vxe.error.notType', [type])
1258
+ _importReject({ status: false, msg: 'reading file error' })
1259
+ }
1260
+ reader.onload = (e: any) => {
1261
+ handleImport(e.target.result, options)
1262
+ }
1263
+ reader.readAsText(file, options.encoding || 'UTF-8')
1264
+ })
1265
+ }
1266
+ } else {
1267
+ // 不支持的浏览器
1268
+ errLog('vxe.error.notExp')
1269
+ _importResolve({ status: false, msg: 'unsupported browser' })
1270
+ }
1271
+ })
1272
+
1273
+ return rest
1274
+ .then(() => {
1275
+ if (afterImportMethod) {
1276
+ afterImportMethod({ status: true, options: opts, $table: $xeTable })
1277
+ }
1278
+ })
1279
+ .catch((e) => {
1280
+ if (afterImportMethod) {
1281
+ afterImportMethod({ status: false, options: opts, $table: $xeTable })
1282
+ }
1283
+ return Promise.reject(e)
1284
+ })
1285
+ }
1286
+
1287
+ const handleFilterColumns = (exportOpts: VxeTablePropTypes.ExportConfig, column: VxeTableDefines.ColumnInfo, columns: VxeTableDefines.ColumnInfo[] | VxeTablePropTypes.ExportOrPrintColumnOption[]) => {
1288
+ return columns.some((item: any) => {
1289
+ if (isColumnInfo(item)) {
1290
+ return column.id === (item as any).id
1291
+ } else if (XEUtils.isString(item)) {
1292
+ return column.field === item
1293
+ } else {
1294
+ const colid = item.id || item.colId
1295
+ const type = item.type
1296
+ const field = item.field
1297
+ if (colid) {
1298
+ return column.id === colid
1299
+ } else if (field && type) {
1300
+ return column.field === field && column.type === type
1301
+ } else if (field) {
1302
+ return column.field === field
1303
+ } else if (type) {
1304
+ return column.type === type
1305
+ }
1306
+ }
1307
+ return false
1308
+ })
1309
+ }
1310
+
1311
+ const handleFilterFields = (exportOpts: VxeTablePropTypes.ExportConfig, column: VxeTableDefines.ColumnInfo, includeFields: string[] | undefined, includeFdMaps: Record<string, number>, excludeFdMaps: Record<string, number>, extraFdMaps: Record<string, number>) => {
1312
+ const { field } = column
1313
+ if (excludeFdMaps[field]) {
1314
+ return false
1315
+ }
1316
+ if (includeFields) {
1317
+ if (includeFdMaps[field]) {
1318
+ return true
1319
+ }
1320
+ return false
1321
+ }
1322
+ if (extraFdMaps[field]) {
1323
+ return true
1324
+ }
1325
+ return exportOpts.original ? !!field : defaultFilterExportColumn(column)
1326
+ }
1327
+
1328
+ const handleExportAndPrint = (options: VxeTablePropTypes.ExportOpts | VxeTablePropTypes.ExportConfig, isPrint?: boolean) => {
1329
+ const $xeGrid = $xeTable.xeGrid
1330
+ const $xeGantt = $xeTable.xeGantt
1331
+ const $xeGGWrapper = $xeGrid || $xeGantt
1332
+
1333
+ const { treeConfig, showHeader, showFooter } = props
1334
+ const { initStore, isGroup, rowGroupList, footerTableData, exportStore, exportParams } = reactData
1335
+ const { collectColumn, mergeBodyList, mergeFooterList } = internalData
1336
+ const exportOpts = computeExportOpts.value
1337
+ const printOpts = computePrintOpts.value
1338
+ const hasTree = !!treeConfig
1339
+ const hasRowGroup = rowGroupList.length > 0
1340
+ const selectRecords = $xeTable.getCheckboxRecords()
1341
+ const proxyOpts = $xeGGWrapper ? $xeGGWrapper.getComputeMaps().computeProxyOpts.value : ({} as VxeGridPropTypes.ProxyOpts)
1342
+ const hasFooter = !!footerTableData.length
1343
+ const hasMerge = !!(mergeBodyList.length || mergeFooterList.length)
1344
+ const defOpts = Object.assign(
1345
+ {
1346
+ message: true,
1347
+ isHeader: showHeader,
1348
+ isTitle: showHeader,
1349
+ isFooter: showFooter,
1350
+ isColgroup: isGroup,
1351
+ isMerge: hasMerge,
1352
+ useStyle: true,
1353
+ current: 'current',
1354
+ modes: (proxyOpts.ajax && proxyOpts.ajax.queryAll ? ['all'] : []).concat(['current', 'selected', 'empty'])
1355
+ },
1356
+ options
1357
+ )
1358
+
1359
+ // 已废弃,参数 isAllExpand
1360
+ if (XEUtils.isBoolean((defOpts as any).isAllExpand)) {
1361
+ warnLog('vxe.error.delProp', ['isAllExpand', 'isTreeAllExpanded'])
1362
+ defOpts.isTreeAllExpanded = (defOpts as any).isAllExpand
1363
+ }
1364
+
1365
+ const types: string[] = isPrint ? [] : defOpts.types || XEUtils.keys(exportOpts._typeMaps)
1366
+ const modes: string[] = defOpts.modes || []
1367
+ const checkMethod = (isPrint ? printOpts : exportOpts).checkMethod
1368
+ const exportColumns = collectColumn.slice(0)
1369
+ const { columns, excludeFields, includeFields, extraFields } = defOpts
1370
+ // 处理类型
1371
+ const typeList = types.map((value) => {
1372
+ return {
1373
+ value,
1374
+ label: getI18n(`vxe.export.types.${value}`)
1375
+ }
1376
+ })
1377
+ const modeList = modes.map((item: any) => {
1378
+ if (item && item.value) {
1379
+ return {
1380
+ value: item.value,
1381
+ label: item.label || item.value
1382
+ }
1383
+ }
1384
+ return {
1385
+ value: item,
1386
+ label: getI18n(`vxe.export.modes.${item}`)
1387
+ }
1388
+ })
1389
+
1390
+ const excludeFdMaps: Record<string, number> = {}
1391
+ if (excludeFields && excludeFields.length) {
1392
+ excludeFields.forEach((field) => {
1393
+ excludeFdMaps[field] = 1
1394
+ })
1395
+ }
1396
+ const includeFdMaps: Record<string, number> = {}
1397
+ if (includeFields && includeFields.length) {
1398
+ includeFields.forEach((field) => {
1399
+ includeFdMaps[field] = 1
1400
+ })
1401
+ }
1402
+ const extraFdMaps: Record<string, number> = {}
1403
+ if (extraFields) {
1404
+ extraFields.forEach((field) => {
1405
+ extraFdMaps[field] = 1
1406
+ })
1407
+ }
1408
+
1409
+ // 默认选中
1410
+ // 优先级 columns > excludeFields > (includeFields || extraFields)
1411
+ XEUtils.eachTree(exportColumns, (column, index, items, path, parentColumn) => {
1412
+ const isColGroup = column.children && column.children.length > 0
1413
+ let isChecked = false
1414
+ const isExtraChecked = extraFdMaps[column.field]
1415
+ if (columns) {
1416
+ isChecked = handleFilterColumns(defOpts, column, columns)
1417
+ } else if (excludeFields || includeFields) {
1418
+ isChecked = handleFilterFields(defOpts, column, includeFields, includeFdMaps, excludeFdMaps, extraFdMaps)
1419
+ } else {
1420
+ if (isExtraChecked) {
1421
+ isChecked = true
1422
+ } else {
1423
+ isChecked = column.visible && (isColGroup || defaultFilterExportColumn(column))
1424
+ }
1425
+ }
1426
+ column.checked = isChecked
1427
+ column.halfChecked = false
1428
+ column.disabled = (parentColumn && parentColumn.disabled) || (checkMethod ? !checkMethod({ $table: $xeTable, column }) : false)
1429
+ })
1430
+ // 更新条件
1431
+ exportStore.columns = exportColumns
1432
+ exportStore.typeList = typeList
1433
+ exportStore.modeList = modeList
1434
+ exportStore.hasFooter = hasFooter
1435
+ exportStore.hasMerge = hasMerge
1436
+ exportStore.hasTree = hasTree
1437
+ exportStore.hasRowGroup = hasRowGroup
1438
+ exportStore.isPrint = !!isPrint
1439
+ exportStore.hasColgroup = isGroup
1440
+ exportStore.visible = true
1441
+ // 默认参数
1442
+ Object.assign(exportParams, {
1443
+ mode: selectRecords.length ? 'selected' : 'current'
1444
+ }, defOpts)
1445
+ const { filename, sheetName, mode, type } = exportParams
1446
+ if (filename) {
1447
+ if (XEUtils.isFunction(filename)) {
1448
+ exportParams.filename = filename({
1449
+ options: defOpts,
1450
+ $table: $xeTable,
1451
+ $grid: $xeGrid,
1452
+ $gantt: $xeGantt
1453
+ })
1454
+ } else {
1455
+ exportParams.filename = `${filename}`
1456
+ }
1457
+ }
1458
+ if (sheetName) {
1459
+ if (XEUtils.isFunction(sheetName)) {
1460
+ exportParams.sheetName = sheetName({
1461
+ options: defOpts,
1462
+ $table: $xeTable,
1463
+ $grid: $xeGrid,
1464
+ $gantt: $xeGantt
1465
+ })
1466
+ } else {
1467
+ exportParams.sheetName = `${sheetName}`
1468
+ }
1469
+ }
1470
+ if (!modeList.some((item) => item.value === mode)) {
1471
+ exportParams.mode = modeList.length ? modeList[0].value : ''
1472
+ }
1473
+ if (!typeList.some((item) => item.value === type)) {
1474
+ exportParams.type = typeList.length ? typeList[0].value : ''
1475
+ }
1476
+ if (!exportParams.widthMode) {
1477
+ exportParams.widthMode = ''
1478
+ }
1479
+ initStore.export = true
1480
+ return nextTick()
1481
+ }
1482
+
1483
+ const handleCloseExport = () => {
1484
+ if (VxeUI.modal) {
1485
+ return VxeUI.modal.close('VXE_EXPORT_MODAL')
1486
+ }
1487
+ return Promise.resolve()
1488
+ }
1489
+
1490
+ const exportMethods: TableExportMethods = {
1491
+ /**
1492
+ * 导出文件,支持 csv/html/xml/txt
1493
+ * 如果是树表格,则默认是导出所有节点
1494
+ * 如果是启用了虚拟滚动,则只能导出数据源,可以配合 dataFilterMethod 函数转换数据
1495
+ * @param {Object} options 参数
1496
+ */
1497
+ exportData(options) {
1498
+ const $xeGrid = $xeTable.xeGrid
1499
+ const $xeGantt = $xeTable.xeGantt
1500
+ const $xeGGWrapper = $xeGrid || $xeGantt
1501
+
1502
+ const { treeConfig, showHeader, showFooter } = props
1503
+ const { isGroup } = reactData
1504
+ const { tableFullColumn, afterFullData, afterTreeFullData, collectColumn, mergeBodyList, mergeFooterList } = internalData
1505
+ const exportOpts = computeExportOpts.value
1506
+ const treeOpts = computeTreeOpts.value
1507
+ const proxyOpts = $xeGGWrapper ? $xeGGWrapper.getComputeMaps().computeProxyOpts.value : ({} as VxeGridPropTypes.ProxyOpts)
1508
+ const hasMerge = !!(mergeBodyList.length || mergeFooterList.length)
1509
+ const opts = Object.assign(
1510
+ {
1511
+ message: true,
1512
+ isHeader: showHeader,
1513
+ isTitle: showHeader,
1514
+ isFooter: showFooter,
1515
+ isColgroup: isGroup,
1516
+ isMerge: hasMerge,
1517
+ useStyle: true,
1518
+ current: 'current',
1519
+ modes: (proxyOpts.ajax && proxyOpts.ajax.queryAll ? ['all'] : []).concat(['current', 'selected', 'empty']),
1520
+ download: true,
1521
+ type: 'csv'
1522
+ // filename: '',
1523
+ // sheetName: '',
1524
+ // original: false,
1525
+ // isTreeAllExpanded: false,
1526
+ // isRowGroupAllExpanded: false,
1527
+ // data: null,
1528
+ // remote: false,
1529
+ // dataFilterMethod: null,
1530
+ // footerFilterMethod: null,
1531
+ // exportMethod: null,
1532
+ // columnFilterMethod: null,
1533
+ // beforeExportMethod: null,
1534
+ // afterExportMethod: null
1535
+ },
1536
+ exportOpts,
1537
+ options
1538
+ )
1539
+
1540
+ // 已废弃,参数 isAllExpand
1541
+ if (XEUtils.isBoolean((opts as any).isAllExpand)) {
1542
+ warnLog('vxe.error.delProp', ['isAllExpand', 'isTreeAllExpanded'])
1543
+ opts.isTreeAllExpanded = (opts as any).isAllExpand
1544
+ }
1545
+
1546
+ let { filename, sheetName, type, mode, columns, columnFilterMethod, beforeExportMethod, includeFields, excludeFields, extraFields } = opts
1547
+ let groups: any[] = []
1548
+ const selectRecords = $xeTable.getCheckboxRecords()
1549
+ if (!mode) {
1550
+ mode = selectRecords.length ? 'selected' : 'current'
1551
+ }
1552
+
1553
+ const excludeFdMaps: Record<string, number> = {}
1554
+ if (excludeFields && excludeFields.length) {
1555
+ excludeFields.forEach((field) => {
1556
+ excludeFdMaps[field] = 1
1557
+ })
1558
+ }
1559
+ const includeFdMaps: Record<string, number> = {}
1560
+ if (includeFields && includeFields.length) {
1561
+ includeFields.forEach((field) => {
1562
+ includeFdMaps[field] = 1
1563
+ })
1564
+ }
1565
+ const extraFdMaps: Record<string, number> = {}
1566
+ if (extraFields) {
1567
+ extraFields.forEach((field) => {
1568
+ extraFdMaps[field] = 1
1569
+ })
1570
+ }
1571
+
1572
+ let isCustomCol = false
1573
+ let customCols = []
1574
+ const _columns = (opts as any)._columns
1575
+ if (_columns) {
1576
+ // 内部导出使用 _columns -> _children 为自定义子集
1577
+ isCustomCol = true
1578
+ customCols = XEUtils.searchTree(_columns, () => true, { children: '_children', mapChildren: 'childNodes', original: true })
1579
+ } else if (columns) {
1580
+ isCustomCol = true
1581
+ customCols = XEUtils.searchTree(columns, () => true, { children: 'children', mapChildren: 'childNodes', original: true })
1582
+ } else {
1583
+ customCols = XEUtils.searchTree(
1584
+ collectColumn,
1585
+ (column) => {
1586
+ const isColGroup = column.children && column.children.length > 0
1587
+ let isChecked = false
1588
+ const isExtraChecked = extraFdMaps[column.field]
1589
+ if (columns) {
1590
+ isChecked = handleFilterColumns(opts, column, columns)
1591
+ } else if (excludeFields || includeFields) {
1592
+ isChecked = handleFilterFields(opts, column, includeFields, includeFdMaps, excludeFdMaps, extraFdMaps)
1593
+ } else {
1594
+ if (isExtraChecked) {
1595
+ isChecked = true
1596
+ } else {
1597
+ isChecked = column.visible && (isColGroup || defaultFilterExportColumn(column))
1598
+ }
1599
+ }
1600
+ return isChecked
1601
+ },
1602
+ { children: 'children', mapChildren: 'childNodes', original: true }
1603
+ )
1604
+ }
1605
+ const handleOptions: VxeTablePropTypes.ExportHandleOptions = Object.assign({} as { data: any[]; colgroups: any[]; columns: any[] }, opts, { filename: '', sheetName: '', _columnConfs: columns })
1606
+ // 如果设置源数据,则默认导出设置了字段的列
1607
+ if (!isCustomCol && !columnFilterMethod) {
1608
+ columnFilterMethod = ({ column }) => handleFilterFields(handleOptions, column, includeFields, includeFdMaps, excludeFdMaps, extraFdMaps)
1609
+ handleOptions.columnFilterMethod = columnFilterMethod
1610
+ }
1611
+ if (customCols) {
1612
+ handleOptions._isCustomColumn = true
1613
+ groups = XEUtils.searchTree(
1614
+ XEUtils.mapTree(
1615
+ customCols,
1616
+ (item) => {
1617
+ let targetColumn
1618
+ if (item) {
1619
+ if (isColumnInfo(item)) {
1620
+ targetColumn = item
1621
+ } else if (XEUtils.isString(item)) {
1622
+ targetColumn = $xeTable.getColumnByField(item)
1623
+ } else {
1624
+ const colid = item.id || item.colId
1625
+ const type = item.type
1626
+ const field = item.field
1627
+ if (colid) {
1628
+ targetColumn = $xeTable.getColumnById(colid)
1629
+ } else if (field && type) {
1630
+ targetColumn = tableFullColumn.find((column) => column.field === field && column.type === type)
1631
+ } else if (field) {
1632
+ targetColumn = $xeTable.getColumnByField(field)
1633
+ } else if (type) {
1634
+ targetColumn = tableFullColumn.find((column) => column.type === type)
1635
+ }
1636
+ }
1637
+ return targetColumn || {}
1638
+ }
1639
+ },
1640
+ {
1641
+ children: 'childNodes',
1642
+ mapChildren: '_children'
1643
+ }
1644
+ ),
1645
+ (column, index) => isColumnInfo(column) && (!columnFilterMethod || columnFilterMethod({ $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt, column: column as any, $columnIndex: index })),
1646
+ {
1647
+ children: '_children',
1648
+ mapChildren: 'childNodes',
1649
+ original: true
1650
+ }
1651
+ )
1652
+ } else {
1653
+ groups = XEUtils.searchTree(isGroup ? collectColumn : tableFullColumn, (column, index) => column.visible && (!columnFilterMethod || columnFilterMethod({ $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt, column, $columnIndex: index })), {
1654
+ children: 'children',
1655
+ mapChildren: 'childNodes',
1656
+ original: true
1657
+ })
1658
+ }
1659
+ // 获取所有列
1660
+ const cols: VxeTableDefines.ColumnInfo[] = []
1661
+ XEUtils.eachTree(
1662
+ groups,
1663
+ (column) => {
1664
+ const isColGroup = column.children && column.children.length
1665
+ if (!isColGroup) {
1666
+ cols.push(column)
1667
+ }
1668
+ },
1669
+ { children: 'childNodes' }
1670
+ )
1671
+ // 构建分组层级
1672
+ handleOptions.columns = cols
1673
+ handleOptions.colgroups = convertToRows(groups)
1674
+ if (filename) {
1675
+ if (XEUtils.isFunction(filename)) {
1676
+ handleOptions.filename = filename({
1677
+ options: opts,
1678
+ $table: $xeTable,
1679
+ $grid: $xeGrid,
1680
+ $gantt: $xeGantt
1681
+ })
1682
+ } else {
1683
+ handleOptions.filename = `${filename}`
1684
+ }
1685
+ }
1686
+ if (!handleOptions.filename) {
1687
+ handleOptions.filename = getI18n(handleOptions.original ? 'vxe.table.expOriginFilename' : 'vxe.table.expFilename', [XEUtils.toDateString(Date.now(), 'yyyyMMddHHmmss')])
1688
+ }
1689
+
1690
+ if (sheetName) {
1691
+ if (XEUtils.isFunction(sheetName)) {
1692
+ handleOptions.sheetName = sheetName({
1693
+ options: opts,
1694
+ $table: $xeTable,
1695
+ $grid: $xeGrid,
1696
+ $gantt: $xeGantt
1697
+ })
1698
+ } else {
1699
+ handleOptions.sheetName = `${sheetName}`
1700
+ }
1701
+ }
1702
+ if (!handleOptions.sheetName) {
1703
+ handleOptions.sheetName = document.title || ''
1704
+ }
1705
+
1706
+ // 检查类型,如果为自定义导出,则不需要校验类型
1707
+ if (!handleOptions.exportMethod && !XEUtils.includes(XEUtils.keys(exportOpts._typeMaps), type)) {
1708
+ errLog('vxe.error.notType', [type])
1709
+ if (['xlsx', 'pdf'].includes(type)) {
1710
+ warnLog('vxe.error.reqPlugin', [4, 'plugin-export-xlsx'])
1711
+ }
1712
+ const params = { status: false, msg: 'type error' }
1713
+ return Promise.reject(params)
1714
+ }
1715
+
1716
+ if (!handleOptions.print) {
1717
+ if (beforeExportMethod) {
1718
+ const beRest = beforeExportMethod({ options: handleOptions, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt })
1719
+ if (XEUtils.isBoolean(beRest)) {
1720
+ if (!beRest) {
1721
+ const params = { status: false, msg: 'before prevent' }
1722
+ return Promise.reject(params)
1723
+ }
1724
+ } else {
1725
+ warnLog('vxe.error.returnErr', ['beforeExportMethod', 'boolean', beRest])
1726
+ }
1727
+ }
1728
+ }
1729
+ if (!handleOptions.data) {
1730
+ handleOptions.data = []
1731
+ if (mode === 'selected') {
1732
+ if (['html', 'pdf'].indexOf(type) > -1 && treeConfig) {
1733
+ handleOptions.data = XEUtils.searchTree($xeTable.getTableData().fullData, (item) => $xeTable.findRowIndexOf(selectRecords, item) > -1, Object.assign({}, treeOpts, { data: '_row' }))
1734
+ } else {
1735
+ handleOptions.data = selectRecords
1736
+ }
1737
+ } else if (mode === 'all') {
1738
+ if (!$xeGGWrapper) {
1739
+ errLog('vxe.error.errProp', ['all', 'mode=current,selected'])
1740
+ }
1741
+
1742
+ if ($xeGGWrapper && !handleOptions.remote) {
1743
+ const gridReactData = $xeGGWrapper.reactData
1744
+ const { computeProxyOpts } = $xeGGWrapper.getComputeMaps()
1745
+ const proxyOpts = computeProxyOpts.value
1746
+ const { sortData } = gridReactData
1747
+ const { beforeQueryAll: oldBeforeQueryAll, afterQueryAll: oldAfterQueryAll, ajax = {} } = proxyOpts
1748
+ const resConfigs = proxyOpts.response || proxyOpts.props || {}
1749
+ const beforeQueryAllMethod = ajax.beforeQueryAll
1750
+ const queryAllMethod = ajax.queryAll
1751
+ const afterQueryAllMethod = ajax.afterQueryAll
1752
+ const queryAllSuccessMethod = ajax.queryAllSuccess
1753
+ const queryAllErrorMethod = ajax.queryAllError
1754
+
1755
+ if (!queryAllMethod) {
1756
+ errLog('vxe.error.notFunc', ['proxy-config.ajax.queryAll'])
1757
+ }
1758
+
1759
+ if (queryAllMethod) {
1760
+ const params = {
1761
+ $table: $xeTable,
1762
+ $grid: $xeGrid,
1763
+ $gantt: $xeGantt,
1764
+ sort: sortData.length ? sortData[0] : ({} as any),
1765
+ sorts: sortData as any[],
1766
+ filters: gridReactData.filterData,
1767
+ form: gridReactData.formData,
1768
+ options: handleOptions
1769
+ }
1770
+
1771
+ const handleQueryAll = () => {
1772
+ return Promise.resolve((oldBeforeQueryAll || queryAllMethod)(params))
1773
+ .then((rest) => {
1774
+ if (afterQueryAllMethod) {
1775
+ afterQueryAllMethod({ ...params, response: rest, status: 'success' })
1776
+ } else {
1777
+ const listProp = resConfigs.list
1778
+ let tdData: any[] = []
1779
+ if (listProp) {
1780
+ if (XEUtils.isFunction(listProp)) {
1781
+ tdData = listProp({ data: rest, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt })
1782
+ } else {
1783
+ tdData = XEUtils.isArray(rest) ? rest : XEUtils.get(rest, listProp)
1784
+ }
1785
+ } else {
1786
+ if (XEUtils.isArray(rest)) {
1787
+ tdData = rest
1788
+ }
1789
+ }
1790
+ handleOptions.data = tdData
1791
+ if (oldAfterQueryAll) {
1792
+ oldAfterQueryAll({ ...params, response: rest })
1793
+ }
1794
+ }
1795
+ if (queryAllSuccessMethod) {
1796
+ queryAllSuccessMethod({ ...params, response: rest })
1797
+ }
1798
+ return handleExport(handleOptions)
1799
+ })
1800
+ .catch((rest) => {
1801
+ if (afterQueryAllMethod) {
1802
+ afterQueryAllMethod({ ...params, response: rest, status: 'error' })
1803
+ }
1804
+ if (queryAllErrorMethod) {
1805
+ queryAllErrorMethod({ ...params, response: rest })
1806
+ }
1807
+ })
1808
+ }
1809
+
1810
+ if (beforeQueryAllMethod) {
1811
+ return Promise.resolve(beforeQueryAllMethod(params)).then((status) => {
1812
+ if (status !== false) {
1813
+ return handleQueryAll()
1814
+ }
1815
+ })
1816
+ }
1817
+ return handleQueryAll()
1818
+ }
1819
+ }
1820
+ }
1821
+ if (mode === 'current') {
1822
+ handleOptions.data = treeConfig ? afterTreeFullData : afterFullData
1823
+ }
1824
+ } else {
1825
+ handleOptions._isCustomData = true
1826
+ }
1827
+ return handleExport(handleOptions)
1828
+ },
1829
+ importByFile(file, options) {
1830
+ const opts = Object.assign({}, options)
1831
+ const { beforeImportMethod } = opts
1832
+ if (beforeImportMethod) {
1833
+ const biRest = beforeImportMethod({ options: opts, $table: $xeTable })
1834
+ if (XEUtils.isBoolean(biRest)) {
1835
+ if (!biRest) {
1836
+ const params = { status: false, mas: 'before prevent' }
1837
+ return Promise.reject(params)
1838
+ }
1839
+ } else {
1840
+ warnLog('vxe.error.returnErr', ['beforeImportMethod', 'boolean', biRest])
1841
+ }
1842
+ }
1843
+ return handleFileImport(file, opts)
1844
+ },
1845
+ importData(options) {
1846
+ const importOpts = computeImportOpts.value
1847
+ const opts = Object.assign(
1848
+ {
1849
+ types: XEUtils.keys(importOpts._typeMaps)
1850
+ // beforeImportMethod: null,
1851
+ // afterImportMethod: null
1852
+ },
1853
+ importOpts,
1854
+ options
1855
+ )
1856
+ const { beforeImportMethod, afterImportMethod } = opts
1857
+ if (beforeImportMethod) {
1858
+ const biRest = beforeImportMethod({ options: opts, $table: $xeTable })
1859
+ if (XEUtils.isBoolean(biRest)) {
1860
+ if (!biRest) {
1861
+ const params = { status: false, mas: 'before prevent' }
1862
+ return Promise.reject(params)
1863
+ }
1864
+ } else {
1865
+ warnLog('vxe.error.returnErr', ['beforeImportMethod', 'boolean', biRest])
1866
+ }
1867
+ }
1868
+ return VxeUI.readFile(opts)
1869
+ .catch((e) => {
1870
+ if (afterImportMethod) {
1871
+ afterImportMethod({ status: false, options: opts, $table: $xeTable })
1872
+ }
1873
+ return Promise.reject(e)
1874
+ })
1875
+ .then((params) => {
1876
+ const { file } = params
1877
+ return handleFileImport(file, opts)
1878
+ })
1879
+ },
1880
+ saveFile(options) {
1881
+ return VxeUI.saveFile(options)
1882
+ },
1883
+ readFile(options) {
1884
+ return VxeUI.readFile(options)
1885
+ },
1886
+ print(options) {
1887
+ const $xeGrid = $xeTable.xeGrid
1888
+ const $xeGantt = $xeTable.xeGantt
1889
+
1890
+ const printOpts = computePrintOpts.value
1891
+ const opts = Object.assign(
1892
+ {
1893
+ original: false
1894
+ // beforePrintMethod
1895
+ },
1896
+ printOpts,
1897
+ options,
1898
+ {
1899
+ type: 'html',
1900
+ download: false,
1901
+ remote: false,
1902
+ print: true
1903
+ }
1904
+ )
1905
+ const { sheetName } = opts
1906
+ let printTitle = ''
1907
+ if (sheetName) {
1908
+ if (XEUtils.isFunction(sheetName)) {
1909
+ printTitle = sheetName({
1910
+ options: opts,
1911
+ $table: $xeTable,
1912
+ $grid: $xeGrid,
1913
+ $gantt: $xeGantt
1914
+ })
1915
+ } else {
1916
+ printTitle = `${sheetName}`
1917
+ }
1918
+ }
1919
+ if (!printTitle) {
1920
+ printTitle = document.title || ''
1921
+ }
1922
+
1923
+ const beforePrintMethod = opts.beforePrintMethod
1924
+ const printMethod = opts.printMethod
1925
+ const tableHtml = opts.html || opts.content
1926
+ return new Promise((resolve, reject) => {
1927
+ if (VxeUI.print) {
1928
+ if (tableHtml) {
1929
+ resolve(
1930
+ VxeUI.print({
1931
+ title: printTitle,
1932
+ html: tableHtml,
1933
+ customStyle: opts.style,
1934
+ beforeMethod: beforePrintMethod
1935
+ ? ({ html }) => {
1936
+ return beforePrintMethod({
1937
+ html,
1938
+ content: html,
1939
+ options: opts,
1940
+ $table: $xeTable,
1941
+ $grid: $xeGrid,
1942
+ $gantt: $xeGantt
1943
+ })
1944
+ }
1945
+ : undefined,
1946
+ beforePrintMethod: beforePrintMethod
1947
+ ? ({ html }) => {
1948
+ return beforePrintMethod({
1949
+ html,
1950
+ content: html,
1951
+ options: opts,
1952
+ $table: $xeTable,
1953
+ $grid: $xeGrid,
1954
+ $gantt: $xeGantt
1955
+ })
1956
+ }
1957
+ : undefined,
1958
+ printMethod: printMethod
1959
+ ? ({ html }) => {
1960
+ return printMethod({
1961
+ html,
1962
+ content: html,
1963
+ options: opts,
1964
+ $table: $xeTable,
1965
+ $grid: $xeGrid,
1966
+ $gantt: $xeGantt
1967
+ })
1968
+ }
1969
+ : undefined
1970
+ })
1971
+ )
1972
+ } else {
1973
+ resolve(
1974
+ exportMethods.exportData(opts).then(({ content }: any) => {
1975
+ return VxeUI.print({
1976
+ title: printTitle,
1977
+ html: content,
1978
+ customStyle: opts.style,
1979
+ beforeMethod: beforePrintMethod
1980
+ ? ({ html }) => {
1981
+ return beforePrintMethod({
1982
+ html,
1983
+ content: html,
1984
+ options: opts,
1985
+ $table: $xeTable,
1986
+ $grid: $xeGrid,
1987
+ $gantt: $xeGantt
1988
+ })
1989
+ }
1990
+ : undefined,
1991
+ beforePrintMethod: beforePrintMethod
1992
+ ? ({ html }) => {
1993
+ return beforePrintMethod({
1994
+ html,
1995
+ content: html,
1996
+ options: opts,
1997
+ $table: $xeTable,
1998
+ $grid: $xeGrid,
1999
+ $gantt: $xeGantt
2000
+ })
2001
+ }
2002
+ : undefined,
2003
+ printMethod: printMethod
2004
+ ? ({ html }) => {
2005
+ return printMethod({
2006
+ html,
2007
+ content: html,
2008
+ options: opts,
2009
+ $table: $xeTable,
2010
+ $grid: $xeGrid,
2011
+ $gantt: $xeGantt
2012
+ })
2013
+ }
2014
+ : undefined
2015
+ })
2016
+ })
2017
+ )
2018
+ }
2019
+ } else {
2020
+ errLog('vxe.error.reqComp', ['vxe-print'])
2021
+ const e = { status: false, msg: 'print not exist' }
2022
+ reject(e)
2023
+ }
2024
+ })
2025
+ },
2026
+ getPrintHtml(options) {
2027
+ const printOpts = computePrintOpts.value
2028
+ const opts = Object.assign(
2029
+ {
2030
+ original: false
2031
+ // beforePrintMethod
2032
+ },
2033
+ printOpts,
2034
+ options,
2035
+ {
2036
+ type: 'html',
2037
+ download: false,
2038
+ remote: false,
2039
+ print: true
2040
+ }
2041
+ )
2042
+ return $xeTable.exportData(opts).then(({ content }) => {
2043
+ return {
2044
+ html: content
2045
+ }
2046
+ })
2047
+ },
2048
+ closeImport() {
2049
+ if (VxeUI.modal) {
2050
+ return VxeUI.modal.close('VXE_IMPORT_MODAL')
2051
+ }
2052
+ return Promise.resolve()
2053
+ },
2054
+ openImport(options) {
2055
+ const { treeConfig, importConfig } = props
2056
+ const { initStore, importStore, importParams } = reactData
2057
+ const importOpts = computeImportOpts.value
2058
+ const defOpts = Object.assign(
2059
+ {
2060
+ mode: 'insertTop',
2061
+ message: true,
2062
+ types: XEUtils.keys(importOpts._typeMaps),
2063
+ modes: ['insertTop', 'covering']
2064
+ },
2065
+ importOpts,
2066
+ options
2067
+ )
2068
+ const types = defOpts.types || []
2069
+ const modes = defOpts.modes || []
2070
+ const isTree = !!treeConfig
2071
+ if (isTree) {
2072
+ if (defOpts.message) {
2073
+ if (VxeUI.modal) {
2074
+ VxeUI.modal.message({ content: getI18n('vxe.error.treeNotImp'), status: 'error' })
2075
+ }
2076
+ }
2077
+ return
2078
+ }
2079
+ if (!hasEnableConf(importConfig, importOpts)) {
2080
+ errLog('vxe.error.reqProp', ['import-config'])
2081
+ }
2082
+ // 处理类型
2083
+ const typeList = types.map((value) => {
2084
+ return {
2085
+ value,
2086
+ label: getI18n(`vxe.export.types.${value}`)
2087
+ }
2088
+ })
2089
+ const modeList = modes.map((item: any) => {
2090
+ if (item && item.value) {
2091
+ return {
2092
+ value: item.value,
2093
+ label: item.label || item.value
2094
+ }
2095
+ }
2096
+ return {
2097
+ value: item,
2098
+ label: getI18n(`vxe.import.modes.${item}`)
2099
+ }
2100
+ })
2101
+ Object.assign(importStore, {
2102
+ file: null,
2103
+ type: '',
2104
+ filename: '',
2105
+ modeList,
2106
+ typeList,
2107
+ visible: true
2108
+ })
2109
+ Object.assign(importParams, defOpts)
2110
+ if (!modeList.some((item) => item.value === importParams.mode)) {
2111
+ importParams.mode = modeList[0].value
2112
+ }
2113
+ initStore.import = true
2114
+ },
2115
+ closeExport: handleCloseExport,
2116
+ openExport(options) {
2117
+ const { exportConfig } = props
2118
+ const exportOpts = computeExportOpts.value
2119
+ const defOpts = Object.assign(
2120
+ {
2121
+ message: true,
2122
+ types: XEUtils.keys(exportOpts._typeMaps)
2123
+ },
2124
+ exportOpts,
2125
+ options
2126
+ )
2127
+ if (!hasEnableConf(exportConfig, exportOpts)) {
2128
+ errLog('vxe.error.reqProp', ['export-config'])
2129
+ }
2130
+ return handleExportAndPrint(defOpts)
2131
+ },
2132
+ closePrint: handleCloseExport,
2133
+ openPrint(options) {
2134
+ const { printConfig } = props
2135
+ const printOpts = computePrintOpts.value
2136
+ const defOpts = Object.assign(
2137
+ {
2138
+ message: true
2139
+ },
2140
+ printOpts,
2141
+ options
2142
+ )
2143
+ if (!hasEnableConf(printConfig, printOpts)) {
2144
+ errLog('vxe.error.reqProp', ['print-config'])
2145
+ }
2146
+ return handleExportAndPrint(defOpts, true)
2147
+ }
2148
+ }
2149
+
2150
+ return exportMethods
2151
+ },
2152
+ setupGrid($xeGrid) {
2153
+ return $xeGrid.extendTableMethods(tableExportMethodKeys)
2154
+ },
2155
+ setupGantt($xeGantt) {
2156
+ return $xeGantt.extendTableMethods(tableExportMethodKeys)
2157
+ }
2158
+ })