vxe-table 3.12.0-beta.9 → 3.12.0

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 (75) hide show
  1. package/es/locale/lang/de-DE.js +490 -490
  2. package/es/locale/lang/en-US.js +438 -438
  3. package/es/locale/lang/it-IT.js +692 -0
  4. package/es/locale/lang/ru-RU.js +36 -36
  5. package/es/locale/lang/th-TH.js +692 -0
  6. package/es/locale/lang/zh-CHT.js +19 -19
  7. package/es/style.css +1 -1
  8. package/es/table/module/custom/panel.js +5 -5
  9. package/es/table/module/export/mixin.js +208 -140
  10. package/es/table/src/cell.js +88 -61
  11. package/es/table/src/column.js +2 -2
  12. package/es/table/src/group.js +2 -2
  13. package/es/table/src/methods.js +112 -87
  14. package/es/table/src/table.js +7 -11
  15. package/es/toolbar/src/toolbar.js +22 -4
  16. package/es/ui/index.js +2 -2
  17. package/es/ui/src/log.js +1 -1
  18. package/es/ui/src/vn.js +3 -0
  19. package/lib/index.umd.js +512 -356
  20. package/lib/index.umd.min.js +1 -1
  21. package/lib/locale/lang/de-DE.js +490 -490
  22. package/lib/locale/lang/de-DE.min.js +1 -1
  23. package/lib/locale/lang/en-US.js +438 -438
  24. package/lib/locale/lang/en-US.min.js +1 -1
  25. package/lib/locale/lang/en-US.umd.js +438 -438
  26. package/lib/locale/lang/it-IT.js +698 -0
  27. package/lib/locale/lang/it-IT.min.js +1 -0
  28. package/lib/locale/lang/ru-RU.js +36 -36
  29. package/lib/locale/lang/ru-RU.min.js +1 -1
  30. package/lib/locale/lang/ru-RU.umd.js +36 -36
  31. package/lib/locale/lang/th-TH.js +698 -0
  32. package/lib/locale/lang/th-TH.min.js +1 -0
  33. package/lib/locale/lang/zh-CHT.js +19 -19
  34. package/lib/locale/lang/zh-CHT.min.js +1 -1
  35. package/lib/locale/lang/zh-CHT.umd.js +19 -19
  36. package/lib/style.css +1 -1
  37. package/lib/table/module/custom/panel.js +5 -5
  38. package/lib/table/module/custom/panel.min.js +1 -1
  39. package/lib/table/module/export/mixin.js +239 -167
  40. package/lib/table/module/export/mixin.min.js +1 -1
  41. package/lib/table/src/cell.js +109 -83
  42. package/lib/table/src/cell.min.js +1 -1
  43. package/lib/table/src/methods.js +112 -87
  44. package/lib/table/src/methods.min.js +1 -1
  45. package/lib/table/src/table.js +4 -9
  46. package/lib/table/src/table.min.js +1 -1
  47. package/lib/toolbar/src/toolbar.js +36 -2
  48. package/lib/toolbar/src/toolbar.min.js +1 -1
  49. package/lib/ui/index.js +2 -2
  50. package/lib/ui/index.min.js +1 -1
  51. package/lib/ui/src/log.js +1 -1
  52. package/lib/ui/src/log.min.js +1 -1
  53. package/lib/ui/src/vn.js +3 -0
  54. package/lib/ui/src/vn.min.js +1 -1
  55. package/package.json +3 -3
  56. package/packages/locale/lang/de-DE.ts +492 -491
  57. package/packages/locale/lang/en-US.ts +438 -438
  58. package/packages/locale/lang/it-IT.ts +692 -0
  59. package/packages/locale/lang/ru-RU.ts +36 -36
  60. package/packages/locale/lang/th-TH.ts +692 -0
  61. package/packages/locale/lang/zh-CHT.ts +19 -19
  62. package/packages/table/module/custom/panel.ts +5 -5
  63. package/packages/table/module/export/mixin.ts +227 -156
  64. package/packages/table/src/cell.ts +141 -108
  65. package/packages/table/src/methods.ts +136 -105
  66. package/packages/table/src/table.ts +8 -12
  67. package/packages/toolbar/src/toolbar.ts +26 -8
  68. package/packages/ui/index.ts +1 -1
  69. package/packages/ui/src/vn.ts +4 -1
  70. /package/es/{iconfont.1735301172726.ttf → iconfont.1735661059384.ttf} +0 -0
  71. /package/es/{iconfont.1735301172726.woff → iconfont.1735661059384.woff} +0 -0
  72. /package/es/{iconfont.1735301172726.woff2 → iconfont.1735661059384.woff2} +0 -0
  73. /package/lib/{iconfont.1735301172726.ttf → iconfont.1735661059384.ttf} +0 -0
  74. /package/lib/{iconfont.1735301172726.woff → iconfont.1735661059384.woff} +0 -0
  75. /package/lib/{iconfont.1735301172726.woff2 → iconfont.1735661059384.woff2} +0 -0
