vxe-table 4.7.10 → 4.7.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.
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _tslib = require("tslib");
7
8
  var _vue = require("vue");
8
9
  var _xeUtils = _interopRequireDefault(require("xe-utils"));
9
10
  var _dom = require("../../ui/src/dom");
@@ -38,10 +39,7 @@ const {
38
39
  useFns
39
40
  } = _ui.VxeUI;
40
41
  const isWebkit = _dom.browse['-webkit'] && !_dom.browse.edge;
41
- const resizableStorageKey = 'VXE_TABLE_CUSTOM_COLUMN_WIDTH';
42
- const visibleStorageKey = 'VXE_TABLE_CUSTOM_COLUMN_VISIBLE';
43
- const fixedStorageKey = 'VXE_TABLE_CUSTOM_COLUMN_FIXED';
44
- const sortStorageKey = 'VXE_TABLE_CUSTOM_COLUMN_SORT';
42
+ const customStorageKey = 'VXE_CUSTOM_STORE';
45
43
  var _default = exports.default = (0, _vue.defineComponent)({
46
44
  name: 'VxeTable',
47
45
  props: _props.default,
@@ -665,12 +663,20 @@ var _default = exports.default = (0, _vue.defineComponent)({
665
663
  const oIndex = orders.indexOf(currOrder) + 1;
666
664
  return orders[oIndex < orders.length ? oIndex : 0];
667
665
  };
668
- const getCustomStorageMap = key => {
666
+ const getCustomStorageMap = id => {
669
667
  const version = getConfig().version;
670
- const rest = _xeUtils.default.toStringJSON(localStorage.getItem(key) || '');
671
- return rest && rest._v === version ? rest : {
668
+ const rest = _xeUtils.default.toStringJSON(localStorage.getItem(customStorageKey) || '');
669
+ const maps = rest && rest._v === version ? rest : {
672
670
  _v: version
673
671
  };
672
+ return (id ? maps[id] : maps) || {};
673
+ };
674
+ const setCustomStorageMap = (id, data) => {
675
+ const version = getConfig().version;
676
+ const maps = getCustomStorageMap();
677
+ maps[id] = data || undefined;
678
+ maps._v = version;
679
+ localStorage.setItem(customStorageKey, _xeUtils.default.toJSONString(maps));
674
680
  };
675
681
  const getRecoverRowMaps = keyMaps => {
676
682
  const {
@@ -909,11 +915,14 @@ var _default = exports.default = (0, _vue.defineComponent)({
909
915
  /**
910
916
  * 还原自定义列操作状态
911
917
  */
912
- const restoreCustomStorage = () => {
918
+ const restoreCustomStorage = () => (0, _tslib.__awaiter)(this, void 0, void 0, function* () {
913
919
  const {
914
920
  id,
915
921
  customConfig
916
922
  } = props;
923
+ const {
924
+ tableFullColumn
925
+ } = internalData;
917
926
  const customOpts = computeCustomOpts.value;
918
927
  const {
919
928
  storage,
@@ -925,131 +934,59 @@ var _default = exports.default = (0, _vue.defineComponent)({
925
934
  const isCustomVisible = isAllCustom || storageOpts.visible;
926
935
  const isCustomFixed = isAllCustom || storageOpts.fixed;
927
936
  const isCustomSort = isAllCustom || storageOpts.sort;
928
- if (storage && id && restoreStore) {
929
- restoreStore({
930
- id
931
- });
932
- }
933
937
  if (customConfig && (isCustomResizable || isCustomVisible || isCustomFixed || isCustomSort)) {
934
- const customMap = {};
935
938
  if (!id) {
936
939
  (0, _log.errLog)('vxe.error.reqProp', ['id']);
937
940
  return;
938
941
  }
939
- // 自定义列宽
940
- if (isCustomResizable) {
941
- const columnWidthStorage = getCustomStorageMap(resizableStorageKey)[id];
942
- if (columnWidthStorage) {
943
- _xeUtils.default.each(columnWidthStorage, (resizeWidth, colKey) => {
944
- customMap[colKey] = {
945
- resizeWidth
946
- };
947
- });
948
- }
949
- }
950
- // 自定义固定列
951
- if (isCustomFixed) {
952
- const columnFixedStorage = getCustomStorageMap(fixedStorageKey)[id];
953
- if (columnFixedStorage) {
954
- const colFixeds = columnFixedStorage.split(',');
955
- colFixeds.forEach(fixConf => {
956
- const [colKey, fixed] = fixConf.split('|');
957
- if (customMap[colKey]) {
958
- customMap[colKey].fixed = fixed;
959
- } else {
960
- customMap[colKey] = {
961
- fixed
962
- };
963
- }
964
- });
965
- }
966
- }
967
- // 自定义顺序
968
- let hasCustomSort = false;
969
- if (isCustomSort) {
970
- const columnSortStorage = getCustomStorageMap(sortStorageKey)[id];
971
- if (columnSortStorage) {
972
- _xeUtils.default.each(columnSortStorage, (renderSortNumber, colKey) => {
973
- if (customMap[colKey]) {
974
- customMap[colKey].renderSortNumber = renderSortNumber;
975
- } else {
976
- customMap[colKey] = {
977
- renderSortNumber
978
- };
979
- }
980
- if (!hasCustomSort) {
981
- hasCustomSort = true;
982
- }
983
- });
984
- }
942
+ let storeData = getCustomStorageMap(id);
943
+ if (restoreStore) {
944
+ storeData = yield restoreStore({
945
+ id,
946
+ type: 'restore',
947
+ storeData
948
+ });
985
949
  }
986
- // 自定义隐藏列
987
- if (isCustomVisible) {
988
- const columnVisibleStorage = getCustomStorageMap(visibleStorageKey)[id];
989
- if (columnVisibleStorage) {
990
- const colVisibles = columnVisibleStorage.split('|');
991
- const colHides = colVisibles[0] ? colVisibles[0].split(',') : [];
992
- const colShows = colVisibles[1] ? colVisibles[1].split(',') : [];
993
- colHides.forEach(colKey => {
994
- if (customMap[colKey]) {
995
- customMap[colKey].visible = false;
996
- } else {
997
- customMap[colKey] = {
998
- visible: false
999
- };
1000
- }
1001
- });
1002
- colShows.forEach(colKey => {
1003
- if (customMap[colKey]) {
1004
- customMap[colKey].visible = true;
1005
- } else {
1006
- customMap[colKey] = {
1007
- visible: true
1008
- };
1009
- }
1010
- });
1011
- }
950
+ if (!storeData) {
951
+ return;
1012
952
  }
1013
953
  let {
1014
954
  collectColumn
1015
955
  } = internalData;
1016
- const keyMap = {};
1017
- _xeUtils.default.eachTree(collectColumn, column => {
1018
- const colKey = column.getKey();
1019
- if (colKey) {
1020
- keyMap[colKey] = column;
1021
- }
1022
- });
1023
- _xeUtils.default.each(customMap, ({
1024
- visible,
1025
- resizeWidth,
1026
- fixed,
1027
- renderSortNumber
1028
- }, colKey) => {
1029
- const column = keyMap[colKey];
1030
- if (column) {
1031
- if (_xeUtils.default.isNumber(resizeWidth)) {
1032
- column.resizeWidth = resizeWidth;
956
+ const {
957
+ resizableData,
958
+ sortData,
959
+ visibleData,
960
+ fixedData
961
+ } = storeData;
962
+ let hasCustomSort = false;
963
+ // 处理还原
964
+ if (resizableData || sortData || visibleData || fixedData) {
965
+ tableFullColumn.forEach(column => {
966
+ const colKey = column.getKey();
967
+ if (resizableData && _xeUtils.default.isNumber(resizableData[colKey])) {
968
+ column.resizeWidth = resizableData[colKey];
1033
969
  }
1034
- if (_xeUtils.default.isBoolean(visible)) {
1035
- column.visible = visible;
970
+ if (visibleData && _xeUtils.default.isBoolean(visibleData[colKey])) {
971
+ column.visible = visibleData[colKey];
1036
972
  }
1037
- if (fixed) {
1038
- column.fixed = fixed;
973
+ if (fixedData && fixedData[colKey]) {
974
+ column.fixed = fixedData[colKey];
1039
975
  }
1040
- if (renderSortNumber) {
1041
- column.renderSortNumber = Number(renderSortNumber);
976
+ if (sortData && _xeUtils.default.isNumber(sortData[colKey])) {
977
+ hasCustomSort = true;
978
+ column.renderSortNumber = sortData[colKey];
1042
979
  }
980
+ });
981
+ // 如果自定义了顺序
982
+ if (hasCustomSort) {
983
+ collectColumn = _xeUtils.default.orderBy(collectColumn, 'renderSortNumber');
984
+ internalData.collectColumn = collectColumn;
985
+ internalData.tableFullColumn = getColumnList(collectColumn);
1043
986
  }
1044
- });
1045
- // 如果自定义了顺序
1046
- if (hasCustomSort) {
1047
- collectColumn = _xeUtils.default.orderBy(collectColumn, 'renderSortNumber');
1048
- internalData.collectColumn = collectColumn;
1049
- internalData.tableFullColumn = getColumnList(collectColumn);
1050
987
  }
1051
988
  }
1052
- };
989
+ });
1053
990
  /**
1054
991
  * 更新数据列的 Map
1055
992
  * 牺牲数据组装的耗时,用来换取使用过程中的流畅
@@ -2913,29 +2850,30 @@ var _default = exports.default = (0, _vue.defineComponent)({
2913
2850
  const tableFullColumn = getColumnList(collectColumn);
2914
2851
  internalData.tableFullColumn = tableFullColumn;
2915
2852
  initColumnSort();
2916
- restoreCustomStorage();
2917
- cacheColumnMap();
2918
- parseColumns().then(() => {
2919
- if (reactData.scrollXLoad) {
2920
- loadScrollXData();
2921
- }
2922
- });
2923
- tableMethods.clearMergeCells();
2924
- tableMethods.clearMergeFooterItems();
2925
- tablePrivateMethods.handleTableData(true);
2926
- if (process.env.NODE_ENV === 'development') {
2927
- if ((reactData.scrollXLoad || reactData.scrollYLoad) && reactData.expandColumn) {
2928
- (0, _log.warnLog)('vxe.error.scrollErrProp', ['column.type=expand']);
2929
- }
2930
- }
2931
- return (0, _vue.nextTick)().then(() => {
2932
- if ($xeToolbar) {
2933
- $xeToolbar.syncUpdate({
2934
- collectColumn,
2935
- $table: $xeTable
2936
- });
2853
+ return restoreCustomStorage().then(() => {
2854
+ cacheColumnMap();
2855
+ parseColumns().then(() => {
2856
+ if (reactData.scrollXLoad) {
2857
+ loadScrollXData();
2858
+ }
2859
+ });
2860
+ tableMethods.clearMergeCells();
2861
+ tableMethods.clearMergeFooterItems();
2862
+ tablePrivateMethods.handleTableData(true);
2863
+ if (process.env.NODE_ENV === 'development') {
2864
+ if ((reactData.scrollXLoad || reactData.scrollYLoad) && reactData.expandColumn) {
2865
+ (0, _log.warnLog)('vxe.error.scrollErrProp', ['column.type=expand']);
2866
+ }
2937
2867
  }
2938
- return tableMethods.recalculate();
2868
+ return (0, _vue.nextTick)().then(() => {
2869
+ if ($xeToolbar) {
2870
+ $xeToolbar.syncUpdate({
2871
+ collectColumn,
2872
+ $table: $xeTable
2873
+ });
2874
+ }
2875
+ return tableMethods.recalculate();
2876
+ });
2939
2877
  });
2940
2878
  };
2941
2879
  const updateScrollYStatus = fullData => {
@@ -3781,7 +3719,7 @@ var _default = exports.default = (0, _vue.defineComponent)({
3781
3719
  _xeUtils.default.eachTree([targetColumn], column => {
3782
3720
  column.fixed = fixed;
3783
3721
  });
3784
- tablePrivateMethods.saveCustomFixed();
3722
+ tablePrivateMethods.saveCustomStore('update:fixed');
3785
3723
  return tableMethods.refreshColumn();
3786
3724
  }
3787
3725
  return (0, _vue.nextTick)();
@@ -3796,7 +3734,7 @@ var _default = exports.default = (0, _vue.defineComponent)({
3796
3734
  _xeUtils.default.eachTree([targetColumn], column => {
3797
3735
  column.fixed = null;
3798
3736
  });
3799
- tablePrivateMethods.saveCustomFixed();
3737
+ tablePrivateMethods.saveCustomStore('update:fixed');
3800
3738
  return tableMethods.refreshColumn();
3801
3739
  }
3802
3740
  return (0, _vue.nextTick)();
@@ -3881,15 +3819,7 @@ var _default = exports.default = (0, _vue.defineComponent)({
3881
3819
  }
3882
3820
  column.renderResizeWidth = column.renderWidth;
3883
3821
  });
3884
- if (opts.resizable) {
3885
- tablePrivateMethods.saveCustomResizable(true);
3886
- }
3887
- if (opts.sort) {
3888
- tablePrivateMethods.saveCustomSort(true);
3889
- }
3890
- if (opts.fixed) {
3891
- tablePrivateMethods.saveCustomFixed();
3892
- }
3822
+ $xeTable.saveCustomStore('reset');
3893
3823
  return tablePrivateMethods.handleCustom();
3894
3824
  },
3895
3825
  /**
@@ -5244,21 +5174,26 @@ var _default = exports.default = (0, _vue.defineComponent)({
5244
5174
  const visibleData = {};
5245
5175
  const fixedData = {};
5246
5176
  const storeData = {
5247
- resizableData,
5248
- sortData,
5249
- visibleData,
5250
- fixedData
5177
+ resizableData: undefined,
5178
+ sortData: undefined,
5179
+ visibleData: undefined,
5180
+ fixedData: undefined
5251
5181
  };
5252
5182
  if (!id) {
5253
5183
  (0, _log.errLog)('vxe.error.reqProp', ['id']);
5254
5184
  return storeData;
5255
5185
  }
5186
+ let hasResizable = 0;
5187
+ let hasSort = 0;
5188
+ let hasFixedt = 0;
5189
+ let hasVisible = 0;
5256
5190
  _xeUtils.default.eachTree(collectColumn, (column, index, items, path, parent) => {
5257
5191
  // 排序只支持一级
5258
5192
  if (!parent) {
5259
5193
  collectColumn.forEach(column => {
5260
5194
  const colKey = column.getKey();
5261
5195
  if (colKey) {
5196
+ hasSort = 1;
5262
5197
  sortData[colKey] = column.renderSortNumber;
5263
5198
  }
5264
5199
  });
@@ -5266,12 +5201,14 @@ var _default = exports.default = (0, _vue.defineComponent)({
5266
5201
  if (column.resizeWidth) {
5267
5202
  const colKey = column.getKey();
5268
5203
  if (colKey) {
5204
+ hasResizable = 1;
5269
5205
  resizableData[colKey] = column.renderWidth;
5270
5206
  }
5271
5207
  }
5272
5208
  if (column.fixed && column.fixed !== column.defaultFixed) {
5273
5209
  const colKey = column.getKey();
5274
5210
  if (colKey) {
5211
+ hasFixedt = 1;
5275
5212
  fixedData[colKey] = column.fixed;
5276
5213
  }
5277
5214
  }
@@ -5281,16 +5218,30 @@ var _default = exports.default = (0, _vue.defineComponent)({
5281
5218
  if (!column.visible && column.defaultVisible) {
5282
5219
  const colKey = column.getKey();
5283
5220
  if (colKey) {
5221
+ hasVisible = 1;
5284
5222
  visibleData[colKey] = false;
5285
5223
  }
5286
5224
  } else if (column.visible && !column.defaultVisible) {
5287
5225
  const colKey = column.getKey();
5288
5226
  if (colKey) {
5227
+ hasVisible = 1;
5289
5228
  visibleData[colKey] = true;
5290
5229
  }
5291
5230
  }
5292
5231
  }
5293
5232
  });
5233
+ if (hasResizable) {
5234
+ storeData.resizableData = resizableData;
5235
+ }
5236
+ if (hasSort) {
5237
+ storeData.sortData = sortData;
5238
+ }
5239
+ if (hasFixedt) {
5240
+ storeData.fixedData = fixedData;
5241
+ }
5242
+ if (hasVisible) {
5243
+ storeData.visibleData = visibleData;
5244
+ }
5294
5245
  return storeData;
5295
5246
  },
5296
5247
  focus() {
@@ -6194,157 +6145,43 @@ var _default = exports.default = (0, _vue.defineComponent)({
6194
6145
  autoList
6195
6146
  });
6196
6147
  },
6197
- saveCustomResizable(isReset) {
6198
- const {
6199
- id,
6200
- customConfig
6201
- } = props;
6202
- const customOpts = computeCustomOpts.value;
6203
- const {
6204
- collectColumn
6205
- } = internalData;
6206
- const {
6207
- storage
6208
- } = customOpts;
6209
- const isAllStorage = storage === true;
6210
- const storageOpts = isAllStorage ? {} : Object.assign({}, storage || {});
6211
- const isResizable = isAllStorage || storageOpts.resizable;
6212
- if (customConfig && isResizable) {
6213
- const columnWidthStorageMap = getCustomStorageMap(resizableStorageKey);
6214
- let columnWidthStorage;
6215
- if (!id) {
6216
- (0, _log.errLog)('vxe.error.reqProp', ['id']);
6217
- return;
6218
- }
6219
- if (!isReset) {
6220
- columnWidthStorage = _xeUtils.default.isPlainObject(columnWidthStorageMap[id]) ? columnWidthStorageMap[id] : {};
6221
- _xeUtils.default.eachTree(collectColumn, column => {
6222
- if (column.resizeWidth) {
6223
- const colKey = column.getKey();
6224
- if (colKey) {
6225
- columnWidthStorage[colKey] = column.renderWidth;
6226
- }
6227
- }
6228
- });
6229
- }
6230
- columnWidthStorageMap[id] = _xeUtils.default.isEmpty(columnWidthStorage) ? undefined : columnWidthStorage;
6231
- localStorage.setItem(resizableStorageKey, _xeUtils.default.toJSONString(columnWidthStorageMap));
6232
- }
6233
- },
6234
- saveCustomSort(isReset) {
6148
+ saveCustomStore(type) {
6235
6149
  const {
6236
- id,
6237
- customConfig
6150
+ id
6238
6151
  } = props;
6239
6152
  const customOpts = computeCustomOpts.value;
6240
6153
  const {
6241
- collectColumn
6242
- } = internalData;
6243
- const {
6154
+ updateStore,
6244
6155
  storage
6245
6156
  } = customOpts;
6246
- const isAllStorage = storage === true;
6247
- const storageOpts = isAllStorage ? {} : Object.assign({}, storage || {});
6248
- const isSort = isAllStorage || storageOpts.sort;
6249
- if (customConfig && isSort) {
6250
- const columnSortStorageMap = getCustomStorageMap(sortStorageKey);
6251
- let columnWidthStorage;
6157
+ const isAllCustom = storage === true;
6158
+ const storageOpts = isAllCustom ? {} : Object.assign({}, storage || {});
6159
+ const isCustomResizable = isAllCustom || storageOpts.resizable;
6160
+ const isCustomVisible = isAllCustom || storageOpts.visible;
6161
+ const isCustomFixed = isAllCustom || storageOpts.fixed;
6162
+ const isCustomSort = isAllCustom || storageOpts.sort;
6163
+ if (isCustomResizable || isCustomVisible || isCustomFixed || isCustomSort) {
6252
6164
  if (!id) {
6253
6165
  (0, _log.errLog)('vxe.error.reqProp', ['id']);
6254
- return;
6166
+ return (0, _vue.nextTick)();
6255
6167
  }
6256
- if (!isReset) {
6257
- columnWidthStorage = _xeUtils.default.isPlainObject(columnSortStorageMap[id]) ? columnSortStorageMap[id] : {};
6258
- // 排序只支持一级
6259
- collectColumn.forEach(column => {
6260
- const colKey = column.getKey();
6261
- if (colKey) {
6262
- columnWidthStorage[colKey] = column.renderSortNumber;
6263
- }
6168
+ const storeData = type === 'reset' ? {
6169
+ resizableData: {},
6170
+ sortData: {},
6171
+ visibleData: {},
6172
+ fixedData: {}
6173
+ } : tableMethods.getCustomStoreData();
6174
+ if (updateStore) {
6175
+ return updateStore({
6176
+ id,
6177
+ type,
6178
+ storeData
6264
6179
  });
6180
+ } else {
6181
+ setCustomStorageMap(id, type === 'reset' ? null : storeData);
6265
6182
  }
6266
- columnSortStorageMap[id] = _xeUtils.default.isEmpty(columnWidthStorage) ? undefined : columnWidthStorage;
6267
- localStorage.setItem(sortStorageKey, _xeUtils.default.toJSONString(columnSortStorageMap));
6268
- }
6269
- },
6270
- saveCustomFixed() {
6271
- const {
6272
- id,
6273
- customConfig
6274
- } = props;
6275
- const {
6276
- collectColumn
6277
- } = internalData;
6278
- const customOpts = computeCustomOpts.value;
6279
- const {
6280
- storage
6281
- } = customOpts;
6282
- const isAllStorage = storage === true;
6283
- const storageOpts = isAllStorage ? {} : Object.assign({}, storage || {});
6284
- const isCustomFixed = isAllStorage || storageOpts.fixed;
6285
- if (customConfig && isCustomFixed) {
6286
- const columnFixedStorageMap = getCustomStorageMap(fixedStorageKey);
6287
- const colFixeds = [];
6288
- if (!id) {
6289
- (0, _log.errLog)('vxe.error.reqProp', ['id']);
6290
- return;
6291
- }
6292
- _xeUtils.default.eachTree(collectColumn, column => {
6293
- if (column.fixed && column.fixed !== column.defaultFixed) {
6294
- const colKey = column.getKey();
6295
- if (colKey) {
6296
- colFixeds.push(`${colKey}|${column.fixed}`);
6297
- }
6298
- }
6299
- });
6300
- columnFixedStorageMap[id] = colFixeds.join(',') || undefined;
6301
- localStorage.setItem(fixedStorageKey, _xeUtils.default.toJSONString(columnFixedStorageMap));
6302
- }
6303
- },
6304
- saveCustomVisible() {
6305
- const {
6306
- id,
6307
- customConfig
6308
- } = props;
6309
- const {
6310
- collectColumn
6311
- } = internalData;
6312
- const customOpts = computeCustomOpts.value;
6313
- const {
6314
- checkMethod,
6315
- storage
6316
- } = customOpts;
6317
- const isAllStorage = storage === true;
6318
- const storageOpts = isAllStorage ? {} : Object.assign({}, storage || {});
6319
- const isCustomVisible = isAllStorage || storageOpts.visible;
6320
- if (customConfig && isCustomVisible) {
6321
- const columnVisibleStorageMap = getCustomStorageMap(visibleStorageKey);
6322
- const colHides = [];
6323
- const colShows = [];
6324
- if (!id) {
6325
- (0, _log.errLog)('vxe.error.reqProp', ['id']);
6326
- return;
6327
- }
6328
- _xeUtils.default.eachTree(collectColumn, column => {
6329
- if (!checkMethod || checkMethod({
6330
- column
6331
- })) {
6332
- if (!column.visible && column.defaultVisible) {
6333
- const colKey = column.getKey();
6334
- if (colKey) {
6335
- colHides.push(colKey);
6336
- }
6337
- } else if (column.visible && !column.defaultVisible) {
6338
- const colKey = column.getKey();
6339
- if (colKey) {
6340
- colShows.push(colKey);
6341
- }
6342
- }
6343
- }
6344
- });
6345
- columnVisibleStorageMap[id] = [colHides.join(',')].concat(colShows.length ? [colShows.join(',')] : []).join('|') || undefined;
6346
- localStorage.setItem(visibleStorageKey, _xeUtils.default.toJSONString(columnVisibleStorageMap));
6347
6183
  }
6184
+ return (0, _vue.nextTick)();
6348
6185
  },
6349
6186
  handleCustom() {
6350
6187
  const {
@@ -6359,8 +6196,6 @@ var _default = exports.default = (0, _vue.defineComponent)({
6359
6196
  $xeTable.clearCopyCellArea();
6360
6197
  }
6361
6198
  }
6362
- tablePrivateMethods.saveCustomVisible();
6363
- tablePrivateMethods.saveCustomSort();
6364
6199
  tablePrivateMethods.analyColumnWidth();
6365
6200
  return tableMethods.refreshColumn(true);
6366
6201
  },