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