@@ -2,10 +2,11 @@ import XEUtils from 'xe-utils'
2
2
  import { VxeUI } from '../../../ui'
3
3
  import { isColumnInfo, mergeBodyMethod, getCellValue } from '../../src/util'
4
4
  import { parseFile, formatText, eqEmptyValue } from '../../../ui/src/utils'
5
- import { browse } from '../../../ui/src/dom'
6
5
  import { createHtmlPage, getExportBlobByContent } from './util'
7
6
  import { warnLog, errLog } from '../../../ui/src/log'
8
7
 
8
+ import type { VxeTablePropTypes, VxeGridConstructor, VxeTableDefines, TableReactData, TableInternalData, GridReactData, VxeColumnPropTypes, VxeTableConstructor } from '../../../../types'
9
+
9
10
  const { getI18n, renderer } = VxeUI
10
11
 
11
12
  let htmlCellElem: any
@@ -14,34 +15,25 @@ let htmlCellElem: any
14
15
  let fileForm: any
15
16
  let fileInput: any
16
17
 
17
- // 打印
18
- let printFrame: any
19
-
20
18
  const csvBOM = '\ufeff'
21
19
  const enterSymbol = '\r\n'
22
20
 
23
- function createFrame () {
24
- const frame = document.createElement('iframe')
25
- frame.className = 'vxe-table--print-frame'
26
- return frame
27
- }
28
-
29
- function hasTreeChildren ($xetable: any, row: any) {
30
- const treeOpts = $xetable.treeOpts
21
+ function hasTreeChildren ($xeTable: VxeTableConstructor, row: any) {
22
+ const treeOpts = $xeTable.computeTreeOpts
31
23
  const childrenField = treeOpts.children || treeOpts.childrenField
32
- return row[childrenField] && row[childrenField].length > 0
24
+ return row[childrenField] && row[childrenField].length
33
25
  }
34
26
 
35
- function getSeq ($xetable: any, cellValue: any, row: any, $rowIndex: any, column: any, $columnIndex: any) {
36
- const seqOpts = $xetable.seqOpts
27
+ function getSeq ($xeTable: VxeTableConstructor, cellValue: any, row: any, $rowIndex: any, column: any, $columnIndex: any) {
28
+ const seqOpts = $xeTable.computeSeqOpts
37
29
  const seqMethod = seqOpts.seqMethod || column.seqMethod
38
30
  if (seqMethod) {
39
31
  return seqMethod({
40
32
  row,
41
- rowIndex: $xetable.getRowIndex(row),
33
+ rowIndex: $xeTable.getRowIndex(row),
42
34
  $rowIndex,
43
35
  column,
44
- columnIndex: $xetable.getColumnIndex(column),
36
+ columnIndex: $xeTable.getColumnIndex(column),
45
37
  $columnIndex
46
38
  })
47
39
  }
@@ -70,17 +62,23 @@ const toStringValue = (cellValue: any) => {
70
62
  return eqEmptyValue(cellValue) ? '' : `${cellValue}`
71
63
  }
72
64
 
73
- function getBodyLabelData ($xeTable: any, opts: any, columns: any[], datas: any[]) {
65
+ function getBodyLabelData ($xeTable: VxeTableConstructor, opts: VxeTablePropTypes.ExportHandleOptions, columns: VxeTableDefines.ColumnInfo[], datas: any[]) {
66
+ const props = $xeTable
67
+
74
68
  const { isAllExpand, mode } = opts
75
- const { treeConfig, treeOpts, radioOpts, checkboxOpts, columnOpts } = $xeTable
76
- const childrenField = treeOpts.children || treeOpts.childrenField
69
+ const { treeConfig } = props
70
+ const radioOpts = $xeTable.computeRadioOpts
71
+ const checkboxOpts = $xeTable.computeCheckboxOpts
72
+ const treeOpts = $xeTable.computeTreeOpts
73
+ const columnOpts = $xeTable.computeColumnOpts
77
74
  if (!htmlCellElem) {
78
75
  htmlCellElem = document.createElement('div')
79
76
  }
80
77
  if (treeConfig) {
78
+ const childrenField = treeOpts.children || treeOpts.childrenField
81
79
  // 如果是树表格只允许导出数据源
82
80
  const rest: any[] = []
83
- const expandMaps = new Map()
81
+ const expandMaps: Map<any, number> = new Map()
84
82
  XEUtils.eachTree(datas, (item, $rowIndex, items, path, parent, nodes) => {
85
83
  const row = item._row || item
86
84
  const parentRow = parent && parent._row ? parent._row : parent
@@ -93,13 +91,13 @@ function getBodyLabelData ($xeTable: any, opts: any, columns: any[], datas: any[
93
91
  _expand: hasRowChild && $xeTable.isTreeExpandByRow(row)
94
92
  }
95
93
  columns.forEach((column, $columnIndex) => {
96
- let cellValue = ''
94
+ let cellValue: string | number | boolean | null = ''
97
95
  const renderOpts = column.editRender || column.cellRender
98
- let bodyExportMethod = column.exportMethod
96
+ let bodyExportMethod: VxeColumnPropTypes.ExportMethod | undefined = column.exportMethod || columnOpts.exportMethod
99
97
  if (!bodyExportMethod && renderOpts && renderOpts.name) {
100
98
  const compConf = renderer.get(renderOpts.name)
101
99
  if (compConf) {
102
- bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod || (compConf as any).cellExportMethod
100
+ bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod
103
101
  }
104
102
  }
105
103
  if (!bodyExportMethod) {
@@ -110,8 +108,8 @@ function getBodyLabelData ($xeTable: any, opts: any, columns: any[], datas: any[
110
108
  } else {
111
109
  switch (column.type) {
112
110
  case 'seq': {
113
- const seqValue = path.map((num, i) => i % 2 === 0 ? (Number(num) + 1) : '.').join('')
114
- cellValue = mode === 'all' ? seqValue : getSeq($xeTable, seqValue, row, $rowIndex, column, $columnIndex)
111
+ const seqVal = path.map((num, i) => i % 2 === 0 ? (Number(num) + 1) : '.').join('')
112
+ cellValue = mode === 'all' ? seqVal : getSeq($xeTable, seqVal, row, $rowIndex, column, $columnIndex)
115
113
  break
116
114
  }
117
115
  case 'checkbox':
@@ -154,18 +152,15 @@ function getBodyLabelData ($xeTable: any, opts: any, columns: any[], datas: any[
154
152
  _row: row
155
153
  }
156
154
  columns.forEach((column, $columnIndex) => {
157
- let cellValue = ''
155
+ let cellValue: string | number | boolean | null = ''
158
156
  const renderOpts = column.editRender || column.cellRender
159
- let bodyExportMethod = column.exportMethod
157
+ let bodyExportMethod: VxeColumnPropTypes.ExportMethod | undefined = column.exportMethod || columnOpts.exportMethod
160
158
  if (!bodyExportMethod && renderOpts && renderOpts.name) {
161
159
  const compConf = renderer.get(renderOpts.name)
162
160
  if (compConf) {
163
- bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod || (compConf as any).cellExportMethod
161
+ bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod
164
162
  }
165
163
  }
166
- if (!bodyExportMethod) {
167
- bodyExportMethod = columnOpts.exportMethod
168
- }
169
164
  if (bodyExportMethod) {
170
165
  cellValue = bodyExportMethod({ $table: $xeTable, row, column, options: opts })
171
166
  } else {
@@ -185,7 +180,7 @@ function getBodyLabelData ($xeTable: any, opts: any, columns: any[], datas: any[
185
180
  item._radioLabel = radioOpts.labelField ? XEUtils.get(row, radioOpts.labelField) : ''
186
181
  item._radioDisabled = radioOpts.checkMethod && !radioOpts.checkMethod({ row })
187
182
  break
188
- default :
183
+ default:
189
184
  if (opts.original) {
190
185
  cellValue = getCellValue(row, column)
191
186
  } else {
@@ -208,7 +203,7 @@ function getBodyLabelData ($xeTable: any, opts: any, columns: any[], datas: any[
208
203
  })
209
204
  }
210
205
 
211
- function getExportData ($xetable: any, opts: any) {
206
+ function getExportData ($xetable: any, opts: VxeTablePropTypes.ExportHandleOptions) {
212
207
  const { columns, dataFilterMethod } = opts
213
208
  let datas = opts.data
214
209
  if (dataFilterMethod) {
@@ -611,17 +606,19 @@ function clearColumnConvert (columns: any) {
611
606
  }, { children: 'children' })
612
607
  }
613
608
 
614
- function handleExport ($xetable: any, opts: any) {
609
+ function handleExport ($xeTable: any, opts: VxeTablePropTypes.ExportHandleOptions) {
610
+ const $xeGrid = $xeTable.$xeGrid
611
+
615
612
  const { remote, columns, colgroups, exportMethod, afterExportMethod } = opts
616
613
  return new Promise(resolve => {
617
614
  if (remote) {
618
- const params = { options: opts, $table: $xetable, $grid: $xetable.$xegrid }
615
+ const params = { options: opts, $table: $xeTable, $grid: $xeGrid }
619
616
  resolve(exportMethod ? exportMethod(params) : params)
620
617
  } else {
621
- const datas = getExportData($xetable, opts)
618
+ const datas = getExportData($xeTable, opts)
622
619
  resolve(
623
- $xetable.preventEvent(null, 'event.export', { options: opts, columns, colgroups, datas }, () => {
624
- return downloadFile($xetable, opts, getContent($xetable, opts, columns, datas))
620
+ $xeTable.preventEvent(null, 'event.export', { options: opts, columns, colgroups, datas }, () => {
621
+ return downloadFile($xeTable, opts, getContent($xeTable, opts, columns, datas))
625
622
  })
626
623
  )
627
624
  }
@@ -629,7 +626,7 @@ function handleExport ($xetable: any, opts: any) {
629
626
  clearColumnConvert(columns)
630
627
  if (!opts.print) {
631
628
  if (afterExportMethod) {
632
- afterExportMethod({ status: true, options: opts, $table: $xetable, $grid: $xetable.$xegrid })
629
+ afterExportMethod({ status: true, options: opts, $table: $xeTable, $grid: $xeGrid })
633
630
  }
634
631
  }
635
632
  return Object.assign({ status: true }, params)
@@ -637,7 +634,7 @@ function handleExport ($xetable: any, opts: any) {
637
634
  clearColumnConvert(columns)
638
635
  if (!opts.print) {
639
636
  if (afterExportMethod) {
640
- afterExportMethod({ status: false, options: opts, $table: $xetable, $grid: $xetable.$xegrid })
637
+ afterExportMethod({ status: false, options: opts, $table: $xeTable, $grid: $xeGrid })
641
638
  }
642
639
  }
643
640
  const params = { status: false }
@@ -987,66 +984,29 @@ export function readLocalFile (options: any = {}) {
987
984
  })
988
985
  }
989
986
 
990
- function removePrintFrame () {
991
- if (printFrame) {
992
- if (printFrame.parentNode) {
993
- try {
994
- printFrame.contentDocument.write('')
995
- } catch (e) { }
996
- printFrame.parentNode.removeChild(printFrame)
997
- }
998
- printFrame = null
999
- }
1000
- }
1001
-
1002
- function appendPrintFrame () {
1003
- if (!printFrame.parentNode) {
1004
- document.body.appendChild(printFrame)
1005
- }
1006
- }
1007
-
1008
- function afterPrintEvent () {
1009
- requestAnimationFrame(removePrintFrame)
1010
- }
1011
-
1012
- export function handlePrint ($xetable: any, opts: any, content: any) {
1013
- const { beforePrintMethod } = opts
1014
- if (beforePrintMethod) {
1015
- content = beforePrintMethod({ content, options: opts, $table: $xetable }) || ''
1016
- }
1017
- content = createHtmlPage(opts, content)
1018
- const blob = getExportBlobByContent(content, opts)
1019
- if (browse.msie) {
1020
- removePrintFrame()
1021
- printFrame = createFrame()
1022
- appendPrintFrame()
1023
- printFrame.contentDocument.write(content)
1024
- printFrame.contentDocument.execCommand('print')
1025
- } else {
1026
- if (!printFrame) {
1027
- printFrame = createFrame()
1028
- printFrame.onload = (evnt: any) => {
1029
- if (evnt.target.src) {
1030
- evnt.target.contentWindow.onafterprint = afterPrintEvent
1031
- evnt.target.contentWindow.print()
1032
- }
1033
- }
1034
- }
1035
- appendPrintFrame()
1036
- printFrame.src = URL.createObjectURL(blob as any)
1037
- }
1038
- }
987
+ function handleExportAndPrint ($xeTable: VxeTableConstructor, options: VxeTablePropTypes.ExportOpts | VxeTablePropTypes.ExportConfig, isPrint?: any) {
988
+ const props = $xeTable
989
+ const reactData = $xeTable as unknown as TableReactData
990
+ const internalData = $xeTable as unknown as TableInternalData
991
+ const $xeGrid = $xeTable.$xeGrid
1039
992
 
1040
- function handleExportAndPrint ($xetable: any, options: any, isPrint?: any) {
1041
- const { $xegrid, initStore, customOpts, collectColumn, footerTableData, treeConfig, mergeList, isGroup, exportParams, exportOpts } = $xetable
1042
- const proxyOpts = $xegrid ? $xegrid.proxyOpts : {}
1043
- const selectRecords = $xetable.getCheckboxRecords()
1044
- const hasFooter = !!footerTableData.length
993
+ const { treeConfig, showHeader, showFooter } = props
994
+ const { initStore, mergeList, mergeFooterList, isGroup, footerTableData, exportStore, exportParams } = reactData
995
+ const { collectColumn } = internalData
996
+ const exportOpts = $xeTable.computeExportOpts
1045
997
  const hasTree = treeConfig
1046
- const hasMerge = !hasTree && mergeList.length
998
+ const customOpts = $xeTable.computeCustomOpts
999
+ const selectRecords = $xeTable.getCheckboxRecords()
1000
+ const proxyOpts = $xeGrid ? $xeGrid.computeProxyOpts : {}
1001
+ const hasFooter = !!footerTableData.length
1002
+ const hasMerge = !!(mergeList.length || mergeFooterList.length)
1047
1003
  const defOpts = Object.assign({
1048
1004
  message: true,
1049
- isHeader: true,
1005
+ isHeader: showHeader,
1006
+ isFooter: showFooter,
1007
+ isColgroup: isGroup,
1008
+ isMerge: hasMerge,
1009
+ useStyle: true,
1050
1010
  current: 'current',
1051
1011
  modes: ['current', 'selected'].concat(proxyOpts.ajax && proxyOpts.ajax.queryAll ? ['all'] : [])
1052
1012
  }, options)
@@ -1056,7 +1016,7 @@ function handleExportAndPrint ($xetable: any, options: any, isPrint?: any) {
1056
1016
  const exportColumns = collectColumn.slice(0)
1057
1017
  const { columns } = defOpts
1058
1018
  // 处理类型
1059
- const typeList = types.map((value: any) => {
1019
+ const typeList = types.map((value) => {
1060
1020
  return {
1061
1021
  value,
1062
1022
  label: getI18n(`vxe.export.types.${value}`)
@@ -1081,7 +1041,7 @@ function handleExportAndPrint ($xetable: any, options: any, isPrint?: any) {
1081
1041
  column.checked = columns
1082
1042
  ? columns.some((item: any) => {
1083
1043
  if (isColumnInfo(item)) {
1084
- return column === item
1044
+ return column.id === (item as any).id
1085
1045
  } else if (XEUtils.isString(item)) {
1086
1046
  return column.field === item
1087
1047
  } else {
@@ -1106,7 +1066,7 @@ function handleExportAndPrint ($xetable: any, options: any, isPrint?: any) {
1106
1066
  }
1107
1067
  })
1108
1068
  // 更新条件
1109
- Object.assign($xetable.exportStore, {
1069
+ Object.assign(exportStore, {
1110
1070
  columns: exportColumns,
1111
1071
  typeList,
1112
1072
  modeList,
@@ -1121,14 +1081,37 @@ function handleExportAndPrint ($xetable: any, options: any, isPrint?: any) {
1121
1081
  Object.assign(exportParams, {
1122
1082
  mode: selectRecords.length ? 'selected' : 'current'
1123
1083
  }, defOpts)
1124
- if (!modeList.some((item: any) => item.value === exportParams.mode)) {
1084
+ const { filename, sheetName, mode, type } = exportParams
1085
+ if (filename) {
1086
+ if (XEUtils.isFunction(filename)) {
1087
+ exportParams.filename = filename({
1088
+ options: defOpts,
1089
+ $table: $xeTable,
1090
+ $grid: $xeGrid
1091
+ })
1092
+ } else {
1093
+ exportParams.filename = `${filename}`
1094
+ }
1095
+ }
1096
+ if (sheetName) {
1097
+ if (XEUtils.isFunction(sheetName)) {
1098
+ exportParams.sheetName = sheetName({
1099
+ options: defOpts,
1100
+ $table: $xeTable,
1101
+ $grid: $xeGrid
1102
+ })
1103
+ } else {
1104
+ exportParams.sheetName = `${sheetName}`
1105
+ }
1106
+ }
1107
+ if (!modeList.some(item => item.value === mode)) {
1125
1108
  exportParams.mode = modeList[0].value
1126
1109
  }
1127
- if (!typeList.some((item: any) => item.value === exportParams.type)) {
1110
+ if (!typeList.some(item => item.value === type)) {
1128
1111
  exportParams.type = typeList[0].value
1129
1112
  }
1130
1113
  initStore.export = true
1131
- return $xetable.$nextTick()
1114
+ return $xeTable.$nextTick()
1132
1115
  }
1133
1116
 
1134
1117
  const getConvertColumns = (columns: any[]) => {
@@ -1194,11 +1177,14 @@ export default {
1194
1177
  /**
1195
1178
  * 导出文件,支持 csv/html/xml/txt
1196
1179
  * 如果是树表格,则默认是导出所有节点
1197
- * 如果是启用了虚拟滚动,则只能导出数据源,可以配合 dataFilterMethod 函数自行转换数据
1180
+ * 如果是启用了虚拟滚动,则只能导出数据源,可以配合 dataFilterMethod 函数转换数据
1198
1181
  * @param {Object} options 参数
1199
1182
  */
1200
1183
  _exportData (options: any) {
1201
- const { $xegrid, isGroup, tableGroupColumn, tableFullColumn, afterFullData, treeConfig, treeOpts, exportOpts } = this
1184
+ const $xeTable = this
1185
+ const $xeGrid = $xeTable.$xeGrid as VxeGridConstructor
1186
+
1187
+ const { isGroup, tableGroupColumn, tableFullColumn, afterFullData, treeConfig, treeOpts, exportOpts } = this
1202
1188
  const opts = Object.assign({
1203
1189
  // filename: '',
1204
1190
  // sheetName: '',
@@ -1223,13 +1209,13 @@ export default {
1223
1209
  }, exportOpts, {
1224
1210
  print: false
1225
1211
  }, options)
1226
- const { type, mode, columns, original, beforeExportMethod, excludeFields, includeFields } = opts
1212
+ const { filename, sheetName, type, mode, columns, original, columnFilterMethod, beforeExportMethod, includeFields, excludeFields } = opts
1227
1213
  let groups = []
1228
1214
  const customCols = columns && columns.length ? columns : null
1215
+ const handleOptions: VxeTablePropTypes.ExportHandleOptions = Object.assign({ } as { data: any[], colgroups: any[], columns: any[] }, opts, { filename: '', sheetName: '' })
1229
1216
  // 如果设置源数据,则默认导出设置了字段的列
1230
- let columnFilterMethod = opts.columnFilterMethod
1231
1217
  if (!customCols && !columnFilterMethod) {
1232
- columnFilterMethod = ({ column }: any) => {
1218
+ handleOptions.columnFilterMethod = ({ column }) => {
1233
1219
  if (excludeFields) {
1234
1220
  if (XEUtils.includes(excludeFields, column.field)) {
1235
1221
  return false
@@ -1245,27 +1231,27 @@ export default {
1245
1231
  }
1246
1232
  }
1247
1233
  if (customCols) {
1248
- opts._isCustomColumn = true
1234
+ handleOptions._isCustomColumn = true
1249
1235
  groups = XEUtils.searchTree(
1250
- XEUtils.mapTree(customCols, item => {
1236
+ XEUtils.mapTree(customCols, (item) => {
1251
1237
  let targetColumn
1252
1238
  if (item) {
1253
1239
  if (isColumnInfo(item)) {
1254
1240
  targetColumn = item
1255
1241
  } else if (XEUtils.isString(item)) {
1256
- targetColumn = this.getColumnByField(item)
1242
+ targetColumn = $xeTable.getColumnByField(item)
1257
1243
  } else {
1258
1244
  const colid = item.id || item.colId
1259
1245
  const type = item.type
1260
1246
  const field = item.field
1261
1247
  if (colid) {
1262
- targetColumn = this.getColumnById(colid)
1248
+ targetColumn = $xeTable.getColumnById(colid)
1263
1249
  } else if (field && type) {
1264
- targetColumn = tableFullColumn.find((column: any) => column.field === field && column.type === type)
1250
+ targetColumn = tableFullColumn.find((column: VxeTableDefines.ColumnInfo) => column.field === field && column.type === type)
1265
1251
  } else if (field) {
1266
- targetColumn = this.getColumnByField(field)
1252
+ targetColumn = $xeTable.getColumnByField(field)
1267
1253
  } else if (type) {
1268
- targetColumn = tableFullColumn.find((column: any) => column.type === type)
1254
+ targetColumn = tableFullColumn.find((column: VxeTableDefines.ColumnInfo) => column.type === type)
1269
1255
  }
1270
1256
  }
1271
1257
  return targetColumn || {}
@@ -1274,7 +1260,7 @@ export default {
1274
1260
  children: 'childNodes',
1275
1261
  mapChildren: '_children'
1276
1262
  }),
1277
- (column, index) => isColumnInfo(column) && (!columnFilterMethod || columnFilterMethod({ column, $columnIndex: index })),
1263
+ (column, index) => isColumnInfo(column) && (!columnFilterMethod || columnFilterMethod({ column: column as any, $columnIndex: index })),
1278
1264
  {
1279
1265
  children: '_children',
1280
1266
  mapChildren: 'childNodes',
@@ -1285,7 +1271,7 @@ export default {
1285
1271
  groups = XEUtils.searchTree(isGroup ? tableGroupColumn : tableFullColumn, (column, index) => column.visible && (!columnFilterMethod || columnFilterMethod({ column, $columnIndex: index })), { children: 'children', mapChildren: 'childNodes', original: true })
1286
1272
  }
1287
1273
  // 获取所有列
1288
- const cols: any[] = []
1274
+ const cols: VxeTableDefines.ColumnInfo[] = []
1289
1275
  XEUtils.eachTree(groups, column => {
1290
1276
  const isColGroup = column.children && column.children.length
1291
1277
  if (!isColGroup) {
@@ -1293,17 +1279,40 @@ export default {
1293
1279
  }
1294
1280
  }, { children: 'childNodes' })
1295
1281
  // 构建分组层级
1296
- opts.columns = cols
1297
- opts.colgroups = convertToRows(groups)
1298
- if (!opts.filename) {
1299
- opts.filename = getI18n(opts.original ? 'vxe.table.expOriginFilename' : 'vxe.table.expFilename', [XEUtils.toDateString(Date.now(), 'yyyyMMddHHmmss')])
1282
+ handleOptions.columns = cols
1283
+ handleOptions.colgroups = convertToRows(groups)
1284
+ if (filename) {
1285
+ if (XEUtils.isFunction(filename)) {
1286
+ handleOptions.filename = filename({
1287
+ options: opts,
1288
+ $table: $xeTable,
1289
+ $grid: $xeGrid
1290
+ })
1291
+ } else {
1292
+ handleOptions.filename = `${filename}`
1293
+ }
1294
+ }
1295
+ if (!handleOptions.filename) {
1296
+ handleOptions.filename = getI18n(handleOptions.original ? 'vxe.table.expOriginFilename' : 'vxe.table.expFilename', [XEUtils.toDateString(Date.now(), 'yyyyMMddHHmmss')])
1297
+ }
1298
+
1299
+ if (sheetName) {
1300
+ if (XEUtils.isFunction(sheetName)) {
1301
+ handleOptions.sheetName = sheetName({
1302
+ options: opts,
1303
+ $table: $xeTable,
1304
+ $grid: $xeGrid
1305
+ })
1306
+ } else {
1307
+ handleOptions.sheetName = `${sheetName}`
1308
+ }
1300
1309
  }
1301
- if (!opts.sheetName) {
1302
- opts.sheetName = document.title
1310
+ if (!handleOptions.sheetName) {
1311
+ handleOptions.sheetName = document.title || ''
1303
1312
  }
1304
1313
 
1305
1314
  // 检查类型,如果为自定义导出,则不需要校验类型
1306
- if (!opts.exportMethod && !XEUtils.includes(XEUtils.keys(exportOpts._typeMaps), type)) {
1315
+ if (!handleOptions.exportMethod && !XEUtils.includes(XEUtils.keys(exportOpts._typeMaps), type)) {
1307
1316
  errLog('vxe.error.notType', [type])
1308
1317
  if (process.env.VUE_APP_VXE_ENV === 'development') {
1309
1318
  if (['xlsx', 'pdf'].includes(type)) {
@@ -1314,30 +1323,34 @@ export default {
1314
1323
  return Promise.reject(params)
1315
1324
  }
1316
1325
 
1317
- if (!opts.print) {
1326
+ if (!handleOptions.print) {
1318
1327
  if (beforeExportMethod) {
1319
- beforeExportMethod({ options: opts, $table: this, $grid: $xegrid })
1328
+ beforeExportMethod({ options: handleOptions, $table: $xeTable, $grid: $xeGrid })
1320
1329
  }
1321
1330
  }
1322
1331
 
1323
1332
  if (!opts.data) {
1324
- opts.data = []
1333
+ handleOptions.data = []
1325
1334
  if (mode === 'selected') {
1326
- const selectRecords = this.getCheckboxRecords()
1335
+ const selectRecords = $xeTable.getCheckboxRecords()
1327
1336
  if (['html', 'pdf'].indexOf(type) > -1 && treeConfig) {
1328
- opts.data = XEUtils.searchTree(this.getTableData().fullData, (item) => selectRecords.indexOf(item) > -1, Object.assign({}, treeOpts, { data: '_row' }))
1337
+ opts.data = XEUtils.searchTree($xeTable.getTableData().fullData, item => $xeTable.findRowIndexOf(selectRecords, item) > -1, Object.assign({}, treeOpts, { data: '_row' }))
1329
1338
  } else {
1330
1339
  opts.data = selectRecords
1331
1340
  }
1332
1341
  } else if (mode === 'all') {
1333
1342
  if (process.env.VUE_APP_VXE_ENV === 'development') {
1334
- if (!$xegrid) {
1343
+ if (!$xeGrid) {
1335
1344
  warnLog('vxe.error.errProp', ['all', 'mode=current,selected'])
1336
1345
  }
1337
1346
  }
1338
1347
 
1339
- if ($xegrid && !opts.remote) {
1340
- const { beforeQueryAll, afterQueryAll, ajax = {}, props = {} } = $xegrid.proxyOpts
1348
+ if ($xeGrid && !handleOptions.remote) {
1349
+ const gridReactData = $xeGrid as unknown as GridReactData
1350
+ const proxyOpts = $xeGrid.computeProxyOpts
1351
+ const { sortData } = gridReactData
1352
+ const { beforeQueryAll, afterQueryAll, ajax = {} } = proxyOpts
1353
+ const resConfigs = proxyOpts.response || proxyOpts.props || {}
1341
1354
  const ajaxMethods = ajax.queryAll
1342
1355
  const queryAllSuccessMethods = ajax.queryAllSuccess
1343
1356
  const queryAllErrorMethods = ajax.queryAllError
@@ -1350,24 +1363,25 @@ export default {
1350
1363
 
1351
1364
  if (ajaxMethods) {
1352
1365
  const params = {
1353
- $table: this,
1354
- $grid: $xegrid,
1355
- sort: $xegrid.sortData,
1356
- filters: $xegrid.filterData,
1357
- form: $xegrid.formData,
1358
- target: ajaxMethods,
1359
- options: opts
1366
+ $table: $xeTable,
1367
+ $grid: $xeGrid,
1368
+ sort: sortData.length ? sortData[0] : {} as any,
1369
+ sorts: sortData as any[],
1370
+ filters: gridReactData.filterData,
1371
+ form: gridReactData.formData,
1372
+ options: handleOptions
1360
1373
  }
1361
1374
  return Promise.resolve((beforeQueryAll || ajaxMethods)(params))
1362
1375
  .then(rest => {
1363
- opts.data = (props.list ? XEUtils.get(rest, props.list) : rest) || []
1376
+ const listProp = resConfigs.list
1377
+ handleOptions.data = (listProp ? (XEUtils.isFunction(listProp) ? listProp({ data: rest, $grid: $xeGrid }) : XEUtils.get(rest, listProp)) : rest) || []
1364
1378
  if (afterQueryAll) {
1365
1379
  afterQueryAll(params)
1366
1380
  }
1367
1381
  if (queryAllSuccessMethods) {
1368
1382
  queryAllSuccessMethods({ ...params, response: rest })
1369
1383
  }
1370
- return handleExport(this, opts)
1384
+ return handleExport($xeTable, handleOptions)
1371
1385
  })
1372
1386
  .catch((rest) => {
1373
1387
  if (queryAllErrorMethods) {
@@ -1377,10 +1391,10 @@ export default {
1377
1391
  }
1378
1392
  }
1379
1393
  } else if (mode === 'current') {
1380
- opts.data = afterFullData
1394
+ handleOptions.data = afterFullData
1381
1395
  }
1382
1396
  }
1383
- return handleExport(this, opts)
1397
+ return handleExport($xeTable, opts)
1384
1398
  },
1385
1399
  _importByFile (file: any, options: any) {
1386
1400
  const opts = Object.assign({}, options)
@@ -1418,6 +1432,9 @@ export default {
1418
1432
  return readLocalFile(options)
1419
1433
  },
1420
1434
  _print (options: any) {
1435
+ const $xeTable = this
1436
+ const $xeGrid = $xeTable.$xeGrid
1437
+
1421
1438
  const opts = Object.assign({
1422
1439
  original: false
1423
1440
  // beforePrintMethod
@@ -1427,23 +1444,77 @@ export default {
1427
1444
  remote: false,
1428
1445
  print: true
1429
1446
  })
1430
- if (!opts.sheetName) {
1431
- opts.sheetName = document.title
1447
+ const { sheetName } = opts
1448
+ let printTitle = ''
1449
+
1450
+ if (sheetName) {
1451
+ if (XEUtils.isFunction(sheetName)) {
1452
+ printTitle = sheetName({
1453
+ options: opts,
1454
+ $table: $xeTable,
1455
+ $grid: $xeGrid
1456
+ })
1457
+ } else {
1458
+ printTitle = `${sheetName}`
1459
+ }
1460
+ }
1461
+ if (!printTitle) {
1462
+ printTitle = document.title || ''
1432
1463
  }
1433
- return new Promise(resolve => {
1434
- if (opts.content) {
1435
- resolve(handlePrint(this, opts, opts.content))
1464
+
1465
+ const beforePrintMethod = opts.beforePrintMethod
1466
+ const tableHtml = opts.html || opts.content
1467
+ return new Promise((resolve, reject) => {
1468
+ if (VxeUI.print) {
1469
+ if (tableHtml) {
1470
+ resolve(
1471
+ VxeUI.print({
1472
+ title: printTitle,
1473
+ html: tableHtml,
1474
+ customStyle: opts.style,
1475
+ beforeMethod: beforePrintMethod
1476
+ ? ({ html }) => {
1477
+ return beforePrintMethod({
1478
+ html,
1479
+ content: html,
1480
+ options: opts,
1481
+ $table: $xeTable
1482
+ })
1483
+ }
1484
+ : undefined
1485
+ })
1486
+ )
1487
+ } else {
1488
+ resolve(
1489
+ $xeTable.exportData(opts).then(({ content }: any) => {
1490
+ return VxeUI.print({
1491
+ title: printTitle,
1492
+ html: content,
1493
+ customStyle: opts.style,
1494
+ beforeMethod: beforePrintMethod
1495
+ ? ({ html }) => {
1496
+ return beforePrintMethod({
1497
+ html,
1498
+ content: html,
1499
+ options: opts,
1500
+ $table: $xeTable
1501
+ })
1502
+ }
1503
+ : undefined
1504
+ })
1505
+ })
1506
+ )
1507
+ }
1436
1508
  } else {
1437
- resolve(
1438
- this.exportData(opts).then(({ content }: any) => {
1439
- return handlePrint(this, opts, content)
1440
- })
1441
- )
1509
+ const e = { status: false }
1510
+ reject(e)
1442
1511
  }
1443
1512
  })
1444
1513
  },
1445
- _getPrintHtml (options: any) {
1446
- const { printOpts } = this
1514
+ _getPrintHtml (options: VxeTablePropTypes.PrintConfig) {
1515
+ const $xeTable = this
1516
+
1517
+ const printOpts = $xeTable.computePrintOpts
1447
1518
  const opts = Object.assign({
1448
1519
  original: false
1449
1520
  // beforePrintMethod
@@ -1453,7 +1524,7 @@ export default {
1453
1524
  remote: false,
1454
1525
  print: true
1455
1526
  })
1456
- return this.exportData(opts).then(({ content }: any) => {
1527
+ return $xeTable.exportData(opts).then(({ content }: any) => {
1457
1528
  return {
1458
1529
  html: content
1459
1530
  }