vxe-table 3.12.0-beta.11 → 3.12.0-beta.13

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.
@@ -4,14 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- exports.handlePrint = handlePrint;
8
7
  exports.readLocalFile = readLocalFile;
9
8
  exports.saveLocalFile = saveLocalFile;
10
9
  var _xeUtils = _interopRequireDefault(require("xe-utils"));
11
10
  var _ui = require("../../../ui");
12
11
  var _util = require("../../src/util");
13
12
  var _utils = require("../../../ui/src/utils");
14
- var _dom = require("../../../ui/src/dom");
15
13
  var _util2 = require("./util");
16
14
  var _log = require("../../../ui/src/log");
17
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -23,15 +21,8 @@ let htmlCellElem;
23
21
  // 导入
24
22
  let fileForm;
25
23
  let fileInput;
26
- // 打印
27
- let printFrame;
28
24
  const csvBOM = '\ufeff';
29
25
  const enterSymbol = '\r\n';
30
- function createFrame() {
31
- const frame = document.createElement('iframe');
32
- frame.className = 'vxe-table--print-frame';
33
- return frame;
34
- }
35
26
  function hasTreeChildren($xetable, row) {
36
27
  const treeOpts = $xetable.treeOpts;
37
28
  const childrenField = treeOpts.children || treeOpts.childrenField;
@@ -663,7 +654,8 @@ function clearColumnConvert(columns) {
663
654
  children: 'children'
664
655
  });
665
656
  }
