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.
- package/es/locale/lang/de-DE.js +490 -490
- package/es/locale/lang/en-US.js +438 -438
- package/es/locale/lang/it-IT.js +692 -0
- package/es/locale/lang/ru-RU.js +36 -36
- package/es/locale/lang/th-TH.js +692 -0
- package/es/locale/lang/zh-CHT.js +19 -19
- package/es/style.css +1 -1
- package/es/table/module/custom/panel.js +5 -5
- package/es/table/module/export/mixin.js +208 -140
- package/es/table/src/cell.js +88 -61
- package/es/table/src/column.js +2 -2
- package/es/table/src/group.js +2 -2
- package/es/table/src/methods.js +112 -87
- package/es/table/src/table.js +7 -11
- package/es/toolbar/src/toolbar.js +22 -4
- package/es/ui/index.js +2 -2
- package/es/ui/src/log.js +1 -1
- package/es/ui/src/vn.js +3 -0
- package/lib/index.umd.js +512 -356
- package/lib/index.umd.min.js +1 -1
- package/lib/locale/lang/de-DE.js +490 -490
- package/lib/locale/lang/de-DE.min.js +1 -1
- package/lib/locale/lang/en-US.js +438 -438
- package/lib/locale/lang/en-US.min.js +1 -1
- package/lib/locale/lang/en-US.umd.js +438 -438
- package/lib/locale/lang/it-IT.js +698 -0
- package/lib/locale/lang/it-IT.min.js +1 -0
- package/lib/locale/lang/ru-RU.js +36 -36
- package/lib/locale/lang/ru-RU.min.js +1 -1
- package/lib/locale/lang/ru-RU.umd.js +36 -36
- package/lib/locale/lang/th-TH.js +698 -0
- package/lib/locale/lang/th-TH.min.js +1 -0
- package/lib/locale/lang/zh-CHT.js +19 -19
- package/lib/locale/lang/zh-CHT.min.js +1 -1
- package/lib/locale/lang/zh-CHT.umd.js +19 -19
- package/lib/style.css +1 -1
- package/lib/table/module/custom/panel.js +5 -5
- package/lib/table/module/custom/panel.min.js +1 -1
- package/lib/table/module/export/mixin.js +239 -167
- package/lib/table/module/export/mixin.min.js +1 -1
- package/lib/table/src/cell.js +109 -83
- package/lib/table/src/cell.min.js +1 -1
- package/lib/table/src/methods.js +112 -87
- package/lib/table/src/methods.min.js +1 -1
- package/lib/table/src/table.js +4 -9
- package/lib/table/src/table.min.js +1 -1
- package/lib/toolbar/src/toolbar.js +36 -2
- package/lib/toolbar/src/toolbar.min.js +1 -1
- package/lib/ui/index.js +2 -2
- package/lib/ui/index.min.js +1 -1
- package/lib/ui/src/log.js +1 -1
- package/lib/ui/src/log.min.js +1 -1
- package/lib/ui/src/vn.js +3 -0
- package/lib/ui/src/vn.min.js +1 -1
- package/package.json +3 -3
- package/packages/locale/lang/de-DE.ts +492 -491
- package/packages/locale/lang/en-US.ts +438 -438
- package/packages/locale/lang/it-IT.ts +692 -0
- package/packages/locale/lang/ru-RU.ts +36 -36
- package/packages/locale/lang/th-TH.ts +692 -0
- package/packages/locale/lang/zh-CHT.ts +19 -19
- package/packages/table/module/custom/panel.ts +5 -5
- package/packages/table/module/export/mixin.ts +227 -156
- package/packages/table/src/cell.ts +141 -108
- package/packages/table/src/methods.ts +136 -105
- package/packages/table/src/table.ts +8 -12
- package/packages/toolbar/src/toolbar.ts +26 -8
- package/packages/ui/index.ts +1 -1
- package/packages/ui/src/vn.ts +4 -1
- /package/es/{iconfont.1735301172726.ttf → iconfont.1735661059384.ttf} +0 -0
- /package/es/{iconfont.1735301172726.woff → iconfont.1735661059384.woff} +0 -0
- /package/es/{iconfont.1735301172726.woff2 → iconfont.1735661059384.woff2} +0 -0
- /package/lib/{iconfont.1735301172726.ttf → iconfont.1735661059384.ttf} +0 -0
- /package/lib/{iconfont.1735301172726.woff → iconfont.1735661059384.woff} +0 -0
- /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
|
|
24
|
-
const
|
|
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
|
|
24
|
+
return row[childrenField] && row[childrenField].length
|
|
33
25
|
}
|
|
34
26
|
|
|
35
|
-
function getSeq ($
|
|
36
|
-
const 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: $
|
|
33
|
+
rowIndex: $xeTable.getRowIndex(row),
|
|
42
34
|
$rowIndex,
|
|
43
35
|
column,
|
|
44
|
-
columnIndex: $
|
|
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:
|
|
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
|
|
76
|
-
const
|
|
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
|
|
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
|
|
114
|
-
cellValue = mode === 'all' ?
|
|
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
|
|
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:
|
|
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 ($
|
|
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: $
|
|
615
|
+
const params = { options: opts, $table: $xeTable, $grid: $xeGrid }
|
|
619
616
|
resolve(exportMethod ? exportMethod(params) : params)
|
|
620
617
|
} else {
|
|
621
|
-
const datas = getExportData($
|
|
618
|
+
const datas = getExportData($xeTable, opts)
|
|
622
619
|
resolve(
|
|
623
|
-
$
|
|
624
|
-
return downloadFile($
|
|
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: $
|
|
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: $
|
|
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
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
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
|
-
|
|
1041
|
-
const {
|
|
1042
|
-
const
|
|
1043
|
-
const
|
|
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
|
|
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:
|
|
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
|
|
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(
|
|
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
|
-
|
|
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(
|
|
1110
|
+
if (!typeList.some(item => item.value === type)) {
|
|
1128
1111
|
exportParams.type = typeList[0].value
|
|
1129
1112
|
}
|
|
1130
1113
|
initStore.export = true
|
|
1131
|
-
return $
|
|
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
|
|
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,
|
|
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 }
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
1248
|
+
targetColumn = $xeTable.getColumnById(colid)
|
|
1263
1249
|
} else if (field && type) {
|
|
1264
|
-
targetColumn = tableFullColumn.find((column:
|
|
1250
|
+
targetColumn = tableFullColumn.find((column: VxeTableDefines.ColumnInfo) => column.field === field && column.type === type)
|
|
1265
1251
|
} else if (field) {
|
|
1266
|
-
targetColumn =
|
|
1252
|
+
targetColumn = $xeTable.getColumnByField(field)
|
|
1267
1253
|
} else if (type) {
|
|
1268
|
-
targetColumn = tableFullColumn.find((column:
|
|
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:
|
|
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
|
-
|
|
1297
|
-
|
|
1298
|
-
if (
|
|
1299
|
-
|
|
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 (!
|
|
1302
|
-
|
|
1310
|
+
if (!handleOptions.sheetName) {
|
|
1311
|
+
handleOptions.sheetName = document.title || ''
|
|
1303
1312
|
}
|
|
1304
1313
|
|
|
1305
1314
|
// 检查类型,如果为自定义导出,则不需要校验类型
|
|
1306
|
-
if (!
|
|
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 (!
|
|
1326
|
+
if (!handleOptions.print) {
|
|
1318
1327
|
if (beforeExportMethod) {
|
|
1319
|
-
beforeExportMethod({ options:
|
|
1328
|
+
beforeExportMethod({ options: handleOptions, $table: $xeTable, $grid: $xeGrid })
|
|
1320
1329
|
}
|
|
1321
1330
|
}
|
|
1322
1331
|
|
|
1323
1332
|
if (!opts.data) {
|
|
1324
|
-
|
|
1333
|
+
handleOptions.data = []
|
|
1325
1334
|
if (mode === 'selected') {
|
|
1326
|
-
const selectRecords =
|
|
1335
|
+
const selectRecords = $xeTable.getCheckboxRecords()
|
|
1327
1336
|
if (['html', 'pdf'].indexOf(type) > -1 && treeConfig) {
|
|
1328
|
-
opts.data = XEUtils.searchTree(
|
|
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 (!$
|
|
1343
|
+
if (!$xeGrid) {
|
|
1335
1344
|
warnLog('vxe.error.errProp', ['all', 'mode=current,selected'])
|
|
1336
1345
|
}
|
|
1337
1346
|
}
|
|
1338
1347
|
|
|
1339
|
-
if ($
|
|
1340
|
-
const
|
|
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:
|
|
1354
|
-
$grid: $
|
|
1355
|
-
sort:
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
options:
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
1394
|
+
handleOptions.data = afterFullData
|
|
1381
1395
|
}
|
|
1382
1396
|
}
|
|
1383
|
-
return handleExport(
|
|
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
|
-
|
|
1431
|
-
|
|
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
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
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
|
-
|
|
1438
|
-
|
|
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:
|
|
1446
|
-
const
|
|
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
|
|
1527
|
+
return $xeTable.exportData(opts).then(({ content }: any) => {
|
|
1457
1528
|
return {
|
|
1458
1529
|
html: content
|
|
1459
1530
|
}
|