vxe-table 3.14.0-beta.7 → 3.14.0-beta.9

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.
@@ -965,6 +965,7 @@ function handleCheckedAllCheckboxRow($xeTable, checked, isForce) {
965
965
  reserve,
966
966
  checkMethod
967
967
  } = checkboxOpts;
968
+ // indeterminateField 仅支持读取
968
969
  const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField;
969
970
  const selectRowMaps = {};
970
971
  /**
@@ -2631,6 +2632,10 @@ const Methods = {
2631
2632
  }
2632
2633
  return [];
2633
2634
  },
2635
+ getEl() {
2636
+ const $xeTable = this;
2637
+ return $xeTable.$refs.refElem;
2638
+ },
2634
2639
  /**
2635
2640
  * 获取父容器元素
2636
2641
  */
@@ -3056,8 +3061,6 @@ const Methods = {
3056
3061
  oTop: 0,
3057
3062
  expandHeight: 0
3058
3063
  };
3059
- fullDataRowIdMaps[rowid] = rowRest;
3060
- fullAllDataRowIdMaps[rowid] = rowRest;
3061
3064
  }
3062
3065
  rowRest.treeLoaded = false;
3063
3066
  rowRest.expandLoaded = false;
@@ -3067,6 +3070,8 @@ const Methods = {
3067
3070
  rowRest.level = level;
3068
3071
  rowRest.index = currIndex;
3069
3072
  rowRest.treeIndex = index;
3073
+ fullDataRowIdMaps[rowid] = rowRest;
3074
+ fullAllDataRowIdMaps[rowid] = rowRest;
3070
3075
  };