666
- function handleExport($xetable, opts) {
657
+ function handleExport($xeTable, opts) {
658
+ const $xeGrid = $xeTable.$xeGrid;
667
659
  const {
668
660
  remote,
669
661
  columns,
@@ -675,19 +667,19 @@ function handleExport($xetable, opts) {
675
667
  if (remote) {
676
668
  const params = {
677
669
  options: opts,
678
- $table: $xetable,
679
- $grid: $xetable.$xegrid
670
+ $table: $xeTable,
671
+ $grid: $xeGrid
680
672
  };
681
673
  resolve(exportMethod ? exportMethod(params) : params);
682
674
  } else {
683
- const datas = getExportData($xetable, opts);
684
- resolve($xetable.preventEvent(null, 'event.export', {
675
+ const datas = getExportData($xeTable, opts);
676
+ resolve($xeTable.preventEvent(null, 'event.export', {
685
677
  options: opts,
686
678
  columns,
687
679
  colgroups,
688
680
  datas
689
681
  }, () => {
690
- return downloadFile($xetable, opts, getContent($xetable, opts, columns, datas));
682
+ return downloadFile($xeTable, opts, getContent($xeTable, opts, columns, datas));
691
683
  }));
692
684
  }
693
685
  }).then(params => {
@@ -697,8 +689,8 @@ function handleExport($xetable, opts) {
697
689
  afterExportMethod({
698
690
  status: true,
699
691
  options: opts,
700
- $table: $xetable,
701
- $grid: $xetable.$xegrid
692
+ $table: $xeTable,
693
+ $grid: $xeGrid
702
694
  });
703
695
  }
704
696
  }
@@ -712,8 +704,8 @@ function handleExport($xetable, opts) {
712
704
  afterExportMethod({
713
705
  status: false,
714
706
  options: opts,
715
- $table: $xetable,
716
- $grid: $xetable.$xegrid
707
+ $table: $xeTable,
708
+ $grid: $xeGrid
717
709
  });
718
710
  }
719
711
  }
@@ -1136,61 +1128,9 @@ function readLocalFile(options = {}) {
1136
1128
  fileInput.click();
1137
1129
  });
1138
1130
  }
1139
- function removePrintFrame() {
1140
- if (printFrame) {
1141
- if (printFrame.parentNode) {
1142
- try {
1143
- printFrame.contentDocument.write('');
1144
- } catch (e) {}
1145
- printFrame.parentNode.removeChild(printFrame);
1146
- }
1147
- printFrame = null;
1148
- }
1149
- }
1150
- function appendPrintFrame() {
1151
- if (!printFrame.parentNode) {
1152
- document.body.appendChild(printFrame);
1153
- }
1154
- }
1155
- function afterPrintEvent() {
1156
- requestAnimationFrame(removePrintFrame);
1157
- }
1158
- function handlePrint($xetable, opts, content) {
1131
+ function handleExportAndPrint($xeTable, options, isPrint) {
1132
+ const $xeGrid = $xeTable.$xeGrid;
1159
1133
  const {
1160
- beforePrintMethod
1161
- } = opts;
1162
- if (beforePrintMethod) {
1163
- content = beforePrintMethod({
1164
- content,
1165
- options: opts,
1166
- $table: $xetable
1167
- }) || '';
1168
- }
1169
- content = (0, _util2.createHtmlPage)(opts, content);
1170
- const blob = (0, _util2.getExportBlobByContent)(content, opts);
1171
- if (_dom.browse.msie) {
1172
- removePrintFrame();
1173
- printFrame = createFrame();
1174
- appendPrintFrame();
1175
- printFrame.contentDocument.write(content);
1176
- printFrame.contentDocument.execCommand('print');
1177
- } else {
1178
- if (!printFrame) {
1179
- printFrame = createFrame();
1180
- printFrame.onload = evnt => {
1181
- if (evnt.target.src) {
1182
- evnt.target.contentWindow.onafterprint = afterPrintEvent;
1183
- evnt.target.contentWindow.print();
1184
- }
1185
- };
1186
- }
1187
- appendPrintFrame();
1188
- printFrame.src = URL.createObjectURL(blob);
1189
- }
1190
- }
1191
- function handleExportAndPrint($xetable, options, isPrint) {
1192
- const {
1193
- $xegrid,
1194
1134
  initStore,
1195
1135
  customOpts,
1196
1136
  collectColumn,
@@ -1200,9 +1140,9 @@ function handleExportAndPrint($xetable, options, isPrint) {
1200
1140
  isGroup,
1201
1141
  exportParams,
1202
1142
  exportOpts
1203
- } = $xetable;
1204
- const proxyOpts = $xegrid ? $xegrid.proxyOpts : {};
1205
- const selectRecords = $xetable.getCheckboxRecords();
1143
+ } = $xeTable;
1144
+ const proxyOpts = $xeGrid ? $xeGrid.computeProxyOpts : {};
1145
+ const selectRecords = $xeTable.getCheckboxRecords();
1206
1146
  const hasFooter = !!footerTableData.length;
1207
1147
  const hasTree = treeConfig;
1208
1148
  const hasMerge = !hasTree && mergeList.length;
@@ -1270,7 +1210,7 @@ function handleExportAndPrint($xetable, options, isPrint) {
1270
1210
  }
1271
1211
  });
1272
1212
  // 更新条件
1273
- Object.assign($xetable.exportStore, {
1213
+ Object.assign($xeTable.exportStore, {
1274
1214
  columns: exportColumns,
1275
1215
  typeList,
1276
1216
  modeList,
@@ -1285,14 +1225,42 @@ function handleExportAndPrint($xetable, options, isPrint) {
1285
1225
  Object.assign(exportParams, {
1286
1226
  mode: selectRecords.length ? 'selected' : 'current'
1287
1227
  }, defOpts);
1288
- if (!modeList.some(item => item.value === exportParams.mode)) {
1228
+ const {
1229
+ filename,
1230
+ sheetName,
1231
+ mode,
1232
+ type
1233
+ } = exportParams;
1234
+ if (filename) {
1235
+ if (_xeUtils.default.isFunction(filename)) {
1236
+ exportParams.filename = filename({
1237
+ options: defOpts,
1238
+ $table: $xeTable,
1239
+ $grid: $xeGrid
1240
+ });
1241
+ } else {
1242
+ exportParams.filename = `${filename}`;
1243
+ }
1244
+ }
1245
+ if (sheetName) {
1246
+ if (_xeUtils.default.isFunction(sheetName)) {
1247
+ exportParams.sheetName = sheetName({
1248
+ options: defOpts,
1249
+ $table: $xeTable,
1250
+ $grid: $xeGrid
1251
+ });
1252
+ } else {
1253
+ exportParams.sheetName = `${sheetName}`;
1254
+ }
1255
+ }
1256
+ if (!modeList.some(item => item.value === mode)) {
1289
1257
  exportParams.mode = modeList[0].value;
1290
1258
  }
1291
- if (!typeList.some(item => item.value === exportParams.type)) {
1259
+ if (!typeList.some(item => item.value === type)) {
1292
1260
  exportParams.type = typeList[0].value;
1293
1261
  }
1294
1262
  initStore.export = true;
1295
- return $xetable.$nextTick();
1263
+ return $xeTable.$nextTick();
1296
1264
  }
1297
1265
  const getConvertColumns = columns => {
1298
1266
  const result = [];
@@ -1350,12 +1318,13 @@ var _default = exports.default = {
1350
1318
  /**
1351
1319
  * 导出文件,支持 csv/html/xml/txt
1352
1320
  * 如果是树表格,则默认是导出所有节点
1353
- * 如果是启用了虚拟滚动,则只能导出数据源,可以配合 dataFilterMethod 函数自行转换数据
1321
+ * 如果是启用了虚拟滚动,则只能导出数据源,可以配合 dataFilterMethod 函数转换数据
1354
1322
  * @param {Object} options 参数
1355
1323
  */
1356
1324
  _exportData(options) {
1325
+ const $xeTable = this;
1326
+ const $xeGrid = $xeTable.$xeGrid;
1357
1327
  const {
1358
- $xegrid,
1359
1328
  isGroup,
1360
1329
  tableGroupColumn,
1361
1330
  tableFullColumn,
@@ -1389,20 +1358,29 @@ var _default = exports.default = {
1389
1358
  print: false
1390
1359
  }, options);
1391
1360
  const {
1361
+ filename,
1362
+ sheetName,
1392
1363
  type,
1393
1364
  mode,
1394
1365
  columns,
1395
1366
  original,
1367
+ columnFilterMethod,
1396
1368
  beforeExportMethod,
1397
- excludeFields,
1398
- includeFields
1369
+ includeFields,
1370
+ excludeFields
1399
1371
  } = opts;
1400
1372
  let groups = [];
1401
1373
  const customCols = columns && columns.length ? columns : null;
1374
+ const handleOptions = Object.assign({}, opts, {
1375
+ filename: '',
1376
+ sheetName: '',
1377
+ colgroups: [],
1378
+ columns: [],
1379
+ data: []
1380
+ });
1402
1381
  // 如果设置源数据,则默认导出设置了字段的列
1403
- let columnFilterMethod = opts.columnFilterMethod;
1404
1382
  if (!customCols && !columnFilterMethod) {
1405
- columnFilterMethod = ({
1383
+ handleOptions.columnFilterMethod = ({
1406
1384
  column
1407
1385
  }) => {
1408
1386
  if (excludeFields) {
@@ -1420,24 +1398,24 @@ var _default = exports.default = {
1420
1398
  };
1421
1399
  }
1422
1400
  if (customCols) {
1423
- opts._isCustomColumn = true;
1401
+ handleOptions._isCustomColumn = true;
1424
1402
  groups = _xeUtils.default.searchTree(_xeUtils.default.mapTree(customCols, item => {
1425
1403
  let targetColumn;
1426
1404
  if (item) {
1427
1405
  if ((0, _util.isColumnInfo)(item)) {
1428
1406
  targetColumn = item;
1429
1407
  } else if (_xeUtils.default.isString(item)) {
1430
- targetColumn = this.getColumnByField(item);
1408
+ targetColumn = $xeTable.getColumnByField(item);
1431
1409
  } else {
1432
1410
  const colid = item.id || item.colId;
1433
1411
  const type = item.type;
1434
1412
  const field = item.field;
1435
1413
  if (colid) {
1436
- targetColumn = this.getColumnById(colid);
1414
+ targetColumn = $xeTable.getColumnById(colid);
1437
1415
  } else if (field && type) {
1438
1416
  targetColumn = tableFullColumn.find(column => column.field === field && column.type === type);
1439
1417
  } else if (field) {
1440
- targetColumn = this.getColumnByField(field);
1418
+ targetColumn = $xeTable.getColumnByField(field);
1441
1419
  } else if (type) {
1442
1420
  targetColumn = tableFullColumn.find(column => column.type === type);
1443
1421
  }
@@ -1448,7 +1426,7 @@ var _default = exports.default = {
1448
1426
  children: 'childNodes',
1449
1427
  mapChildren: '_children'
1450
1428
  }), (column, index) => (0, _util.isColumnInfo)(column) && (!columnFilterMethod || columnFilterMethod({
1451
- column,
1429
+ column: column,
1452
1430
  $columnIndex: index
1453
1431
  })), {
1454
1432
  children: '_children',
@@ -1476,16 +1454,38 @@ var _default = exports.default = {
1476
1454
  children: 'childNodes'
1477
1455
  });
1478
1456
  // 构建分组层级
1479
- opts.columns = cols;
1480
- opts.colgroups = convertToRows(groups);
1481
- if (!opts.filename) {
1482
- opts.filename = getI18n(opts.original ? 'vxe.table.expOriginFilename' : 'vxe.table.expFilename', [_xeUtils.default.toDateString(Date.now(), 'yyyyMMddHHmmss')]);
1457
+ handleOptions.columns = cols;
1458
+ handleOptions.colgroups = convertToRows(groups);
1459
+ if (filename) {
1460
+ if (_xeUtils.default.isFunction(filename)) {
1461
+ handleOptions.filename = filename({
1462
+ options: opts,
1463
+ $table: $xeTable,
1464
+ $grid: $xeGrid
1465
+ });
1466
+ } else {
1467
+ handleOptions.filename = `${filename}`;
1468
+ }
1469
+ }
1470
+ if (!handleOptions.filename) {
1471
+ handleOptions.filename = getI18n(handleOptions.original ? 'vxe.table.expOriginFilename' : 'vxe.table.expFilename', [_xeUtils.default.toDateString(Date.now(), 'yyyyMMddHHmmss')]);
1472
+ }
1473
+ if (sheetName) {
1474
+ if (_xeUtils.default.isFunction(sheetName)) {
1475
+ handleOptions.sheetName = sheetName({
1476
+ options: opts,
1477
+ $table: $xeTable,
1478
+ $grid: $xeGrid
1479
+ });
1480
+ } else {
1481
+ handleOptions.sheetName = `${sheetName}`;
1482
+ }
1483
1483
  }
1484
- if (!opts.sheetName) {
1485
- opts.sheetName = document.title;
1484
+ if (!handleOptions.sheetName) {
1485
+ handleOptions.sheetName = document.title || '';
1486
1486
  }
1487
1487
  // 检查类型,如果为自定义导出,则不需要校验类型
1488
- if (!opts.exportMethod && !_xeUtils.default.includes(_xeUtils.default.keys(exportOpts._typeMaps), type)) {
1488
+ if (!handleOptions.exportMethod && !_xeUtils.default.includes(_xeUtils.default.keys(exportOpts._typeMaps), type)) {
1489
1489
  (0, _log.errLog)('vxe.error.notType', [type]);
1490
1490
  if (process.env.NODE_ENV === 'development') {
1491
1491
  if (['xlsx', 'pdf'].includes(type)) {
@@ -1497,21 +1497,21 @@ var _default = exports.default = {
1497
1497
  };
1498
1498
  return Promise.reject(params);
1499
1499
  }
1500
- if (!opts.print) {
1500
+ if (!handleOptions.print) {
1501
1501
  if (beforeExportMethod) {
1502
1502
  beforeExportMethod({
1503
- options: opts,
1504
- $table: this,
1505
- $grid: $xegrid
1503
+ options: handleOptions,
1504
+ $table: $xeTable,
1505
+ $grid: $xeGrid
1506
1506
  });
1507
1507
  }
1508
1508
  }
1509
1509
  if (!opts.data) {
1510
- opts.data = [];
1510
+ handleOptions.data = [];
1511
1511
  if (mode === 'selected') {
1512
- const selectRecords = this.getCheckboxRecords();
1512
+ const selectRecords = $xeTable.getCheckboxRecords();
1513
1513
  if (['html', 'pdf'].indexOf(type) > -1 && treeConfig) {
1514
- opts.data = _xeUtils.default.searchTree(this.getTableData().fullData, item => selectRecords.indexOf(item) > -1, Object.assign({}, treeOpts, {
1514
+ opts.data = _xeUtils.default.searchTree($xeTable.getTableData().fullData, item => $xeTable.findRowIndexOf(selectRecords, item) > -1, Object.assign({}, treeOpts, {
1515
1515
  data: '_row'
1516
1516
  }));
1517
1517
  } else {
@@ -1519,17 +1519,22 @@ var _default = exports.default = {
1519
1519
  }
1520
1520
  } else if (mode === 'all') {
1521
1521
  if (process.env.NODE_ENV === 'development') {
1522
- if (!$xegrid) {
1522
+ if (!$xeGrid) {
1523
1523
  (0, _log.warnLog)('vxe.error.errProp', ['all', 'mode=current,selected']);
1524
1524
  }
1525
1525
  }
1526
- if ($xegrid && !opts.remote) {
1526
+ if ($xeGrid && !handleOptions.remote) {
1527
+ const gridReactData = $xeGrid;
1528
+ const proxyOpts = $xeGrid.computeProxyOpts;
1529
+ const {
1530
+ sortData
1531
+ } = gridReactData;
1527
1532
  const {
1528
1533
  beforeQueryAll,
1529
1534
  afterQueryAll,
1530
- ajax = {},
1531
- props = {}
1532
- } = $xegrid.proxyOpts;
1535
+ ajax = {}
1536
+ } = proxyOpts;
1537
+ const resConfigs = proxyOpts.response || proxyOpts.props || {};
1533
1538
  const ajaxMethods = ajax.queryAll;
1534
1539
  const queryAllSuccessMethods = ajax.queryAllSuccess;
1535
1540
  const queryAllErrorMethods = ajax.queryAllError;
@@ -1540,16 +1545,20 @@ var _default = exports.default = {
1540
1545
  }
1541
1546
  if (ajaxMethods) {
1542
1547
  const params = {
1543
- $table: this,
1544
- $grid: $xegrid,
1545
- sort: $xegrid.sortData,
1546
- filters: $xegrid.filterData,
1547
- form: $xegrid.formData,
1548
- target: ajaxMethods,
1549
- options: opts
1548
+ $table: $xeTable,
1549
+ $grid: $xeGrid,
1550
+ sort: sortData.length ? sortData[0] : {},
1551
+ sorts: sortData,
1552
+ filters: gridReactData.filterData,
1553
+ form: gridReactData.formData,
1554
+ options: handleOptions
1550
1555
  };
1551
1556
  return Promise.resolve((beforeQueryAll || ajaxMethods)(params)).then(rest => {
1552
- opts.data = (props.list ? _xeUtils.default.get(rest, props.list) : rest) || [];
1557
+ const listProp = resConfigs.list;
1558
+ handleOptions.data = (listProp ? _xeUtils.default.isFunction(listProp) ? listProp({
1559
+ data: rest,
1560
+ $grid: $xeGrid
1561
+ }) : _xeUtils.default.get(rest, listProp) : rest) || [];
1553
1562
  if (afterQueryAll) {
1554
1563
  afterQueryAll(params);
1555
1564
  }
@@ -1558,7 +1567,7 @@ var _default = exports.default = {
1558
1567
  response: rest
1559
1568
  }));
1560
1569
  }
1561
- return handleExport(this, opts);
1570
+ return handleExport($xeTable, handleOptions);
1562
1571
  }).catch(rest => {
1563
1572
  if (queryAllErrorMethods) {
1564
1573
  queryAllErrorMethods(Object.assign(Object.assign({}, params), {
@@ -1569,10 +1578,10 @@ var _default = exports.default = {
1569
1578
  }
1570
1579
  }
1571
1580
  } else if (mode === 'current') {
1572
- opts.data = afterFullData;
1581
+ handleOptions.data = afterFullData;
1573
1582
  }
1574
1583
  }
1575
- return handleExport(this, opts);
1584
+ return handleExport($xeTable, opts);
1576
1585
  },
1577
1586
  _importByFile(file, options) {
1578
1587
  const opts = Object.assign({}, options);
@@ -1629,6 +1638,8 @@ var _default = exports.default = {
1629
1638
  return readLocalFile(options);
1630
1639
  },
1631
1640
  _print(options) {
1641
+ const $xeTable = this;
1642
+ const $xeGrid = $xeTable.$xeGrid;
1632
1643
  const opts = Object.assign({
1633
1644
  original: false
1634
1645
  // beforePrintMethod
@@ -1638,25 +1649,76 @@ var _default = exports.default = {
1638
1649
  remote: false,
1639
1650
  print: true
1640
1651
  });
1641
- if (!opts.sheetName) {
1642
- opts.sheetName = document.title;
1652
+ const {
1653
+ sheetName
1654
+ } = opts;
1655
+ let printTitle = '';
1656
+ if (sheetName) {
1657
+ if (_xeUtils.default.isFunction(sheetName)) {
1658
+ printTitle = sheetName({
1659
+ options: opts,
1660
+ $table: $xeTable,
1661
+ $grid: $xeGrid
1662
+ });
1663
+ } else {
1664
+ printTitle = `${sheetName}`;
1665
+ }
1643
1666
  }
1644
- return new Promise(resolve => {
1645
- if (opts.content) {
1646
- resolve(handlePrint(this, opts, opts.content));
1667
+ if (!printTitle) {
1668
+ printTitle = document.title || '';
1669
+ }
1670
+ const beforePrintMethod = opts.beforePrintMethod;
1671
+ const tableHtml = opts.html || opts.content;
1672
+ return new Promise((resolve, reject) => {
1673
+ if (_ui.VxeUI.print) {
1674
+ if (tableHtml) {
1675
+ resolve(_ui.VxeUI.print({
1676
+ title: printTitle,
1677
+ html: tableHtml,
1678
+ customStyle: opts.style,
1679
+ beforeMethod: beforePrintMethod ? ({
1680
+ html
1681
+ }) => {
1682
+ return beforePrintMethod({
1683
+ html,
1684
+ content: html,
1685
+ options: opts,
1686
+ $table: $xeTable
1687
+ });
1688
+ } : undefined
1689
+ }));
1690
+ } else {
1691
+ resolve($xeTable.exportData(opts).then(({
1692
+ content
1693
+ }) => {
1694
+ return _ui.VxeUI.print({
1695
+ title: printTitle,
1696
+ html: content,
1697
+ customStyle: opts.style,
1698
+ beforeMethod: beforePrintMethod ? ({
1699
+ html
1700
+ }) => {
1701
+ return beforePrintMethod({
1702
+ html,
1703
+ content: html,
1704
+ options: opts,
1705
+ $table: $xeTable
1706
+ });
1707
+ } : undefined
1708
+ });
1709
+ }));
1710
+ }
1647
1711
  } else {
1648
- resolve(this.exportData(opts).then(({
1649
- content
1650
- }) => {
1651
- return handlePrint(this, opts, content);
1652
- }));
1712
+ const e = {
1713
+ status: false
1714
+ };
1715
+ reject(e);
1653
1716
  }
1654
1717
  });
1655
1718
  },
1656
1719
  _getPrintHtml(options) {
1657
- const {
1658
- printOpts
1659
- } = this;
1720
+ const $xeTable = this;
1721
+ const printOpts = $xeTable.computePrintOpts;
1660
1722
  const opts = Object.assign({
1661
1723
  original: false
1662
1724
  // beforePrintMethod
@@ -1666,7 +1728,7 @@ var _default = exports.default = {
1666
1728
  remote: false,
1667
1729
  print: true
1668
1730
  });
1669
- return this.exportData(opts).then(({
1731
+ return $xeTable.exportData(opts).then(({
1670
1732
  content
1671
1733
  }) => {
1672
1734
  return {