vxe-table 3.9.9 → 3.9.11

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.
@@ -402,7 +402,6 @@ const Methods = {
402
402
  } = this;
403
403
  return this.handleTableData(true).then(() => {
404
404
  this.updateFooter();
405
- this.checkSelectionStatus();
406
405
  if (scrollXLoad || scrollYLoad) {
407
406
  if (scrollXLoad) {
408
407
  this.updateScrollXSpace();
@@ -755,7 +754,6 @@ const Methods = {
755
754
  treeOpts,
756
755
  tableFullData,
757
756
  fullAllDataRowIdData,
758
- fullAllDataRowMap,
759
757
  tableFullTreeData
760
758
  } = this;
761
759
  const childrenField = treeOpts.children || treeOpts.childrenField;
@@ -799,7 +797,6 @@ const Methods = {
799
797
  this.fullDataRowIdData = fullDataRowIdMaps;
800
798
  }
801
799
  this.fullAllDataRowIdData = fullAllDataRowIdMaps;
802
- fullAllDataRowMap.clear();
803
800
  if (treeConfig) {
804
801
  _xeUtils.default.eachTree(tableFullTreeData, handleCache, {
805
802
  children: childrenField
@@ -843,13 +840,12 @@ const Methods = {
843
840
  return this.params;
844
841
  },
845
842
  loadTreeChildren(row, childRecords) {
843
+ const $xeTable = this;
846
844
  const {
847
845
  keepSource,
848
846
  tableSourceData,
849
847
  treeOpts,
850
848
  fullDataRowIdData,
851
- fullDataRowMap,
852
- fullAllDataRowMap,
853
849
  fullAllDataRowIdData,
854
850
  sourceDataRowIdData
855
851
  } = this;
@@ -858,8 +854,8 @@ const Methods = {
858
854
  mapChildrenField
859
855
  } = treeOpts;
860
856
  const childrenField = treeOpts.children || treeOpts.childrenField;
861
- const rest = fullAllDataRowIdData[(0, _util.getRowid)(this, row)];
862
- const parentLevel = rest ? rest.level : 0;
857
+ const parentRest = fullAllDataRowIdData[(0, _util.getRowid)($xeTable, row)];
858
+ const parentLevel = parentRest ? parentRest.level : 0;
863
859
  return this.createData(childRecords).then(rows => {
864
860
  if (keepSource) {
865
861
  const rowid = (0, _util.getRowid)(this, row);
@@ -875,8 +871,8 @@ const Methods = {
875
871
  });
876
872
  }
877
873
  _xeUtils.default.eachTree(rows, (childRow, index, items, path, parent, nodes) => {
878
- const rowid = (0, _util.getRowid)(this, childRow);
879
- const parentRow = parent || row;
874
+ const rowid = (0, _util.getRowid)($xeTable, childRow);
875
+ const parentRow = parent || parentRest.row;
880
876
  const rest = {
881
877
  row: childRow,
882
878
  rowid,
@@ -889,9 +885,7 @@ const Methods = {
889
885
  level: parentLevel + nodes.length
890
886
  };
891
887
  fullDataRowIdData[rowid] = rest;
892
- fullDataRowMap.set(childRow, rest);
893
888
  fullAllDataRowIdData[rowid] = rest;
894
- fullAllDataRowMap.set(childRow, rest);
895
889
  }, {
896
890
  children: childrenField
897
891
  });
@@ -1416,6 +1410,7 @@ const Methods = {
1416
1410
  return null;
1417
1411
  },
1418
1412
  getCellLabel(row, fieldOrColumn) {
1413
+ const $xeTable = this;
1419
1414
  const column = (0, _util.handleFieldOrColumn)(this, fieldOrColumn);
1420
1415
  if (!column) {
1421
1416
  return null;
@@ -1424,17 +1419,17 @@ const Methods = {
1424
1419
  const cellValue = (0, _util.getCellValue)(row, column);
1425
1420
  let cellLabel = cellValue;
1426
1421
  if (formatter) {
1427
- let rest, formatData;
1422
+ let formatData;
1428
1423
  const {
1429
- fullAllDataRowMap
1430
- } = this;
1424
+ fullAllDataRowIdData
1425
+ } = $xeTable;
1426
+ const rowid = (0, _util.getRowid)($xeTable, row);
1431
1427
  const colid = column.id;
1432
- const cacheFormat = fullAllDataRowMap.has(row);
1433
- if (cacheFormat) {
1434
- rest = fullAllDataRowMap.get(row);
1428
+ const rest = fullAllDataRowIdData[rowid];
1429
+ if (rest) {
1435
1430
  formatData = rest.formatData;
1436
1431
  if (!formatData) {
1437
- formatData = fullAllDataRowMap.get(row).formatData = {};
1432
+ formatData = fullAllDataRowIdData[rowid].formatData = {};
1438
1433
  }
1439
1434
  if (rest && formatData[colid]) {
1440
1435
  if (formatData[colid].value === cellValue) {
@@ -1976,8 +1971,9 @@ const Methods = {
1976
1971
  * @param {Row} row 行对象
1977
1972
  */
1978
1973
  getRowid(row) {
1979
- const fullAllDataRowMap = this.fullAllDataRowMap;
1980
- return fullAllDataRowMap.has(row) ? fullAllDataRowMap.get(row).rowid : null;
1974
+ const $xeTable = this;
1975
+ const rowid = _xeUtils.default.get(row, (0, _util.getRowkey)($xeTable));
1976
+ return _xeUtils.default.eqNull(rowid) ? '' : encodeURIComponent(rowid);
1981
1977
  },
1982
1978
  /**
1983
1979
  * 获取处理后的表格数据
@@ -3985,9 +3981,8 @@ const Methods = {
3985
3981
  if (rows && !_xeUtils.default.isArray(rows)) {
3986
3982
  rows = [rows];
3987
3983
  }
3988
- rows.forEach(row => this.handleSelectRow({
3989
- row
3990
- }, !!value, isForce));
3984
+ this.handleBatchSelectRows(rows, !!value, isForce);
3985
+ this.checkSelectionStatus();
3991
3986
  return this.$nextTick();
3992
3987
  },
3993
3988
  /**
@@ -3996,6 +3991,9 @@ const Methods = {
3996
3991
  * @param {Boolean} value 是否选中
3997
3992
  */
3998
3993
  setCheckboxRow(rows, value) {
3994
+ if (rows && !_xeUtils.default.isArray(rows)) {
3995
+ rows = [rows];
3996
+ }
3999
3997
  return this.handleCheckedCheckboxRow(rows, value, true);
4000
3998
  },
4001
3999
  isCheckedByCheckboxRow(row) {
@@ -4016,6 +4014,72 @@ const Methods = {
4016
4014
  } = this;
4017
4015
  return !!treeIndeterminateMaps[(0, _util.getRowid)(this, row)] && !this.isCheckedByCheckboxRow(row);
4018
4016
  },
4017
+ /**
4018
+ * 多行
4019
+ * 多选,行选中事件
4020
+ * value 选中true 不选false 半选-1
4021
+ */
4022
+ handleBatchSelectRows(rows, value, isForce) {
4023
+ const $xeTable = this;
4024
+ const {
4025
+ treeConfig
4026
+ } = $xeTable;
4027
+ const {
4028
+ selectCheckboxMaps,
4029
+ checkboxOpts
4030
+ } = this;
4031
+ const {
4032
+ checkField,
4033
+ checkStrictly,
4034
+ checkMethod
4035
+ } = checkboxOpts;
4036
+ if (checkField) {
4037
+ if (treeConfig && !checkStrictly) {
4038
+ rows.forEach(row => {
4039
+ this.handleSelectRow({
4040
+ row
4041
+ }, value, isForce);
4042
+ });
4043
+ } else {
4044
+ rows.forEach(row => {
4045
+ if (isForce || !checkMethod || checkMethod({
4046
+ row
4047
+ })) {
4048
+ _xeUtils.default.set(row, checkField, value);
4049
+ this.handleCheckboxReserveRow(row, value);
4050
+ }
4051
+ });
4052
+ }
4053
+ } else {
4054
+ if (treeConfig && !checkStrictly) {
4055
+ rows.forEach(row => {
4056
+ this.handleSelectRow({
4057
+ row
4058
+ }, value, isForce);
4059
+ });
4060
+ } else {
4061
+ const selectRowMaps = Object.assign({}, selectCheckboxMaps);
4062
+ rows.forEach(row => {
4063
+ const rowid = (0, _util.getRowid)($xeTable, row);
4064
+ if (isForce || !checkMethod || checkMethod({
4065
+ row
4066
+ })) {
4067
+ if (value) {
4068
+ if (!selectRowMaps[rowid]) {
4069
+ selectRowMaps[rowid] = row;
4070
+ }
4071
+ } else {
4072
+ if (selectRowMaps[rowid]) {
4073
+ delete selectRowMaps[rowid];
4074
+ }
4075
+ }
4076
+ this.handleCheckboxReserveRow(row, value);
4077
+ }
4078
+ });
4079
+ this.selectCheckboxMaps = selectRowMaps;
4080
+ }
4081
+ }
4082
+ },
4019
4083
  /**
4020
4084
  * 多选,行选中事件
4021
4085
  * value 选中true 不选false 半选-1
@@ -4214,7 +4278,6 @@ const Methods = {
4214
4278
  }
4215
4279
  }
4216
4280
  this.selectCheckboxMaps = selectRowMaps;
4217
- this.checkSelectionStatus();
4218
4281
  },
4219
4282
  handleToggleCheckRowEvent(evnt, params) {
4220
4283
  const {
@@ -4241,6 +4304,7 @@ const Methods = {
4241
4304
  this.triggerCheckRowEvent(evnt, params, value);
4242
4305
  } else {
4243
4306
  this.handleSelectRow(params, value);
4307
+ this.checkSelectionStatus();
4244
4308
  }
4245
4309
  },
4246
4310
  triggerCheckRowEvent(evnt, params, value) {
@@ -4280,6 +4344,7 @@ const Methods = {
4280
4344
  row
4281
4345
  })) {
4282
4346
  this.handleSelectRow(params, value);
4347
+ this.checkSelectionStatus();
4283
4348
  this.emitEvent('checkbox-change', Object.assign({
4284
4349
  records: this.getCheckboxRecords(),
4285
4350
  reserves: this.getCheckboxReserveRecords(),
@@ -4303,6 +4368,7 @@ const Methods = {
4303
4368
  this.handleSelectRow({
4304
4369
  row
4305
4370
  }, value, true);
4371
+ this.checkSelectionStatus();
4306
4372
  return this.$nextTick();
4307
4373
  },
4308
4374
  handleCheckedAllCheckboxRow(value, isForce) {
@@ -4542,12 +4608,13 @@ const Methods = {
4542
4608
  },
4543
4609
  // 还原展开、选中等相关状态
4544
4610
  handleReserveStatus() {
4611
+ const $xeTable = this;
4545
4612
  const {
4546
4613
  expandColumn,
4547
4614
  treeOpts,
4548
4615
  treeConfig,
4549
4616
  fullDataRowIdData,
4550
- fullAllDataRowMap,
4617
+ fullAllDataRowIdData,
4551
4618
  currentRow,
4552
4619
  selectRadioRow,
4553
4620
  radioReserveRow,
@@ -4559,7 +4626,7 @@ const Methods = {
4559
4626
  expandOpts
4560
4627
  } = this;
4561
4628
  // 单选框
4562
- if (selectRadioRow && !fullAllDataRowMap.has(selectRadioRow)) {
4629
+ if (selectRadioRow && !fullAllDataRowIdData[(0, _util.getRowid)($xeTable, selectRadioRow)]) {
4563
4630
  this.selectRadioRow = null; // 刷新单选行状态
4564
4631
  }
4565
4632
  // 还原保留选中状态
@@ -4575,7 +4642,7 @@ const Methods = {
4575
4642
  if (checkboxOpts.reserve) {
4576
4643
  this.handleCheckedCheckboxRow(handleReserveRow(this, this.checkboxReserveRowMap), true, true);
4577
4644
  }
4578
- if (currentRow && !fullAllDataRowMap.has(currentRow)) {
4645
+ if (currentRow && !this.fullAllDataRowIdData[(0, _util.getRowid)($xeTable, currentRow)]) {
4579
4646
  this.currentRow = null; // 刷新当前行状态
4580
4647
  }
4581
4648
  // 行展开
@@ -5477,20 +5544,25 @@ const Methods = {
5477
5544
  * @param {Row} row 行对象
5478
5545
  */
5479
5546
  isRowExpandLoaded(row) {
5480
- const rest = this.fullAllDataRowMap.get(row);
5481
- return rest && rest.expandLoaded;
5547
+ const $xeTable = this;
5548
+ const {
5549
+ fullAllDataRowIdData
5550
+ } = this;
5551
+ const rest = fullAllDataRowIdData[(0, _util.getRowid)($xeTable, row)];
5552
+ return rest && !!rest.expandLoaded;
5482
5553
  },
5483
5554
  clearRowExpandLoaded(row) {
5555
+ const $xeTable = this;
5484
5556
  const {
5485
5557
  expandOpts,
5486
5558
  rowExpandLazyLoadedMaps,
5487
- fullAllDataRowMap
5559
+ fullAllDataRowIdData
5488
5560
  } = this;
5489
5561
  const {
5490
5562
  lazy
5491
5563
  } = expandOpts;
5492
- const rowid = (0, _util.getRowid)(this, row);
5493
- const rest = fullAllDataRowMap.get(row);
5564
+ const rowid = (0, _util.getRowid)($xeTable, row);
5565
+ const rest = fullAllDataRowIdData[rowid];
5494
5566
  if (lazy && rest) {
5495
5567
  rest.expandLoaded = false;
5496
5568
  const rowTempExpandLazyLoadedMaps = Object.assign({}, rowExpandLazyLoadedMaps);
@@ -5618,48 +5690,43 @@ const Methods = {
5618
5690
  return this.setRowExpand(expandedRows, expanded);
5619
5691
  },
5620
5692
  handleAsyncRowExpand(row) {
5621
- const {
5622
- fullAllDataRowMap,
5623
- expandOpts
5624
- } = this;
5625
- const rest = fullAllDataRowMap.get(row);
5693
+ const $xeTable = this;
5626
5694
  return new Promise(resolve => {
5695
+ const {
5696
+ expandOpts
5697
+ } = this;
5627
5698
  const {
5628
5699
  loadMethod
5629
5700
  } = expandOpts;
5630
5701
  if (loadMethod) {
5631
5702
  const {
5632
- rowExpandLazyLoadedMaps
5703
+ rowExpandLazyLoadedMaps,
5704
+ fullAllDataRowIdData
5633
5705
  } = this;
5634
- const rowTempExpandLazyLoadedMaps = Object.assign({}, rowExpandLazyLoadedMaps);
5635
- const rowid = (0, _util.getRowid)(this, row);
5636
- rowTempExpandLazyLoadedMaps[rowid] = row;
5637
- this.rowExpandLazyLoadedMaps = rowTempExpandLazyLoadedMaps;
5706
+ const rowid = (0, _util.getRowid)($xeTable, row);
5707
+ const rest = fullAllDataRowIdData[rowid];
5708
+ rowExpandLazyLoadedMaps[rowid] = row;
5638
5709
  loadMethod({
5639
- $table: this,
5710
+ $table: $xeTable,
5640
5711
  row,
5641
5712
  rowIndex: this.getRowIndex(row),
5642
5713
  $rowIndex: this.getVMRowIndex(row)
5643
5714
  }).then(() => {
5644
- rest.expandLoaded = true;
5645
5715
  const {
5646
5716
  rowExpandedMaps
5647
5717
  } = this;
5648
- const rowTempExpandedMaps = Object.assign({}, rowExpandedMaps);
5649
- rowTempExpandedMaps[rowid] = row;
5650
- this.rowExpandedMaps = rowTempExpandedMaps;
5718
+ rest.expandLoaded = true;
5719
+ rowExpandedMaps[rowid] = row;
5651
5720
  }).catch(() => {
5652
5721
  rest.expandLoaded = false;
5653
5722
  }).finally(() => {
5654
5723
  const {
5655
5724
  rowExpandLazyLoadedMaps
5656
5725
  } = this;
5657
- const rowTempExpandLazyLoadedMaps = Object.assign({}, rowExpandLazyLoadedMaps);
5658
- if (rowTempExpandLazyLoadedMaps[rowid]) {
5659
- delete rowTempExpandLazyLoadedMaps[rowid];
5726
+ if (rowExpandLazyLoadedMaps[rowid]) {
5727
+ delete rowExpandLazyLoadedMaps[rowid];
5660
5728
  }
5661
- this.rowExpandLazyLoadedMaps = rowTempExpandLazyLoadedMaps;
5662
- resolve(this.$nextTick().then(this.recalculate));
5729
+ this.$nextTick().then(() => this.recalculate()).then(() => resolve());
5663
5730
  });
5664
5731
  } else {
5665
5732
  resolve();
@@ -5830,21 +5897,26 @@ const Methods = {
5830
5897
  * @param {Row} row 行对象
5831
5898
  */
5832
5899
  isTreeExpandLoaded(row) {
5833
- const rest = this.fullAllDataRowMap.get(row);
5834
- return rest && rest.treeLoaded;
5900
+ const $xeTable = this;
5901
+ const {
5902
+ fullAllDataRowIdData
5903
+ } = this;
5904
+ const rest = fullAllDataRowIdData[(0, _util.getRowid)($xeTable, row)];
5905
+ return rest && !!rest.treeLoaded;
5835
5906
  },
5836
5907
  clearTreeExpandLoaded(row) {
5908
+ const $xeTable = this;
5837
5909
  const {
5838
5910
  treeOpts,
5839
5911
  treeExpandedMaps,
5840
- fullAllDataRowMap
5912
+ fullAllDataRowIdData
5841
5913
  } = this;
5842
5914
  const {
5843
5915
  transform,
5844
5916
  lazy
5845
5917
  } = treeOpts;
5846
- const rowid = (0, _util.getRowid)(this, row);
5847
- const rest = fullAllDataRowMap.get(row);
5918
+ const rowid = (0, _util.getRowid)($xeTable, row);
5919
+ const rest = fullAllDataRowIdData[rowid];
5848
5920
  if (lazy && rest) {
5849
5921
  rest.treeLoaded = false;
5850
5922
  if (treeExpandedMaps[rowid]) {
@@ -5967,6 +6039,7 @@ const Methods = {
5967
6039
  }
5968
6040
  },
5969
6041
  handleAsyncTreeExpandChilds(row) {
6042
+ const $xeTable = this;
5970
6043
  const {
5971
6044
  treeOpts,
5972
6045
  checkboxOpts
@@ -5981,20 +6054,19 @@ const Methods = {
5981
6054
  return new Promise(resolve => {
5982
6055
  if (loadMethod) {
5983
6056
  const {
5984
- fullAllDataRowMap,
5985
- treeExpandLazyLoadedMaps
6057
+ treeExpandLazyLoadedMaps,
6058
+ fullAllDataRowIdData
5986
6059
  } = this;
5987
- const rowid = (0, _util.getRowid)(this, row);
5988
- const rest = fullAllDataRowMap.get(row);
6060
+ const rowid = (0, _util.getRowid)($xeTable, row);
6061
+ const rest = fullAllDataRowIdData[rowid];
5989
6062
  treeExpandLazyLoadedMaps[rowid] = row;
5990
- loadMethod({
5991
- $table: this,
6063
+ Promise.resolve(loadMethod({
6064
+ $table: $xeTable,
5992
6065
  row
5993
- }).then(childRecords => {
5994
- // 响应成功后则展开行,并将子节点挂载到该节点下
6066
+ })).then(childRecords => {
5995
6067
  rest.treeLoaded = true;
5996
6068
  if (treeExpandLazyLoadedMaps[rowid]) {
5997
- treeExpandLazyLoadedMaps[rowid] = null;
6069
+ delete treeExpandLazyLoadedMaps[rowid];
5998
6070
  }
5999
6071
  if (!_xeUtils.default.isArray(childRecords)) {
6000
6072
  childRecords = [];
@@ -6004,14 +6076,12 @@ const Methods = {
6004
6076
  const {
6005
6077
  treeExpandedMaps
6006
6078
  } = this;
6007
- const treeTempExpandedMaps = Object.assign({}, treeExpandedMaps);
6008
- if (childRows.length && !treeTempExpandedMaps[rowid]) {
6009
- treeTempExpandedMaps[rowid] = row;
6010
- this.treeExpandedMaps = treeTempExpandedMaps;
6079
+ if (childRows.length && !treeExpandedMaps[rowid]) {
6080
+ treeExpandedMaps[rowid] = row;
6011
6081
  }
6012
6082
  // 如果当前节点已选中,则展开后子节点也被选中
6013
6083
  if (!checkStrictly && this.isCheckedByCheckboxRow(row)) {
6014
- this.handleCheckedCheckboxRow(childRows, true, true);
6084
+ this.handleCheckedCheckboxRow(childRows, true);
6015
6085
  }
6016
6086
  return this.$nextTick().then(() => {
6017
6087
  if (transform) {
@@ -6021,13 +6091,12 @@ const Methods = {
6021
6091
  });
6022
6092
  }
6023
6093
  }).catch(() => {
6024
- // 如果响应异常,则不展开,再次点击后将重新触发懒加载
6025
- rest.treeLoaded = false;
6026
6094
  const {
6027
6095
  treeExpandLazyLoadedMaps
6028
6096
  } = this;
6097
+ rest.treeLoaded = false;
6029
6098
  if (treeExpandLazyLoadedMaps[rowid]) {
6030
- treeExpandLazyLoadedMaps[rowid] = null;
6099
+ delete treeExpandLazyLoadedMaps[rowid];
6031
6100
  }
6032
6101
  }).finally(() => {
6033
6102
  this.$nextTick().then(() => this.recalculate()).then(() => resolve());
@@ -6069,7 +6138,7 @@ const Methods = {
6069
6138
  */
6070
6139
  handleBaseTreeExpand(rows, expanded) {
6071
6140
  const {
6072
- fullAllDataRowMap,
6141
+ fullAllDataRowIdData,
6073
6142
  tableFullData,
6074
6143
  treeExpandedMaps,
6075
6144
  treeOpts,
@@ -6114,7 +6183,7 @@ const Methods = {
6114
6183
  validRows.forEach(row => {
6115
6184
  const rowid = (0, _util.getRowid)(this, row);
6116
6185
  if (!treeTempExpandedMaps[rowid]) {
6117
- const rest = fullAllDataRowMap.get(row);
6186
+ const rest = fullAllDataRowIdData[rowid];
6118
6187
  const isLoad = lazy && row[hasChildField] && !rest.treeLoaded && !treeExpandLazyLoadedMaps[rowid];
6119
6188
  // 是否使用懒加载
6120
6189
  if (isLoad) {