3071
3076
  if (treeConfig) {
3072
3077
  _xeUtils.default.eachTree(tableFullTreeData, (row, index, items, path, parentRow, nodes) => {
@@ -3096,24 +3101,26 @@ const Methods = {
3096
3101
  reactData.treeExpandedMaps = treeTempExpandedMaps;
3097
3102
  },
3098
3103
  cacheSourceMap(fullData) {
3104
+ const $xeTable = this;
3105
+ const props = $xeTable;
3106
+ const internalData = $xeTable;
3107
+ const {
3108
+ treeConfig
3109
+ } = props;
3110
+ const treeOpts = $xeTable.computeTreeOpts;
3099
3111
  let {
3100
- treeConfig,
3101
- treeOpts,
3102
3112
  sourceDataRowIdData
3103
- } = this;
3113
+ } = internalData;
3104
3114
  const sourceData = _xeUtils.default.clone(fullData, true);
3105
- const rowkey = (0, _util.getRowkey)(this);
3106
- sourceDataRowIdData = this.sourceDataRowIdData = {};
3115
+ const rowkey = (0, _util.getRowkey)($xeTable);
3116
+ sourceDataRowIdData = internalData.sourceDataRowIdData = {};
3107
3117
  const handleSourceRow = row => {
3108
- let rowid = (0, _util.getRowid)(this, row);
3118
+ let rowid = (0, _util.getRowid)($xeTable, row);
3109
3119
  if ((0, _utils.eqEmptyValue)(rowid)) {
3110
3120
  rowid = (0, _util.getRowUniqueId)();
3111
3121
  _xeUtils.default.set(row, rowkey, rowid);
3112
3122
  }
3113
- sourceDataRowIdData[rowid] = {
3114
- row,
3115
- rowid
3116
- };
3123
+ sourceDataRowIdData[rowid] = row;
3117
3124
  };
3118
3125
  // 源数据缓存
3119
3126
  if (treeConfig) {
@@ -3124,7 +3131,7 @@ const Methods = {
3124
3131
  } else {
3125
3132
  sourceData.forEach(handleSourceRow);
3126
3133
  }
3127
- this.tableSourceData = sourceData;
3134
+ internalData.tableSourceData = sourceData;
3128
3135
  },
3129
3136
  getParams() {
3130
3137
  return this.params;
@@ -3485,6 +3492,9 @@ const Methods = {
3485
3492
  keepSource,
3486
3493
  treeConfig
3487
3494
  } = props;
3495
+ const {
3496
+ editStore
3497
+ } = reactData;
3488
3498
  const {
3489
3499
  fullAllDataRowIdData,
3490
3500
  fullDataRowIdData,
@@ -3493,6 +3503,7 @@ const Methods = {
3493
3503
  tableFullData,
3494
3504
  afterFullData
3495
3505
  } = internalData;
3506
+ const removeTempMaps = Object.assign({}, editStore.removeMaps);
3496
3507
  const treeOpts = $xeTable.computeTreeOpts;
3497
3508
  const {
3498
3509
  transform
@@ -3527,6 +3538,7 @@ const Methods = {
3527
3538
  _xeUtils.default.destructuring(row, _xeUtils.default.clone(oRow, true));
3528
3539
  }
3529
3540
  if (!fullDataRowIdData[rowid] && $xeTable.isRemoveByRow(row)) {
3541
+ delete removeTempMaps[rowid];
3530
3542
  tableFullData.unshift(row);
3531
3543
  afterFullData.unshift(row);
3532
3544
  reDelFlag = true;
@@ -3538,6 +3550,7 @@ const Methods = {
3538
3550
  }
3539
3551
  if (rows) {
3540
3552
  if (reDelFlag) {
3553
+ editStore.removeMaps = removeTempMaps;
3541
3554
  $xeTable.updateFooter();
3542
3555
  $xeTable.cacheRowMap(false);
3543
3556
  $xeTable.handleTableData(treeConfig && transform);
@@ -3717,25 +3730,31 @@ const Methods = {
3717
3730
  },
3718
3731
  /**
3719
3732
  * 检查行或列数据是否发生改变
3720
- * @param {Row} row 行对象
3733
+ * @param {Row} rowOrId 行对象
3721
3734
  * @param {String} field 字段名
3722
3735
  */
3723
- isUpdateByRow(row, field) {
3736
+ isUpdateByRow(rowOrId, field) {
3737
+ const $xeTable = this;
3738
+ const props = $xeTable;
3739
+ const internalData = $xeTable;
3740
+ const {
3741
+ keepSource
3742
+ } = props;
3724
3743
  const {
3725
3744
  tableFullColumn,
3726
- keepSource,
3727
- sourceDataRowIdData,
3728
- fullDataRowIdData
3729
- } = this;
3745
+ fullDataRowIdData,
3746
+ sourceDataRowIdData
3747
+ } = internalData;
3730
3748
  if (keepSource) {
3731
- const rowid = (0, _util.getRowid)(this, row);
3749
+ const rowid = _xeUtils.default.isString(rowOrId) || _xeUtils.default.isNumber(rowOrId) ? rowOrId : (0, _util.getRowid)($xeTable, rowOrId);
3750
+ const rowRest = fullDataRowIdData[rowid];
3732
3751
  // 新增的数据不需要检测
3733
- if (!fullDataRowIdData[rowid]) {
3752
+ if (!rowRest) {
3734
3753
  return false;
3735
3754
  }
3736
- const oldRest = sourceDataRowIdData[rowid];
3737
- if (oldRest) {
3738
- const oRow = oldRest.row;
3755
+ const row = rowRest.row;
3756
+ const oRow = sourceDataRowIdData[rowid];
3757
+ if (oRow) {
3739
3758
  if (arguments.length > 1) {
3740
3759
  return !eqCellValue(oRow, row, field);
3741
3760
  }
@@ -3797,6 +3816,113 @@ const Methods = {
3797
3816
  tableColumn: this.tableColumn.slice(0)
3798
3817
  };
3799
3818
  },
3819
+ /**
3820
+ * 移动列到指定列的位置
3821
+ * @param fieldOrColumn
3822
+ * @param targetFieldOrColumn
3823
+ * @param options
3824
+ */
3825
+ moveColumnTo(fieldOrColumn, targetFieldOrColumn, options) {
3826
+ const $xeTable = this;
3827
+ const internalData = $xeTable;
3828
+ const {
3829
+ fullColumnIdData,
3830
+ visibleColumn
3831
+ } = internalData;
3832
+ const {
3833
+ dragToChild,
3834
+ dragPos,
3835
+ isCrossDrag
3836
+ } = Object.assign({}, options);
3837
+ const dragCol = (0, _util.handleFieldOrColumn)($xeTable, fieldOrColumn);
3838
+ let prevDragCol = null;
3839
+ const colRest = dragCol ? fullColumnIdData[dragCol.id] : null;
3840
+ let defPos = 'left';
3841
+ if (_xeUtils.default.isNumber(targetFieldOrColumn)) {
3842
+ if (colRest && targetFieldOrColumn) {
3843
+ let currList = colRest.items;
3844
+ let offsetIndex = colRest._index + targetFieldOrColumn;
3845
+ if (isCrossDrag) {
3846
+ currList = visibleColumn;
3847
+ offsetIndex = colRest._index + targetFieldOrColumn;
3848
+ }
3849
+ if (offsetIndex > 0 && offsetIndex < currList.length - 1) {
3850
+ prevDragCol = currList[offsetIndex];
3851
+ }
3852
+ if (targetFieldOrColumn > 0) {
3853
+ defPos = 'right';
3854
+ }
3855
+ }
3856
+ } else {
3857
+ prevDragCol = (0, _util.handleFieldOrColumn)($xeTable, targetFieldOrColumn);
3858
+ const targetColRest = prevDragCol ? fullColumnIdData[prevDragCol.id] : null;
3859
+ if (colRest && targetColRest) {
3860
+ if (targetColRest._index > colRest._index) {
3861
+ defPos = 'right';
3862
+ }
3863
+ }
3864
+ }
3865
+ return $xeTable.handleColDragSwapEvent(null, true, dragCol, prevDragCol, dragPos || defPos, dragToChild === true);
3866
+ },
3867
+ /**
3868
+ * 移动行到指定行的位置
3869
+ * @param rowidOrRow
3870
+ * @param targetRowidOrRow
3871
+ * @param options
3872
+ */
3873
+ moveRowTo(rowidOrRow, targetRowidOrRow, options) {
3874
+ const $xeTable = this;
3875
+ const props = $xeTable;
3876
+ const internalData = $xeTable;
3877
+ const {
3878
+ treeConfig
3879
+ } = props;
3880
+ const {
3881
+ fullAllDataRowIdData,
3882
+ afterFullData
3883
+ } = internalData;
3884
+ const {
3885
+ dragToChild,
3886
+ dragPos,
3887
+ isCrossDrag
3888
+ } = Object.assign({}, options);
3889
+ const treeOpts = $xeTable.computeTreeOpts;
3890
+ const dragRow = (0, _util.handleRowidOrRow)($xeTable, rowidOrRow);
3891
+ let prevDragRow = null;
3892
+ let defPos = 'top';
3893
+ const rowRest = dragRow ? fullAllDataRowIdData[(0, _util.getRowid)($xeTable, dragRow)] : null;
3894
+ if (_xeUtils.default.isNumber(targetRowidOrRow)) {
3895
+ if (rowRest && targetRowidOrRow) {
3896
+ let currList = afterFullData;
3897
+ let offsetIndex = rowRest._index + targetRowidOrRow;
3898
+ if (treeConfig) {
3899
+ currList = rowRest.items;
3900
+ if (treeOpts.transform) {
3901
+ offsetIndex = rowRest.treeIndex + targetRowidOrRow;
3902
+ if (isCrossDrag) {
3903
+ currList = afterFullData;
3904
+ offsetIndex = rowRest._index + targetRowidOrRow;
3905
+ }
3906
+ }
3907
+ }
3908
+ if (offsetIndex >= 0 && offsetIndex <= currList.length - 1) {
3909
+ prevDragRow = currList[offsetIndex];
3910
+ }
3911
+ if (targetRowidOrRow > 0) {
3912
+ defPos = 'bottom';
3913
+ }
3914
+ }
3915
+ } else {
3916
+ prevDragRow = (0, _util.handleRowidOrRow)($xeTable, targetRowidOrRow);
3917
+ const targetRowRest = prevDragRow ? fullAllDataRowIdData[(0, _util.getRowid)($xeTable, prevDragRow)] : null;
3918
+ if (rowRest && targetRowRest) {
3919
+ if (targetRowRest._index > rowRest._index) {
3920
+ defPos = 'bottom';
3921
+ }
3922
+ }
3923
+ }
3924
+ return $xeTable.handleRowDragSwapEvent(null, true, dragRow, prevDragRow, dragPos || defPos, dragToChild === true);
3925
+ },
3800
3926
  /**
3801
3927
  * 获取表格的全量列
3802
3928
  */
@@ -3819,16 +3945,26 @@ const Methods = {
3819
3945
  * 用于多选行,获取已选中的数据
3820
3946
  */
3821
3947
  getCheckboxRecords(isFull) {
3948
+ const $xeTable = this;
3949
+ const props = $xeTable;
3950
+ const reactData = $xeTable;
3951
+ const internalData = $xeTable;
3952
+ const {
3953
+ treeConfig
3954
+ } = props;
3955
+ const {
3956
+ selectCheckboxMaps
3957
+ } = reactData;
3822
3958
  const {
3823
3959
  tableFullData,
3824
3960
  afterFullData,
3825
- treeConfig,
3826
- treeOpts,
3827
- checkboxOpts,
3828
- tableFullTreeData,
3829
3961
  afterTreeFullData,
3962
+ tableFullTreeData,
3963
+ fullDataRowIdData,
3830
3964
  afterFullRowMaps
3831
- } = this;
3965
+ } = internalData;
3966
+ const treeOpts = $xeTable.computeTreeOpts;
3967
+ const checkboxOpts = $xeTable.computeCheckboxOpts;
3832
3968
  const {
3833
3969
  transform,
3834
3970
  mapChildrenField
@@ -3837,21 +3973,18 @@ const Methods = {
3837
3973
  checkField
3838
3974
  } = checkboxOpts;
3839
3975
  const childrenField = treeOpts.children || treeOpts.childrenField;
3840
- const currTableData = isFull ? transform ? tableFullTreeData : tableFullData : transform ? afterTreeFullData : afterFullData;
3841
3976
  let rowList = [];
3842
3977
  if (checkField) {
3843
3978
  if (treeConfig) {
3979
+ const currTableData = isFull ? transform ? tableFullTreeData : tableFullData : transform ? afterTreeFullData : afterFullData;
3844
3980
  rowList = _xeUtils.default.filterTree(currTableData, row => _xeUtils.default.get(row, checkField), {
3845
3981
  children: transform ? mapChildrenField : childrenField
3846
3982
  });
3847
3983
  } else {
3984
+ const currTableData = isFull ? tableFullData : afterFullData;
3848
3985
  rowList = currTableData.filter(row => _xeUtils.default.get(row, checkField));
3849
3986
  }
3850
3987
  } else {
3851
- const {
3852
- selectCheckboxMaps,
3853
- fullDataRowIdData
3854
- } = this;
3855
3988
  _xeUtils.default.each(selectCheckboxMaps, (row, rowid) => {
3856
3989
  if (isFull) {
3857
3990
  if (fullDataRowIdData[rowid]) {
@@ -6326,6 +6459,7 @@ const Methods = {
6326
6459
  checkStrictly,
6327
6460
  checkMethod
6328
6461
  } = checkboxOpts;
6462
+ // indeterminateField 仅支持读取
6329
6463
  const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField;
6330
6464
  if (checkField) {
6331
6465
  // 树结构
@@ -6852,6 +6986,7 @@ const Methods = {
6852
6986
  reserve
6853
6987
  } = checkboxOpts;
6854
6988
  const childrenField = treeOpts.children || treeOpts.childrenField;
6989
+ // indeterminateField 仅支持读取
6855
6990
  const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField;
6856
6991
  if (checkField) {
6857
6992
  const handleClearChecked = item => {
@@ -7623,6 +7758,9 @@ const Methods = {
7623
7758
  } = internalData;
7624
7759
  const dEndMethod = dragEndMethod || (dragConfig ? dragConfig.dragEndMethod : null);
7625
7760
  const dragOffsetIndex = prevDragPos === 'bottom' ? 1 : 0;
7761
+ const errRest = {
7762
+ status: false
7763
+ };
7626
7764
  if (prevDragRow && dragRow) {
7627
7765
  // 判断是否有拖动
7628
7766
  if (prevDragRow !== dragRow) {
@@ -7637,7 +7775,7 @@ const Methods = {
7637
7775
  const isDragToChildFlag = isSelfToChildDrag && dragToChildMethod ? dragToChildMethod(dragParams) : prevDragToChild;
7638
7776
  return Promise.resolve(dEndMethod ? dEndMethod(dragParams) : true).then(status => {
7639
7777
  if (!status) {
7640
- return;
7778
+ return errRest;
7641
7779
  }
7642
7780
  let oafIndex = -1;
7643
7781
  let nafIndex = -1;
@@ -7668,11 +7806,11 @@ const Methods = {
7668
7806
  if (isPeerDrag && !isCrossDrag) {
7669
7807
  if (oldRest.row[parentField] !== newRest.row[parentField]) {
7670
7808
  // 非同级
7671
- return;
7809
+ return errRest;
7672
7810
  }
7673
7811
  } else {
7674
7812
  if (!isCrossDrag) {
7675
- return;
7813
+ return errRest;
7676
7814
  }
7677
7815
  if (oldAllMaps[newRowid]) {
7678
7816
  isSelfToChildStatus = true;
@@ -7683,19 +7821,19 @@ const Methods = {
7683
7821
  content: getI18n('vxe.error.treeDragChild')
7684
7822
  });
7685
7823
  }
7686
- return;
7824
+ return errRest;
7687
7825
  }
7688
7826
  }
7689
7827
  }
7690
7828
  } else if (oldLevel) {
7691
7829
  // 子到根
7692
7830
  if (!isCrossDrag) {
7693
- return;
7831
+ return errRest;
7694
7832
  }
7695
7833
  } else if (newLevel) {
7696
7834
  // 根到子
7697
7835
  if (!isCrossDrag) {
7698
- return;
7836
+ return errRest;
7699
7837
  }
7700
7838
  if (oldAllMaps[newRowid]) {
7701
7839
  isSelfToChildStatus = true;
@@ -7706,7 +7844,7 @@ const Methods = {
7706
7844
  content: getI18n('vxe.error.treeDragChild')
7707
7845
  });
7708
7846
  }
7709
- return;
7847
+ return errRest;
7710
7848
  }
7711
7849
  }
7712
7850
  } else {
@@ -7764,26 +7902,34 @@ const Methods = {
7764
7902
  if (reactData.scrollYLoad) {
7765
7903
  $xeTable.updateScrollYSpace();
7766
7904
  }
7767
- $xeTable.$nextTick().then(() => {
7905
+ if (evnt) {
7906
+ $xeTable.dispatchEvent('row-dragend', {
7907
+ oldRow: dragRow,
7908
+ newRow: prevDragRow,
7909
+ dragRow,
7910
+ dragPos: prevDragPos,
7911
+ dragToChild: isDragToChildFlag,
7912
+ offsetIndex: dragOffsetIndex,
7913
+ _index: {
7914
+ newIndex: nafIndex,
7915
+ oldIndex: oafIndex
7916
+ }
7917
+ }, evnt);
7918
+ }
7919
+ return $xeTable.$nextTick().then(() => {
7768
7920
  $xeTable.updateCellAreas();
7769
7921
  $xeTable.recalculate();
7922
+ }).then(() => {
7923
+ return {
7924
+ status: true
7925
+ };
7770
7926
  });
7771
- $xeTable.dispatchEvent('row-dragend', {
7772
- oldRow: dragRow,
7773
- newRow: prevDragRow,
7774
- dragRow,
7775
- dragPos: prevDragPos,
7776
- dragToChild: isDragToChildFlag,
7777
- offsetIndex: dragOffsetIndex,
7778
- _index: {
7779
- newIndex: nafIndex,
7780
- oldIndex: oafIndex
7781
- }
7782
- }, evnt);
7783
- }).catch(() => {});
7927
+ }).catch(() => {
7928
+ return errRest;
7929
+ });
7784
7930
  }
7785
7931
  }
7786
- return Promise.resolve();
7932
+ return Promise.resolve(errRest);
7787
7933
  },
7788
7934
  handleRowDragDragendEvent(evnt) {
7789
7935
  const $xeTable = this;
@@ -7970,6 +8116,9 @@ const Methods = {
7970
8116
  collectColumn
7971
8117
  } = internalData;
7972
8118
  const dragOffsetIndex = prevDragPos === 'right' ? 1 : 0;
8119
+ const errRest = {
8120
+ status: false
8121
+ };
7973
8122
  if (prevDragCol && dragCol) {
7974
8123
  // 判断是否有拖动
7975
8124
  if (prevDragCol !== dragCol) {
@@ -7986,7 +8135,7 @@ const Methods = {
7986
8135
  const isDragToChildFlag = isSelfToChildDrag && dragToChildMethod ? dragToChildMethod(dragParams) : prevDragToChild;
7987
8136
  return Promise.resolve(dragEndMethod ? dragEndMethod(dragParams) : true).then(status => {
7988
8137
  if (!status) {
7989
- return;
8138
+ return errRest;
7990
8139
  }
7991
8140
  let oafIndex = -1;
7992
8141
  let nafIndex = -1;
@@ -8000,11 +8149,11 @@ const Methods = {
8000
8149
  if (isPeerDrag && !isCrossDrag) {
8001
8150
  if (dragColumn.parentId !== newColumn.parentId) {
8002
8151
  // 非同级
8003
- return;
8152
+ return errRest;
8004
8153
  }
8005
8154
  } else {
8006
8155
  if (!isCrossDrag) {
8007
- return;
8156
+ return errRest;
8008
8157
  }
8009
8158
  if (oldAllMaps[newColumn.id]) {
8010
8159
  isSelfToChildStatus = true;
@@ -8015,19 +8164,19 @@ const Methods = {
8015
8164
  content: getI18n('vxe.error.treeDragChild')
8016
8165
  });
8017
8166
  }
8018
- return;
8167
+ return errRest;
8019
8168
  }
8020
8169
  }
8021
8170
  }
8022
8171
  } else if (dragColumn.parentId) {
8023
8172
  // 子到根
8024
8173
  if (!isCrossDrag) {
8025
- return;
8174
+ return errRest;
8026
8175
  }
8027
8176
  } else if (newColumn.parentId) {
8028
8177
  // 根到子
8029
8178
  if (!isCrossDrag) {
8030
- return;
8179
+ return errRest;
8031
8180
  }
8032
8181
  if (oldAllMaps[newColumn.id]) {
8033
8182
  isSelfToChildStatus = true;
@@ -8038,7 +8187,7 @@ const Methods = {
8038
8187
  content: getI18n('vxe.error.treeDragChild')
8039
8188
  });
8040
8189
  }
8041
- return;
8190
+ return errRest;
8042
8191
  }
8043
8192
  }
8044
8193
  } else {
@@ -8107,25 +8256,32 @@ const Methods = {
8107
8256
  $xeTable.clearCopyCellArea();
8108
8257
  }
8109
8258
  }
8110
- $xeTable.dispatchEvent('column-dragend', {
8111
- oldColumn: dragColumn,
8112
- newColumn,
8113
- dragColumn,
8114
- dragPos: prevDragPos,
8115
- dragToChild: isDragToChildFlag,
8116
- offsetIndex: dragOffsetIndex,
8117
- _index: {
8118
- newIndex: nafIndex,
8119
- oldIndex: oafIndex
8120
- }
8121
- }, evnt);
8259
+ if (evnt) {
8260
+ $xeTable.dispatchEvent('column-dragend', {
8261
+ oldColumn: dragColumn,
8262
+ newColumn,
8263
+ dragColumn,
8264
+ dragPos: prevDragPos,
8265
+ dragToChild: isDragToChildFlag,
8266
+ offsetIndex: dragOffsetIndex,
8267
+ _index: {
8268
+ newIndex: nafIndex,
8269
+ oldIndex: oafIndex
8270
+ }
8271
+ }, evnt);
8272
+ }
8122
8273
  if (isSyncColumn) {
8123
8274
  $xeTable.handleColDragSwapColumn();
8124
8275
  }
8125
- }).catch(() => {});
8276
+ return {
8277
+ status: true
8278
+ };
8279
+ }).catch(() => {
8280
+ return errRest;
8281
+ });
8126
8282
  }
8127
8283
  }
8128
- return Promise.resolve();
8284
+ return Promise.resolve(errRest);
8129
8285
  },
8130
8286
  handleHeaderCellDragDragendEvent(evnt) {
8131
8287
  const $xeTable = this;