@deot/vc-components 1.0.11 → 1.0.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.
@@ -759,7 +759,7 @@
759
759
 
760
760
  // [color, borderColor, backgroundColor], -> CSS
761
761
  const THEME_MAP = {
762
- info: ['#5495f6', '#91d5ff', '#e6f7ff'],
762
+ info: ['#2B72FD', '#91d5ff', '#e6f7ff'],
763
763
  success: ['#52c41a', '#b7eb8f', '#f6ffed'],
764
764
  error: ['#ed4014', '#ffb08f', '#fbe9e9'],
765
765
  warning: ['#ffbf00', '#ffe58f', '#fffbe6']
@@ -13318,6 +13318,7 @@
13318
13318
  isVisible.value = cursorDown.value;
13319
13319
  };
13320
13320
  const refreshThumb = () => raf(() => {
13321
+ if (!thumb.value) return;
13321
13322
  thumb.value.style[prefixStyle('transform').camel] = `translate${barOptions.value.axis}(${thumbMove.value}px)`;
13322
13323
  });
13323
13324
  const refreshThrottleThumb = throttle$2(refreshThumb, 10);
@@ -18895,7 +18896,7 @@
18895
18896
  color: {
18896
18897
  type: [Object, String],
18897
18898
  default: () => ({
18898
- normal: "#5495f6",
18899
+ normal: "#2B72FD",
18899
18900
  success: "#52c41a",
18900
18901
  error: "#f5222d"
18901
18902
  })
@@ -20034,6 +20035,7 @@
20034
20035
 
20035
20036
  // 设置data首个元素的在originalData索引值
20036
20037
  const setFirstItemIndex = () => {
20038
+ if (!wrapper.value) return;
20037
20039
  const position = wrapper.value[K.scrollAxis];
20038
20040
  let item;
20039
20041
  for (let i = 0; i < rebuildData.value.length; i++) {
@@ -20214,6 +20216,7 @@
20214
20216
 
20215
20217
  // 图片撑开时,会影响布局, 节流结束后调用
20216
20218
  const handleResize = throttle$1(async () => {
20219
+ if (!wrapper.value) return;
20217
20220
  const isNeedRefreshLayout = rebuildData.value.some(i => !i.isPlaceholder);
20218
20221
  if (isNeedRefreshLayout) {
20219
20222
  const oldFirstItemIndex = firstItemIndex.value;
@@ -20247,6 +20250,8 @@
20247
20250
  });
20248
20251
  if (!originalData.length) {
20249
20252
  rebuildData.value = [];
20253
+ } else {
20254
+ rebuildData.value = originalData.slice();
20250
20255
  }
20251
20256
  offsetPageSize.value = 0;
20252
20257
  await refreshLayout(0, originalData.length);
@@ -20651,88 +20656,65 @@
20651
20656
  }
20652
20657
  });
20653
20658
 
20654
- const parseHeight = (height) => {
20655
- if (typeof height === "number") {
20656
- return height;
20659
+ const parseHeight = (v) => {
20660
+ if (typeof v === "number") {
20661
+ return v;
20657
20662
  }
20658
- if (height && typeof height === "string") {
20659
- if (/^\d+(?:px)?/.test(height)) {
20660
- return parseInt(height, 10);
20663
+ if (v && typeof v === "string") {
20664
+ if (/^\d+(?:px)?/.test(v)) {
20665
+ return parseInt(v, 10);
20661
20666
  }
20662
20667
  throw new VcError("table", "Invalid Height");
20663
20668
  }
20664
20669
  return null;
20665
20670
  };
20666
- const parseWidth = (width) => {
20667
- if (width !== void 0) {
20668
- width = parseInt(width, 10);
20669
- if (isNaN(width)) {
20670
- width = null;
20671
+ const parseWidth = (v) => {
20672
+ if (typeof v === "number") {
20673
+ return v;
20674
+ }
20675
+ let v1;
20676
+ if (typeof v !== "undefined") {
20677
+ v1 = parseInt(v, 10);
20678
+ if (isNaN(v1)) {
20679
+ v1 = null;
20671
20680
  }
20672
20681
  }
20673
- return width;
20682
+ return v1;
20674
20683
  };
20675
- const parseMinWidth = (minWidth) => {
20676
- if (typeof minWidth !== "undefined") {
20677
- minWidth = parseWidth(minWidth);
20678
- if (isNaN(minWidth)) {
20679
- minWidth = 80;
20684
+ const parseMinWidth = (v) => {
20685
+ if (typeof v === "number") {
20686
+ return v;
20687
+ }
20688
+ let v1;
20689
+ if (typeof v !== "undefined") {
20690
+ v1 = parseWidth(v);
20691
+ if (isNaN(v1)) {
20692
+ v = 80;
20680
20693
  }
20681
20694
  }
20682
- return minWidth;
20695
+ return v1;
20683
20696
  };
20684
- const getRowIdentity = (row, rowKey) => {
20697
+ const getRowValue = (row, primaryKey) => {
20685
20698
  if (row.__KEY__) return row.__KEY__;
20686
20699
  if (!row) throw new VcError("table", "row is required when get row identity");
20687
- if (typeof rowKey === "string") {
20688
- if (!rowKey.includes(".")) {
20689
- return row[rowKey];
20700
+ if (typeof primaryKey === "string") {
20701
+ if (!primaryKey.includes(".")) {
20702
+ return row[primaryKey];
20690
20703
  }
20691
- const key = rowKey.split(".");
20704
+ const key = primaryKey.split(".");
20692
20705
  let current = row;
20693
20706
  for (let i = 0; i < key.length; i++) {
20694
20707
  current = current[key[i]];
20695
20708
  }
20696
20709
  return current;
20697
- } else if (typeof rowKey === "function") {
20698
- return rowKey.call(null, row);
20710
+ } else if (typeof primaryKey === "function") {
20711
+ return primaryKey.call(null, row);
20699
20712
  }
20700
20713
  };
20701
- const walkTreeNode = (root, cb, opts = {}) => {
20702
- const {
20703
- childrenKey = "children",
20704
- lazyKey = "hasChildren",
20705
- level: baseLevel = 0
20706
- } = opts;
20707
- const isNil = (array) => !(Array.isArray(array) && array.length);
20708
- function _walker(parent, children, level) {
20709
- cb(parent, children, level);
20710
- children.forEach((item) => {
20711
- if (item[lazyKey]) {
20712
- cb(item, null, level + 1);
20713
- return;
20714
- }
20715
- const $children = item[childrenKey];
20716
- if (!isNil($children)) {
20717
- _walker(item, $children, level + 1);
20718
- }
20719
- });
20720
- }
20721
- root.forEach((item) => {
20722
- if (item[lazyKey]) {
20723
- cb(item, null, baseLevel);
20724
- return;
20725
- }
20726
- const children = item[childrenKey];
20727
- if (!isNil(children)) {
20728
- _walker(item, children, baseLevel);
20729
- }
20730
- });
20731
- };
20732
- const getKeysMap = (array = [], rowKey) => {
20714
+ const getValuesMap = (array = [], primaryKey) => {
20733
20715
  const arrayMap = {};
20734
20716
  array.forEach((row, index) => {
20735
- arrayMap[getRowIdentity(row, rowKey)] = { row, index };
20717
+ arrayMap[getRowValue(row, primaryKey)] = { row, index };
20736
20718
  });
20737
20719
  return arrayMap;
20738
20720
  };
@@ -20745,35 +20727,23 @@
20745
20727
  });
20746
20728
  return column;
20747
20729
  };
20748
- const getColumnByCell = (table, cell) => {
20730
+ const getColumnByCell = (columns, cell) => {
20749
20731
  const matches = (cell.className || "").match(/vc-table_[^\s]+/gm);
20750
20732
  if (matches) {
20751
- return getColumnById(table, matches[0]);
20733
+ return getColumnById(columns, matches[0]);
20752
20734
  }
20753
20735
  return null;
20754
20736
  };
20755
- const getCell = (event) => {
20756
- let cell = event.target;
20737
+ const getCell = (e) => {
20738
+ let cell = e.target;
20757
20739
  while (cell && cell.tagName.toUpperCase() !== "HTML") {
20758
- if (cell.tagName.toUpperCase() === "TD") {
20740
+ if (cell.classList.contains("vc-table__td")) {
20759
20741
  return cell;
20760
20742
  }
20761
20743
  cell = cell.parentNode;
20762
20744
  }
20763
20745
  return null;
20764
20746
  };
20765
- const flattenData = (data, opts = {}) => {
20766
- const result = [];
20767
- data.forEach((item) => {
20768
- if (item.children) {
20769
- const { children, ...rest } = item;
20770
- opts.parent ? result.push(...[opts.cascader ? item : rest, ...flattenData(children, opts)]) : result.push(...flattenData(children));
20771
- } else {
20772
- result.push(item);
20773
- }
20774
- });
20775
- return result;
20776
- };
20777
20747
 
20778
20748
  var lodash$1 = {exports: {}};
20779
20749
 
@@ -37986,29 +37956,115 @@
37986
37956
 
37987
37957
  var lodashExports = requireLodash();
37988
37958
 
37959
+ const getAllColumns = (columns) => {
37960
+ const result = [];
37961
+ columns.forEach((column) => {
37962
+ if (column.children) {
37963
+ result.push(column);
37964
+ result.push(...getAllColumns(column.children));
37965
+ } else {
37966
+ result.push(column);
37967
+ }
37968
+ });
37969
+ return result;
37970
+ };
37971
+ const columnsToRowsEffect = (v) => {
37972
+ let maxLevel = 1;
37973
+ const traverse = (column, parent) => {
37974
+ if (parent) {
37975
+ column.level = parent.level + 1;
37976
+ if (maxLevel < column.level) {
37977
+ maxLevel = column.level;
37978
+ }
37979
+ }
37980
+ if (column.children) {
37981
+ let colSpan = 0;
37982
+ column.children.forEach((subColumn) => {
37983
+ traverse(subColumn, column);
37984
+ colSpan += subColumn.colSpan;
37985
+ });
37986
+ column.colSpan = colSpan;
37987
+ } else {
37988
+ column.colSpan = 1;
37989
+ }
37990
+ };
37991
+ v.forEach((column) => {
37992
+ column.level = 1;
37993
+ traverse(column);
37994
+ });
37995
+ const rows = [];
37996
+ for (let i = 0; i < maxLevel; i++) {
37997
+ rows.push([]);
37998
+ }
37999
+ const allColumns = getAllColumns(v);
38000
+ allColumns.forEach((column) => {
38001
+ if (!column.children) {
38002
+ column.rowSpan = maxLevel - column.level + 1;
38003
+ } else {
38004
+ column.rowSpan = 1;
38005
+ }
38006
+ rows[column.level - 1].push(column);
38007
+ });
38008
+ return rows;
38009
+ };
38010
+ const flattenData = (data, opts = {}) => {
38011
+ const result = [];
38012
+ data.forEach((item) => {
38013
+ if (item.children) {
38014
+ const { children, ...rest } = item;
38015
+ opts.parent ? result.push(...[opts.cascader ? item : rest, ...flattenData(children, opts)]) : result.push(...flattenData(children));
38016
+ } else {
38017
+ result.push(item);
38018
+ }
38019
+ });
38020
+ return result;
38021
+ };
38022
+ const walkTreeNode = (root, cb, opts = {}) => {
38023
+ const {
38024
+ childrenKey = "children",
38025
+ lazyKey = "hasChildren",
38026
+ level: baseLevel = 0
38027
+ } = opts;
38028
+ const isNil = (array) => !(Array.isArray(array) && array.length);
38029
+ function _walker(parent, children, level) {
38030
+ cb(parent, children, level);
38031
+ children.forEach((item) => {
38032
+ if (item[lazyKey]) {
38033
+ cb(item, null, level + 1);
38034
+ return;
38035
+ }
38036
+ const $children = item[childrenKey];
38037
+ if (!isNil($children)) {
38038
+ _walker(item, $children, level + 1);
38039
+ }
38040
+ });
38041
+ }
38042
+ root.forEach((item) => {
38043
+ if (item[lazyKey]) {
38044
+ cb(item, null, baseLevel);
38045
+ return;
38046
+ }
38047
+ const children = item[childrenKey];
38048
+ if (!isNil(children)) {
38049
+ _walker(item, children, baseLevel);
38050
+ }
38051
+ });
38052
+ };
38053
+
37989
38054
  class BaseWatcher {
37990
38055
  states = vue.reactive({
37991
38056
  // 渲染的数据来源,是对 table 中的 data 过滤排序后的结果
37992
38057
  _data: [],
37993
38058
  data: [],
37994
38059
  list: [],
37995
- // 是否包含固定列
37996
- isComplex: false,
37997
- // 列
38060
+ // 表头数据
38061
+ headerRows: [],
38062
+ // 列 动态收集vc-table-column中的columnConfig
37998
38063
  _columns: [],
37999
- // 动态收集vc-table-column中的columnConfig
38000
38064
  originColumns: [],
38001
- // leftFixedColumns, notFixedColumns, rightFixedColumns
38002
- columns: [],
38003
- // 包括 leftFixedLeafColumns,leafColumns,rightFixedLeafColumns
38065
+ notFixedColumns: [],
38004
38066
  leftFixedColumns: [],
38005
38067
  rightFixedColumns: [],
38006
- leafColumns: [],
38007
- leftFixedLeafColumns: [],
38008
- rightFixedLeafColumns: [],
38009
- leafColumnsLength: 0,
38010
- leftFixedLeafColumnsLength: 0,
38011
- rightFixedLeafColumnsLength: 0,
38012
38068
  // 选择
38013
38069
  isAllSelected: false,
38014
38070
  selection: [],
@@ -38030,7 +38086,17 @@
38030
38086
  treeLazyData: [],
38031
38087
  // 源数据展开
38032
38088
  treeLazyColumnIdentifier: "hasChildren",
38033
- treeChildrenColumnName: "children"
38089
+ treeChildrenColumnName: "children",
38090
+ // compputeds
38091
+ isComplex: vue.computed(() => this.states.leftFixedColumns.length > 0 || this.states.rightFixedColumns.length > 0),
38092
+ isGroup: vue.computed(() => this.states.columns.length > this.states.originColumns.length),
38093
+ columns: vue.computed(() => lodashExports.concat(this.states.leftFixedLeafColumns, this.states.leafColumns, this.states.rightFixedLeafColumns)),
38094
+ leafColumns: vue.computed(() => flattenData(this.states.notFixedColumns)),
38095
+ leftFixedLeafColumns: vue.computed(() => flattenData(this.states.leftFixedColumns)),
38096
+ rightFixedLeafColumns: vue.computed(() => flattenData(this.states.rightFixedColumns)),
38097
+ leafColumnsLength: vue.computed(() => this.states.leafColumns.length),
38098
+ leftFixedLeafColumnsLength: vue.computed(() => this.states.leftFixedLeafColumns.length),
38099
+ rightFixedLeafColumnsLength: vue.computed(() => this.states.rightFixedLeafColumns.length)
38034
38100
  });
38035
38101
  }
38036
38102
 
@@ -38041,14 +38107,14 @@
38041
38107
  }
38042
38108
  update() {
38043
38109
  const store = this.store;
38044
- const { rowKey, defaultExpandAll } = this.store.table.props;
38110
+ const { primaryKey, defaultExpandAll } = this.store.table.props;
38045
38111
  const { data = [], expandRows } = store.states;
38046
38112
  if (defaultExpandAll) {
38047
38113
  store.states.expandRows = data.slice();
38048
- } else if (rowKey) {
38049
- const expandRowsMap = getKeysMap(expandRows, rowKey);
38114
+ } else if (primaryKey) {
38115
+ const expandRowsMap = getValuesMap(expandRows, primaryKey);
38050
38116
  store.states.expandRows = data.reduce((prev, row) => {
38051
- const rowId = getRowIdentity(row, rowKey);
38117
+ const rowId = getRowValue(row, primaryKey);
38052
38118
  const rowInfo = expandRowsMap[rowId];
38053
38119
  if (rowInfo) {
38054
38120
  prev.push(row);
@@ -38070,10 +38136,10 @@
38070
38136
  }
38071
38137
  reset(ids) {
38072
38138
  const store = this.store;
38073
- store.checkRowKey();
38074
- const { rowKey } = store.table.props;
38139
+ store.checkPrimaryKey();
38140
+ const { primaryKey } = store.table.props;
38075
38141
  const { data } = store.states;
38076
- const keysMap = getKeysMap(data, rowKey);
38142
+ const keysMap = getValuesMap(data, primaryKey);
38077
38143
  store.states.expandRows = ids.reduce((prev, cur) => {
38078
38144
  const info = keysMap[cur];
38079
38145
  if (info) {
@@ -38083,11 +38149,11 @@
38083
38149
  }, []);
38084
38150
  }
38085
38151
  isExpanded(row) {
38086
- const { rowKey } = this.store.table.props;
38152
+ const { primaryKey } = this.store.table.props;
38087
38153
  const { expandRows = [] } = this.store.states;
38088
- if (rowKey) {
38089
- const expandMap = getKeysMap(expandRows, rowKey);
38090
- return !!expandMap[getRowIdentity(row, rowKey)];
38154
+ if (primaryKey) {
38155
+ const expandMap = getValuesMap(expandRows, primaryKey);
38156
+ return !!expandMap[getRowValue(row, primaryKey)];
38091
38157
  }
38092
38158
  return expandRows.indexOf(row) !== -1;
38093
38159
  }
@@ -38100,22 +38166,22 @@
38100
38166
  }
38101
38167
  reset(id) {
38102
38168
  const store = this.store;
38103
- const { rowKey } = store.table.props;
38104
- store.checkRowKey();
38169
+ const { primaryKey } = store.table.props;
38170
+ store.checkPrimaryKey();
38105
38171
  const { data = [] } = store.states;
38106
- const currentRow = data.find((item) => getRowIdentity(item, rowKey) === id);
38172
+ const currentRow = data.find((item) => getRowValue(item, primaryKey) === id);
38107
38173
  store.states.currentRow = currentRow || null;
38108
38174
  }
38109
38175
  update() {
38110
38176
  const store = this.store;
38111
- const { rowKey } = store.table.props;
38177
+ const { primaryKey } = store.table.props;
38112
38178
  const { data = [], currentRow } = store.states;
38113
38179
  const oldCurrentRow = currentRow;
38114
38180
  if (oldCurrentRow && !data.includes(oldCurrentRow)) {
38115
38181
  let newCurrentRow = null;
38116
- if (rowKey) {
38182
+ if (primaryKey) {
38117
38183
  newCurrentRow = data.find((item) => {
38118
- return getRowIdentity(item, rowKey) === getRowIdentity(oldCurrentRow, rowKey);
38184
+ return getRowValue(item, primaryKey) === getRowValue(oldCurrentRow, primaryKey);
38119
38185
  });
38120
38186
  }
38121
38187
  store.states.currentRow = newCurrentRow;
@@ -38134,8 +38200,8 @@
38134
38200
  * { id: { level, children } }
38135
38201
  */
38136
38202
  normalizedData = vue.computed(() => {
38137
- const { rowKey } = this.store.table.props;
38138
- if (!rowKey) return {};
38203
+ const { primaryKey } = this.store.table.props;
38204
+ if (!primaryKey) return {};
38139
38205
  return this.normalize(this.store.states.data || []);
38140
38206
  });
38141
38207
  /**
@@ -38143,7 +38209,7 @@
38143
38209
  * { id: { children } }
38144
38210
  */
38145
38211
  normalizedLazyNode = vue.computed(() => {
38146
- const { rowKey } = this.store.table.props;
38212
+ const { primaryKey } = this.store.table.props;
38147
38213
  const { treelazyNodeMap, treeLazyColumnIdentifier, treeChildrenColumnName } = this.store.states;
38148
38214
  const keys = Object.keys(treelazyNodeMap);
38149
38215
  const res = {};
@@ -38152,7 +38218,7 @@
38152
38218
  if (treelazyNodeMap[key].length) {
38153
38219
  const item = { children: [] };
38154
38220
  treelazyNodeMap[key].forEach((row) => {
38155
- const id = getRowIdentity(row, rowKey);
38221
+ const id = getRowValue(row, primaryKey);
38156
38222
  item.children.push(id);
38157
38223
  const hasChildren = row[treeLazyColumnIdentifier] || row[treeChildrenColumnName] && row[treeChildrenColumnName].length === 0;
38158
38224
  if (hasChildren && !res[id]) {
@@ -38172,16 +38238,16 @@
38172
38238
  );
38173
38239
  }
38174
38240
  normalize(data) {
38175
- const { rowKey } = this.store.table.props;
38241
+ const { primaryKey } = this.store.table.props;
38176
38242
  const { treeChildrenColumnName, treeLazyColumnIdentifier, treeLazy } = this.store.states;
38177
38243
  const res = {};
38178
38244
  walkTreeNode(
38179
38245
  data,
38180
38246
  (parent, children, level) => {
38181
- const parentId = getRowIdentity(parent, rowKey);
38247
+ const parentId = getRowValue(parent, primaryKey);
38182
38248
  if (Array.isArray(children)) {
38183
38249
  res[parentId] = {
38184
- children: children.map((row) => getRowIdentity(row, rowKey)),
38250
+ children: children.map((row) => getRowValue(row, primaryKey)),
38185
38251
  level
38186
38252
  };
38187
38253
  } else if (treeLazy) {
@@ -38201,7 +38267,7 @@
38201
38267
  }
38202
38268
  // 获取当前展开最大的level
38203
38269
  getMaxLevel() {
38204
- const { rowKey } = this.store.table.props;
38270
+ const { primaryKey } = this.store.table.props;
38205
38271
  const { data, treeData } = this.store.states;
38206
38272
  const levels = data.map((item) => {
38207
38273
  const traverse = (source) => {
@@ -38212,7 +38278,7 @@
38212
38278
  return source.level;
38213
38279
  }
38214
38280
  };
38215
- const id = getRowIdentity(item, rowKey);
38281
+ const id = getRowValue(item, primaryKey);
38216
38282
  return traverse(treeData[id]);
38217
38283
  });
38218
38284
  return max$2(levels) || 0;
@@ -38274,10 +38340,10 @@
38274
38340
  this.update();
38275
38341
  }
38276
38342
  toggle(row, expanded) {
38277
- this.store.checkRowKey();
38278
- const { rowKey } = this.store.table.props;
38343
+ this.store.checkPrimaryKey();
38344
+ const { primaryKey } = this.store.table.props;
38279
38345
  const { treeData } = this.store.states;
38280
- const id = getRowIdentity(row, rowKey);
38346
+ const id = getRowValue(row, primaryKey);
38281
38347
  const data = id && treeData[id];
38282
38348
  if (id && data && "expanded" in data) {
38283
38349
  const oldExpanded = data.expanded;
@@ -38290,10 +38356,10 @@
38290
38356
  }
38291
38357
  }
38292
38358
  loadOrToggle(row) {
38293
- this.store.checkRowKey();
38294
- const { rowKey } = this.store.table.props;
38359
+ this.store.checkPrimaryKey();
38360
+ const { primaryKey } = this.store.table.props;
38295
38361
  const { treeLazy, treeData } = this.store.states;
38296
- const id = getRowIdentity(row, rowKey);
38362
+ const id = getRowValue(row, primaryKey);
38297
38363
  const data = treeData[id];
38298
38364
  if (treeLazy && data && "loaded" in data && !data.loaded) {
38299
38365
  this.loadData(row, id, data);
@@ -38302,9 +38368,9 @@
38302
38368
  }
38303
38369
  }
38304
38370
  loadData(row, key, treeNode) {
38305
- this.store.checkRowKey();
38371
+ this.store.checkPrimaryKey();
38306
38372
  const { table } = this.store;
38307
- const { rowKey } = table.props;
38373
+ const { primaryKey } = table.props;
38308
38374
  const { treelazyNodeMap, treeData, treeChildrenColumnName, treeLazyColumnIdentifier } = this.store.states;
38309
38375
  if (table.props.loadExpand && !treeData[key].loaded) {
38310
38376
  this.store.states.treeData[key].loading = true;
@@ -38319,7 +38385,7 @@
38319
38385
  walkTreeNode(
38320
38386
  data,
38321
38387
  (parent, _, level) => {
38322
- const id = getRowIdentity(parent, rowKey);
38388
+ const id = getRowValue(parent, primaryKey);
38323
38389
  Object.defineProperty(parent, "__KEY__", {
38324
38390
  value: `${level}__${id}`,
38325
38391
  writable: false
@@ -38389,27 +38455,13 @@
38389
38455
  if (!this.store) {
38390
38456
  throw new VcError("table", "Table Layout 必须包含store实例");
38391
38457
  }
38392
- this.updateScroller = this.updateScroller.bind(this);
38393
- this.updateColumns = this.updateColumns.bind(this);
38394
- vue.onMounted(() => {
38395
- this.updateColumns();
38396
- this.updateScroller();
38397
- });
38398
- let __updated__;
38399
- vue.onUpdated(() => {
38400
- if (__updated__) return;
38401
- this.updateColumns();
38402
- this.updateScroller();
38403
- __updated__ = true;
38404
- });
38405
38458
  }
38406
38459
  updateScrollY() {
38407
38460
  const { height, bodyHeight } = this.states;
38408
38461
  if (height === null || bodyHeight === null) return;
38409
- const scroller = this.table.exposed.scroller.value;
38410
- if (this.table.vnode.el && scroller) {
38411
- const body = scroller.$el.querySelector(".vc-table__body");
38412
- this.states.scrollY = body.offsetHeight > bodyHeight;
38462
+ const bodyYWrapper = this.table.exposed.bodyYWrapper.value;
38463
+ if (this.table.vnode.el && bodyYWrapper) {
38464
+ this.states.scrollY = bodyYWrapper.offsetHeight > bodyHeight;
38413
38465
  }
38414
38466
  }
38415
38467
  setHeight(value, prop = "height") {
@@ -38426,18 +38478,6 @@
38426
38478
  setMaxHeight(value) {
38427
38479
  this.setHeight(value, "max-height");
38428
38480
  }
38429
- getFlattenColumns() {
38430
- const flattenColumns = [];
38431
- const columns = this.store.states.columns;
38432
- columns.forEach((column) => {
38433
- if (column.isColumnGroup) {
38434
- flattenColumns.push(...column.columns);
38435
- } else {
38436
- flattenColumns.push(column);
38437
- }
38438
- });
38439
- return flattenColumns;
38440
- }
38441
38481
  updateElsHeight() {
38442
38482
  if (!this.table.exposed.isReady.value) return vue.nextTick(() => this.updateElsHeight());
38443
38483
  const table = this.table.exposed;
@@ -38460,13 +38500,12 @@
38460
38500
  this.states.bodyHeight = tableHeight - headerHeight - footerHeight + (footerWrapper ? 1 : 0);
38461
38501
  }
38462
38502
  this.updateScrollY();
38463
- this.updateScroller();
38464
38503
  }
38465
38504
  updateColumnsWidth() {
38466
38505
  if (IS_SERVER$2) return;
38467
38506
  const bodyWidth = this.table.vnode.el.clientWidth;
38468
38507
  let bodyMinWidth = 0;
38469
- const flattenColumns = this.getFlattenColumns();
38508
+ const flattenColumns = this.store.states.columns;
38470
38509
  const flexColumns = flattenColumns.filter((column) => typeof column.width !== "number");
38471
38510
  const { fit } = this.table.props;
38472
38511
  if (flexColumns.length > 0 && fit) {
@@ -38492,7 +38531,7 @@
38492
38531
  }
38493
38532
  } else {
38494
38533
  this.states.scrollX = true;
38495
- flexColumns.forEach(function(column) {
38534
+ flexColumns.forEach((column) => {
38496
38535
  column.realWidth = column.width || column.minWidth;
38497
38536
  });
38498
38537
  }
@@ -38526,12 +38565,6 @@
38526
38565
  });
38527
38566
  this.states.rightFixedWidth = rightFixedWidth;
38528
38567
  }
38529
- this.updateColumns();
38530
- }
38531
- // v2.x中的 notifyObservers
38532
- updateColumns() {
38533
- }
38534
- updateScroller() {
38535
38568
  }
38536
38569
  }
38537
38570
 
@@ -38541,7 +38574,7 @@
38541
38574
  expand;
38542
38575
  tree;
38543
38576
  layout;
38544
- flattenData = vue.computed(() => {
38577
+ flatData = vue.computed(() => {
38545
38578
  if (this.table.props.expandSelectable) {
38546
38579
  return lodashExports.concat(
38547
38580
  flattenData(this.states.data, { parent: true, cascader: true }),
@@ -38572,17 +38605,24 @@
38572
38605
  const dataInstanceChanged = this.states._data !== data;
38573
38606
  this.states._data = data;
38574
38607
  this.states.data = data;
38608
+ const caches = /* @__PURE__ */ new Map();
38609
+ this.states.list.forEach((item) => {
38610
+ item.rows.forEach((row) => {
38611
+ caches.set(row.data, row);
38612
+ });
38613
+ });
38575
38614
  this.states.list = data.reduce((pre, row, index) => {
38615
+ const cache = caches.get(row) || { heightMap: {} };
38576
38616
  pre.push({
38577
38617
  rows: [
38578
38618
  {
38579
38619
  index,
38580
38620
  data: row,
38581
- height: "",
38621
+ height: cache.height || "",
38582
38622
  heightMap: {
38583
- left: "",
38584
- main: "",
38585
- right: ""
38623
+ left: cache.heightMap.left || "",
38624
+ main: cache.heightMap.main || "",
38625
+ right: cache.heightMap.right || ""
38586
38626
  }
38587
38627
  }
38588
38628
  ],
@@ -38590,6 +38630,7 @@
38590
38630
  });
38591
38631
  return pre;
38592
38632
  }, []);
38633
+ caches.clear();
38593
38634
  this.current.update();
38594
38635
  this.expand.update();
38595
38636
  if (!this.states.reserveSelection) {
@@ -38599,7 +38640,7 @@
38599
38640
  this.cleanSelection();
38600
38641
  }
38601
38642
  } else {
38602
- this.checkRowKey();
38643
+ this.checkPrimaryKey();
38603
38644
  this.updateSelectionByRowKey();
38604
38645
  }
38605
38646
  this.updateAllSelected();
@@ -38621,10 +38662,10 @@
38621
38662
  }
38622
38663
  }
38623
38664
  /**
38624
- * 检查 rowKey 是否存在
38665
+ * 检查 primaryKey 是否存在
38625
38666
  */
38626
- checkRowKey() {
38627
- const { rowKey } = this.table.props;
38667
+ checkPrimaryKey() {
38668
+ const { primaryKey } = this.table.props;
38628
38669
  }
38629
38670
  /**
38630
38671
  * states
@@ -38685,22 +38726,20 @@
38685
38726
  updateColumns() {
38686
38727
  const { states } = this;
38687
38728
  const _columns = states._columns || [];
38688
- states.leftFixedColumns = _columns.filter((column) => column.fixed === true || column.fixed === "left");
38689
- states.rightFixedColumns = _columns.filter((column) => column.fixed === "right");
38690
- if (states.leftFixedColumns.length > 0 && _columns[0] && _columns[0].type === "selection" && !_columns[0].fixed) {
38729
+ const leftFixedColumns = _columns.filter((column) => column.fixed === true || column.fixed === "left");
38730
+ const rightFixedColumns = _columns.filter((column) => column.fixed === "right");
38731
+ if (leftFixedColumns.length > 0 && _columns[0] && _columns[0].type === "selection" && !_columns[0].fixed) {
38691
38732
  _columns[0].fixed = true;
38692
- states.leftFixedColumns.unshift(_columns[0]);
38733
+ leftFixedColumns.unshift(_columns[0]);
38693
38734
  }
38694
38735
  const notFixedColumns = _columns.filter((column) => !column.fixed);
38695
- states.originColumns = lodashExports.concat(states.leftFixedColumns, notFixedColumns, states.rightFixedColumns);
38696
- const leafColumns = flattenData(notFixedColumns);
38697
- const leftFixedLeafColumns = flattenData(states.leftFixedColumns);
38698
- const rightFixedLeafColumns = flattenData(states.rightFixedColumns);
38699
- states.leafColumnsLength = leafColumns.length;
38700
- states.leftFixedLeafColumnsLength = leftFixedLeafColumns.length;
38701
- states.rightFixedLeafColumnsLength = rightFixedLeafColumns.length;
38702
- states.columns = lodashExports.concat(leftFixedLeafColumns, leafColumns, rightFixedLeafColumns);
38703
- states.isComplex = states.leftFixedColumns.length > 0 || states.rightFixedColumns.length > 0;
38736
+ const originColumns = lodashExports.concat(leftFixedColumns, notFixedColumns, rightFixedColumns);
38737
+ const headerRows = columnsToRowsEffect(originColumns);
38738
+ states.leftFixedColumns = leftFixedColumns;
38739
+ states.notFixedColumns = notFixedColumns;
38740
+ states.rightFixedColumns = rightFixedColumns;
38741
+ states.originColumns = originColumns;
38742
+ states.headerRows = headerRows;
38704
38743
  }
38705
38744
  // 选择
38706
38745
  isSelected(row) {
@@ -38724,13 +38763,13 @@
38724
38763
  * 清理选择
38725
38764
  */
38726
38765
  cleanSelection() {
38727
- const { rowKey } = this.table.props;
38728
- const { selection = [] } = this.states;
38766
+ const { primaryKey } = this.table.props;
38767
+ const { selection = [], data } = this.states;
38729
38768
  let deleted;
38730
- if (rowKey) {
38769
+ if (primaryKey) {
38731
38770
  deleted = [];
38732
- const selectedMap = getKeysMap(selection, rowKey);
38733
- const dataMap = getKeysMap(selection, rowKey);
38771
+ const selectedMap = getValuesMap(selection, primaryKey);
38772
+ const dataMap = getValuesMap(data, primaryKey);
38734
38773
  for (const key in selectedMap) {
38735
38774
  if (hasOwn$1(selectedMap, key) && !dataMap[key]) {
38736
38775
  deleted.push(selectedMap[key].row);
@@ -38738,7 +38777,7 @@
38738
38777
  }
38739
38778
  } else {
38740
38779
  deleted = selection.filter((item) => {
38741
- return !this.flattenData.value.includes(item);
38780
+ return !this.flatData.value.includes(item);
38742
38781
  });
38743
38782
  }
38744
38783
  deleted.forEach((deletedItem) => {
@@ -38799,7 +38838,7 @@
38799
38838
  const value = indeterminate ? !isAllSelected : !(isAllSelected || selection.length);
38800
38839
  this.states.isAllSelected = value;
38801
38840
  let selectionChanged = false;
38802
- this.flattenData.value.forEach((row, index) => {
38841
+ this.flatData.value.forEach((row, index) => {
38803
38842
  if (selectable) {
38804
38843
  if (selectable.call(null, row, index) && this.toggleRowStatus(selection, row, value)) {
38805
38844
  selectionChanged = true;
@@ -38830,11 +38869,11 @@
38830
38869
  this.tree.expand(val);
38831
38870
  }
38832
38871
  updateSelectionByRowKey() {
38833
- const { rowKey } = this.table.props;
38872
+ const { primaryKey } = this.table.props;
38834
38873
  const { selection } = this.states;
38835
- const selectedMap = getKeysMap(selection, rowKey);
38836
- this.states.selection = this.flattenData.value.reduce((prev, row) => {
38837
- const rowId = getRowIdentity(row, rowKey);
38874
+ const selectedMap = getValuesMap(selection, primaryKey);
38875
+ this.states.selection = this.flatData.value.reduce((prev, row) => {
38876
+ const rowId = getRowValue(row, primaryKey);
38838
38877
  const rowInfo = selectedMap[rowId];
38839
38878
  if (rowInfo) {
38840
38879
  prev.push(row);
@@ -38850,7 +38889,7 @@
38850
38889
  }
38851
38890
  let isAllSelected = true;
38852
38891
  let selectedCount = 0;
38853
- const temp = this.flattenData.value;
38892
+ const temp = this.flatData.value;
38854
38893
  for (let i = 0, j = temp.length; i < j; i++) {
38855
38894
  const row = temp[i];
38856
38895
  const isRowSelectable = selectable && selectable.call(null, row, i);
@@ -38905,8 +38944,10 @@
38905
38944
  const NormalList = /* @__PURE__ */ vue.defineComponent({
38906
38945
  name: COMPONENT_NAME$h,
38907
38946
  props: {
38908
- data: Array,
38909
- default: () => []
38947
+ data: {
38948
+ type: Array,
38949
+ default: () => []
38950
+ }
38910
38951
  },
38911
38952
  emits: ['row-resize'],
38912
38953
  setup(props, {
@@ -38948,7 +38989,7 @@
38948
38989
  expose
38949
38990
  }) {
38950
38991
  const instance = vue.getCurrentInstance();
38951
- const table = getInstance$1('table', 'tableId');
38992
+ const table = vue.inject('vc-table');
38952
38993
  const states = useStates({
38953
38994
  data: 'data',
38954
38995
  list: 'list',
@@ -38965,6 +39006,7 @@
38965
39006
  type
38966
39007
  }) => type === 'default')
38967
39008
  });
39009
+ const wrapper = vue.ref();
38968
39010
  vue.watch(() => props.store.states.hoverRowIndex, (v, oldV) => {
38969
39011
  if (!props.store.states.isComplex || IS_SERVER$2) return;
38970
39012
  raf(() => {
@@ -38975,12 +39017,12 @@
38975
39017
  newRow && addClass(newRow, 'hover-row');
38976
39018
  });
38977
39019
  });
38978
- const getKeyOfRow = (row, index) => {
39020
+ const getValueOfRow = (row, index) => {
38979
39021
  const {
38980
- rowKey
39022
+ primaryKey
38981
39023
  } = table.props;
38982
- if (rowKey) {
38983
- return getRowIdentity(row, rowKey);
39024
+ if (primaryKey) {
39025
+ return getRowValue(row, primaryKey);
38984
39026
  }
38985
39027
  return index;
38986
39028
  };
@@ -39045,7 +39087,7 @@
39045
39087
  return cellStyle;
39046
39088
  };
39047
39089
  const getCellClass = (rowIndex, columnIndex, row, column) => {
39048
- const classes = [column.align, column.className];
39090
+ const classes = [column.realAlign, column.className];
39049
39091
  if (isColumnHidden(columnIndex)) {
39050
39092
  classes.push('is-hidden');
39051
39093
  }
@@ -39071,7 +39113,7 @@
39071
39113
  column,
39072
39114
  row
39073
39115
  };
39074
- table.exposed.hoverState.value = hoverState;
39116
+ table.hoverState.value = hoverState;
39075
39117
  table.emit('cell-mouse-enter', hoverState.row, hoverState.column, hoverState.cell, e);
39076
39118
  }
39077
39119
 
@@ -39104,8 +39146,8 @@
39104
39146
  const handleCellMouseLeave = e => {
39105
39147
  const cell = getCell(e);
39106
39148
  if (!cell) return;
39107
- const oldHoverState = table.exposed.hoverState.value || {};
39108
- table.emit('cell-mouse-leave', oldHoverState.row, oldHoverState.column, oldHoverState.cell, event);
39149
+ const oldHoverState = table.hoverState.value || {};
39150
+ table.emit('cell-mouse-leave', oldHoverState.row, oldHoverState.column, oldHoverState.cell, e);
39109
39151
  };
39110
39152
  const handleMouseEnter = debounce$1(index => {
39111
39153
  props.store.setHoverRow(index);
@@ -39141,7 +39183,8 @@
39141
39183
  const {
39142
39184
  columns
39143
39185
  } = states;
39144
- const key = getKeyOfRow(row, rowIndex);
39186
+ const key = getValueOfRow(row, rowIndex);
39187
+ const selected = props.store.isSelected(row);
39145
39188
  return vue.createVNode("div", {
39146
39189
  "key": key,
39147
39190
  "class": [getRowClass(row, rowIndex), 'vc-table__tr'],
@@ -39162,10 +39205,12 @@
39162
39205
  };
39163
39206
  if (columnsHidden.value[columnIndex]) {
39164
39207
  return vue.createVNode("div", {
39208
+ "key": column.id,
39165
39209
  "style": [sizeStyle]
39166
39210
  }, null);
39167
39211
  }
39168
39212
  return vue.createVNode("div", {
39213
+ "key": column.id,
39169
39214
  "style": [getCellStyle(rowIndex, columnIndex, row, column), sizeStyle],
39170
39215
  "class": [getCellClass(rowIndex, columnIndex, row, column), 'vc-table__td'],
39171
39216
  "onMouseenter": e => handleCellMouseEnter(e, row),
@@ -39175,7 +39220,8 @@
39175
39220
  column,
39176
39221
  rowIndex,
39177
39222
  columnIndex,
39178
- store: props.store
39223
+ store: props.store,
39224
+ selected
39179
39225
  })]);
39180
39226
  })]);
39181
39227
  };
@@ -39205,13 +39251,12 @@
39205
39251
  }
39206
39252
  });
39207
39253
  };
39208
- const wrapper = vue.ref();
39209
39254
  expose({
39210
39255
  wrapper,
39211
39256
  getRootElement: () => instance.vnode.el
39212
39257
  });
39258
+ const layout = table.layout;
39213
39259
  return () => {
39214
- const layout = table.exposed.layout;
39215
39260
  return vue.createVNode("div", {
39216
39261
  "class": "vc-table__body"
39217
39262
  }, [table.props.height ? vue.createVNode(RecycleList, {
@@ -39220,7 +39265,7 @@
39220
39265
  "disabled": true,
39221
39266
  "class": "vc-table__tbody",
39222
39267
  "scrollerOptions": {
39223
- barTo: `.${table.exposed.tableId}`,
39268
+ barTo: `.${table.tableId}`,
39224
39269
  native: false,
39225
39270
  always: false,
39226
39271
  showBar: !props.fixed,
@@ -39256,57 +39301,6 @@
39256
39301
 
39257
39302
  const TableSort = 'div';
39258
39303
  const TableFilter = 'div';
39259
- const getAllColumns = columns => {
39260
- const result = [];
39261
- columns.forEach(column => {
39262
- if (column.children) {
39263
- result.push(column);
39264
- result.push(...getAllColumns(column.children));
39265
- } else {
39266
- result.push(column);
39267
- }
39268
- });
39269
- return result;
39270
- };
39271
- const convertToRows = originColumns => {
39272
- let maxLevel = 1;
39273
- const traverse = (column, parent) => {
39274
- if (parent) {
39275
- column.level = parent.level + 1;
39276
- if (maxLevel < column.level) {
39277
- maxLevel = column.level;
39278
- }
39279
- }
39280
- if (column.children) {
39281
- let colSpan = 0;
39282
- column.children.forEach(subColumn => {
39283
- traverse(subColumn, column);
39284
- colSpan += subColumn.colSpan;
39285
- });
39286
- column.colSpan = colSpan;
39287
- } else {
39288
- column.colSpan = 1;
39289
- }
39290
- };
39291
- originColumns.forEach(column => {
39292
- column.level = 1;
39293
- traverse(column);
39294
- });
39295
- const rows = [];
39296
- for (let i = 0; i < maxLevel; i++) {
39297
- rows.push([]);
39298
- }
39299
- const allColumns = getAllColumns(originColumns);
39300
- allColumns.forEach(column => {
39301
- if (!column.children) {
39302
- column.rowSpan = maxLevel - column.level + 1;
39303
- } else {
39304
- column.rowSpan = 1;
39305
- }
39306
- rows[column.level - 1].push(column);
39307
- });
39308
- return rows;
39309
- };
39310
39304
  const TableHeader = /* @__PURE__ */ vue.defineComponent({
39311
39305
  name: 'vc-table-header',
39312
39306
  props: {
@@ -39323,7 +39317,7 @@
39323
39317
  }
39324
39318
  },
39325
39319
  setup(props) {
39326
- const table = getInstance$1('table', 'tableId');
39320
+ const table = vue.inject('vc-table');
39327
39321
  const instance = vue.getCurrentInstance();
39328
39322
  const draggingColumn = vue.ref(null);
39329
39323
  const dragging = vue.ref(false);
@@ -39333,16 +39327,18 @@
39333
39327
  isAllSelected: 'isAllSelected',
39334
39328
  leftFixedLeafCount: 'leftFixedLeafColumnsLength',
39335
39329
  rightFixedLeafCount: 'rightFixedLeafColumnsLength',
39330
+ isGroup: 'isGroup',
39331
+ headerRows: 'headerRows',
39336
39332
  columnsCount: $states => $states.columns.length,
39337
39333
  leftFixedCount: $states => $states.leftFixedColumns.length,
39338
39334
  rightFixedCount: $states => $states.rightFixedColumns.length
39339
39335
  });
39340
- const isCellHidden = (index, columns) => {
39336
+ const isColumnHidden = index => {
39341
39337
  let start = 0;
39342
39338
  for (let i = 0; i < index; i++) {
39343
- start += columns[i].colSpan;
39339
+ start += states.columns[i].colSpan;
39344
39340
  }
39345
- const after = start + columns[index].colSpan - 1;
39341
+ const after = start + states.columns[index].colSpan - 1;
39346
39342
  if (props.fixed === true || props.fixed === 'left') {
39347
39343
  return after >= states.leftFixedLeafCount;
39348
39344
  } else if (props.fixed === 'right') {
@@ -39351,6 +39347,9 @@
39351
39347
  return after < states.leftFixedLeafCount || start >= states.columnsCount - states.rightFixedLeafCount;
39352
39348
  }
39353
39349
  };
39350
+ const columnsHidden = vue.computed(() => {
39351
+ return states.columns.map((_, index) => isColumnHidden(index));
39352
+ });
39354
39353
  const getHeaderRowStyle = rowIndex => {
39355
39354
  const {
39356
39355
  headerRowStyle
@@ -39391,8 +39390,8 @@
39391
39390
  return headerCellStyle;
39392
39391
  };
39393
39392
  const getHeaderCellClass = (rowIndex, columnIndex, row, column) => {
39394
- const classes = [column.id, column.order, column.headerAlign, column.className, column.labelClass];
39395
- if (rowIndex === 0 && isCellHidden(columnIndex, row)) {
39393
+ const classes = [column.id, column.order, column.realHeaderAlign, column.className, column.labelClass];
39394
+ if (rowIndex === 0 && columnsHidden.value[columnIndex]) {
39396
39395
  classes.push('is-hidden');
39397
39396
  }
39398
39397
  if (!column.children) {
@@ -39425,7 +39424,7 @@
39425
39424
  /* istanbul ignore if */
39426
39425
  if (draggingColumn.value && props.border) {
39427
39426
  dragging.value = true;
39428
- table.exposed.resizeProxyVisible.value = true;
39427
+ table.resizeProxyVisible.value = true;
39429
39428
  const tableEl = table.vnode.el;
39430
39429
  const tableLeft = tableEl.getBoundingClientRect().left;
39431
39430
  const columnEl = instance.vnode.el.querySelector(`.vc-table__th.${column.id}`);
@@ -39438,7 +39437,7 @@
39438
39437
  startColumnLeft: columnRect.left - tableLeft,
39439
39438
  tableLeft
39440
39439
  };
39441
- const resizeProxy = table.exposed.resizeProxy.value;
39440
+ const resizeProxy = table.resizeProxy.value;
39442
39441
  resizeProxy.style.left = dragState.value.startLeft + 'px';
39443
39442
  document.onselectstart = () => false;
39444
39443
  document.ondragstart = () => false;
@@ -39532,37 +39531,27 @@
39532
39531
  });
39533
39532
  };
39534
39533
  return () => {
39535
- const {
39536
- originColumns
39537
- } = props.store.states;
39538
- const columnRows = convertToRows(originColumns);
39539
-
39540
- // 是否拥有多级表头
39541
- const isGroup = columnRows.length > 1;
39542
- if (isGroup) table.exposed.isGroup.value = true;
39543
39534
  return vue.createVNode("div", {
39544
39535
  "class": "vc-table__header"
39545
39536
  }, [vue.createVNode("div", {
39546
39537
  "class": [{
39547
- 'is-group': isGroup
39538
+ 'is-group': states.isGroup
39548
39539
  }, 'vc-table__thead']
39549
39540
  }, [
39550
39541
  // renderList
39551
- columnRows.map((columns, rowIndex) => vue.createVNode("div", {
39542
+ states.headerRows.map((columns, rowIndex) => vue.createVNode("div", {
39552
39543
  "style": getHeaderRowStyle(rowIndex),
39553
39544
  "class": [getHeaderRowClass(rowIndex), 'vc-table__tr']
39554
- }, [columns.map((column, cellIndex) => vue.createVNode("div", {
39555
- "colspan": column.colSpan,
39556
- "rowspan": column.rowSpan,
39557
- "onMousemove": $event => handleMouseMove($event, column),
39545
+ }, [columns.map((column, columnIndex) => vue.createVNode("div", {
39546
+ "onMousemove": e => handleMouseMove(e, column),
39558
39547
  "onMouseout": handleMouseOut,
39559
- "onMousedown": $event => handleMouseDown($event, column),
39560
- "onClick": $event => handleHeaderClick($event, column),
39561
- "onContextmenu": $event => handleHeaderContextMenu($event, column),
39562
- "style": [getHeaderCellStyle(rowIndex, cellIndex, columns, column), {
39548
+ "onMousedown": e => handleMouseDown(e, column),
39549
+ "onClick": e => handleHeaderClick(e, column),
39550
+ "onContextmenu": e => handleHeaderContextMenu(e, column),
39551
+ "style": [getHeaderCellStyle(rowIndex, columnIndex, columns, column), {
39563
39552
  width: `${column.realWidth}px`
39564
39553
  }],
39565
- "class": [getHeaderCellClass(rowIndex, cellIndex, columns, column), 'vc-table__th'],
39554
+ "class": [getHeaderCellClass(rowIndex, columnIndex, columns, column), 'vc-table__th'],
39566
39555
  "key": column.id
39567
39556
  }, [vue.createVNode("div", {
39568
39557
  "class": ['vc-table__cell',
@@ -39572,10 +39561,8 @@
39572
39561
  column.labelClass]
39573
39562
  }, [column.renderHeader ? column.renderHeader({
39574
39563
  column,
39575
- $index: cellIndex,
39576
- // index: cellIndex,
39577
- store: props.store,
39578
- _self: instance
39564
+ columnIndex,
39565
+ store: props.store
39579
39566
  }) : column.label, column.tooltip ? vue.createVNode(Icon, {
39580
39567
  "type": "o-info",
39581
39568
  "onMouseenter": e => handleCellMouseEnter(e, column)
@@ -39617,28 +39604,28 @@
39617
39604
  leftFixedCount: $states => $states.leftFixedColumns.length,
39618
39605
  rightFixedCount: $states => $states.rightFixedColumns.length
39619
39606
  });
39620
- const isCellHidden = (index, columns, column) => {
39607
+ const isColumnHidden = (column, index) => {
39621
39608
  if (props.fixed === true || props.fixed === 'left') {
39622
39609
  return index >= states.leftFixedLeafCount;
39623
39610
  } else if (props.fixed === 'right') {
39624
39611
  let before = 0;
39625
39612
  for (let i = 0; i < index; i++) {
39626
- before += columns[i].colSpan;
39613
+ before += states.columns[i].colSpan;
39627
39614
  }
39628
39615
  return before < states.columnsCount - states.rightFixedLeafCount;
39629
39616
  } else if (!props.fixed && column.fixed) {
39630
- // hide cell when footer instance is not fixed and column is fixed
39631
39617
  return true;
39632
39618
  } else {
39633
39619
  return index < states.leftFixedCount || index >= states.columnsCount - states.rightFixedCount;
39634
39620
  }
39635
39621
  };
39636
- const getRowClasses = (column, cellIndex) => {
39637
- const classes = [column.id, column.align, column.labelClass];
39622
+ const columnsHidden = vue.computed(() => states.columns.map(isColumnHidden));
39623
+ const getRowClasses = (column, columnIndex) => {
39624
+ const classes = [column.realAlign, column.labelClass];
39638
39625
  if (column.className) {
39639
39626
  classes.push(column.className);
39640
39627
  }
39641
- if (isCellHidden(cellIndex, states.columns, column)) {
39628
+ if (columnsHidden.value[columnIndex]) {
39642
39629
  classes.push('is-hidden');
39643
39630
  }
39644
39631
  if (!column.children) {
@@ -39646,17 +39633,17 @@
39646
39633
  }
39647
39634
  return classes;
39648
39635
  };
39649
- return () => {
39650
- let sums = [];
39636
+ const sums = vue.computed(() => {
39637
+ let v = [];
39651
39638
  if (props.getSummary) {
39652
- sums = props.getSummary({
39639
+ v = props.getSummary({
39653
39640
  columns: states.columns,
39654
39641
  data: states.data
39655
39642
  });
39656
39643
  } else {
39657
39644
  states.columns.forEach((column, index) => {
39658
39645
  if (index === 0) {
39659
- sums[index] = props.sumText;
39646
+ v[index] = props.sumText;
39660
39647
  return;
39661
39648
  }
39662
39649
  const values = states.data.map(item => Number(item[column.prop]));
@@ -39671,7 +39658,7 @@
39671
39658
  });
39672
39659
  const precision = Math.max.apply(null, precisions);
39673
39660
  if (!notNumber) {
39674
- sums[index] = values.reduce((prev, curr) => {
39661
+ v[index] = values.reduce((prev, curr) => {
39675
39662
  const value = Number(curr);
39676
39663
  if (!isNaN(value)) {
39677
39664
  return parseFloat((prev + curr).toFixed(Math.min(precision, 20)));
@@ -39680,10 +39667,13 @@
39680
39667
  }
39681
39668
  }, 0);
39682
39669
  } else {
39683
- sums[index] = '';
39670
+ v[index] = '';
39684
39671
  }
39685
39672
  });
39686
39673
  }
39674
+ return v;
39675
+ });
39676
+ return () => {
39687
39677
  return vue.createVNode("div", {
39688
39678
  "class": "vc-table__footer",
39689
39679
  "cellspacing": "0",
@@ -39693,17 +39683,15 @@
39693
39683
  "class": "vc-table__tbody"
39694
39684
  }, [vue.createVNode("div", {
39695
39685
  "class": "vc-table__tr"
39696
- }, [states.columns.map((column, cellIndex) => vue.createVNode("div", {
39697
- "key": cellIndex,
39698
- "colspan": column.colSpan,
39699
- "rowspan": column.rowSpan,
39700
- "class": [getRowClasses(column, cellIndex), 'vc-table__td'],
39686
+ }, [states.columns.map((column, columnIndex) => vue.createVNode("div", {
39687
+ "key": columnIndex,
39688
+ "class": [getRowClasses(column, columnIndex), 'vc-table__td'],
39701
39689
  "style": [{
39702
39690
  width: `${column.realWidth}px`
39703
39691
  }]
39704
39692
  }, [vue.createVNode("div", {
39705
39693
  "class": ['vc-table__cell', column.labelClass]
39706
- }, [sums[cellIndex]])]))])])]);
39694
+ }, [sums.value[columnIndex]])]))])])]);
39707
39695
  };
39708
39696
  }
39709
39697
  });
@@ -39731,7 +39719,7 @@
39731
39719
  type: Number,
39732
39720
  default: 10
39733
39721
  },
39734
- rowKey: [String, Function],
39722
+ primaryKey: [String, Function],
39735
39723
  // 是否显示表头
39736
39724
  showHeader: {
39737
39725
  type: Boolean,
@@ -39808,7 +39796,8 @@
39808
39796
  emits: ['select', 'select-all', 'selection-change', 'cell-mouse-enter', 'cell-mouse-leave', 'cell-click', 'cell-dblclick', 'row-click', 'row-contextmenu', 'row-dblclick', 'header-click', 'header-contextmenu', 'current-change', 'header-dragend ', 'expand-change', 'sort-change'],
39809
39797
  setup(props, {
39810
39798
  slots,
39811
- expose
39799
+ expose,
39800
+ emit
39812
39801
  }) {
39813
39802
  const instance = vue.getCurrentInstance();
39814
39803
  const store = new Store({
@@ -39848,23 +39837,21 @@
39848
39837
  const rightFixedBody = vue.ref(null);
39849
39838
  const rightFixedFooterWrapper = vue.ref(null);
39850
39839
  const resizeProxy = vue.ref(null);
39851
-
39852
- // 是否拥有多级表头, 由table-header控制
39853
- const isGroup = vue.ref(false);
39854
39840
  const scrollPosition = vue.ref('left');
39855
39841
  const hoverState = vue.ref(null);
39856
39842
  const isReady = vue.ref(false);
39857
39843
  const states = useStates({
39858
39844
  columns: 'columns',
39859
39845
  leftFixedColumns: 'leftFixedColumns',
39860
- rightFixedColumns: 'rightFixedColumns'
39846
+ rightFixedColumns: 'rightFixedColumns',
39847
+ isGroup: 'isGroup'
39861
39848
  }, store);
39862
39849
  const classes = vue.computed(() => {
39863
39850
  return {
39864
39851
  'vc-table--fit': props.fit,
39865
39852
  'vc-table--striped': props.stripe,
39866
- 'vc-table--border': props.border || isGroup.value,
39867
- 'vc-table--group': isGroup.value,
39853
+ 'vc-table--border': props.border || states.isGroup,
39854
+ 'vc-table--group': states.isGroup,
39868
39855
  'vc-table--fluid-height': props.maxHeight,
39869
39856
  'vc-table--scrollable-x': layout.states.scrollX,
39870
39857
  'vc-table--scrollable-y': layout.states.scrollY,
@@ -40125,13 +40112,13 @@
40125
40112
  immediate: true
40126
40113
  });
40127
40114
  vue.watch(() => props.currentRowValue, v => {
40128
- if (!props.rowKey) return;
40115
+ if (!props.primaryKey) return;
40129
40116
  store.current.reset(v);
40130
40117
  }, {
40131
40118
  immediate: true
40132
40119
  });
40133
- vue.watch(() => props.data, v => {
40134
- store.setData(v);
40120
+ vue.watch(() => [props.data, props.data.length], () => {
40121
+ store.setData(props.data);
40135
40122
  isReady.value && vue.nextTick(refreshLayout);
40136
40123
  }, {
40137
40124
  immediate: true
@@ -40154,6 +40141,7 @@
40154
40141
  }, {
40155
40142
  immediate: true
40156
40143
  });
40144
+ const tableId = getUid('table');
40157
40145
  vue.onMounted(() => {
40158
40146
  bindEvents();
40159
40147
  store.updateColumns();
@@ -40164,12 +40152,13 @@
40164
40152
  };
40165
40153
  isReady.value = true;
40166
40154
  });
40167
- vue.onBeforeUnmount(() => {
40155
+ vue.onUnmounted(() => {
40168
40156
  isUnMount = true;
40169
40157
  unbindEvents();
40170
40158
  });
40171
- const tableId = getUid('table');
40172
- expose({
40159
+ const exposed = {
40160
+ bodyXWrapper,
40161
+ bodyYWrapper,
40173
40162
  tableId,
40174
40163
  store,
40175
40164
  layout,
@@ -40189,8 +40178,12 @@
40189
40178
  isReady,
40190
40179
  hoverState,
40191
40180
  renderExpanded,
40192
- hiddenColumns
40193
- });
40181
+ hiddenColumns,
40182
+ props,
40183
+ emit
40184
+ };
40185
+ expose(exposed);
40186
+ vue.provide('vc-table', exposed);
40194
40187
  return () => {
40195
40188
  return vue.createVNode("div", {
40196
40189
  "class": [classes.value, tableId, 'vc-table'],
@@ -40339,22 +40332,19 @@
40339
40332
  order: ''
40340
40333
  },
40341
40334
  selection: {
40342
- width: 48,
40343
- minWidth: 48,
40344
- realWidth: 48,
40335
+ width: 60,
40336
+ minWidth: 60,
40345
40337
  order: '',
40346
40338
  className: 'vc-table-column--selection'
40347
40339
  },
40348
40340
  expand: {
40349
- width: 48,
40350
- minWidth: 48,
40351
- realWidth: 48,
40341
+ width: 60,
40342
+ minWidth: 60,
40352
40343
  order: ''
40353
40344
  },
40354
40345
  index: {
40355
- width: 48,
40356
- minWidth: 48,
40357
- realWidth: 48,
40346
+ width: 60,
40347
+ minWidth: 60,
40358
40348
  order: ''
40359
40349
  }
40360
40350
  };
@@ -40380,10 +40370,11 @@
40380
40370
  column,
40381
40371
  store,
40382
40372
  rowIndex,
40383
- level
40373
+ level,
40374
+ selected
40384
40375
  }) {
40385
40376
  return vue.withDirectives(vue.createVNode(Checkbox, {
40386
- "modelValue": store.isSelected(row),
40377
+ "modelValue": selected,
40387
40378
  "disabled": column.selectable ? !column.selectable.call(null, row, rowIndex) : false,
40388
40379
  "onChange": () => store.rowSelectedChanged(row),
40389
40380
  "onClick": e => e.stopPropagation()
@@ -40521,8 +40512,8 @@
40521
40512
  customClass: String,
40522
40513
  labelClass: String,
40523
40514
  prop: String,
40524
- width: [Number, String],
40525
- minWidth: [Number, String],
40515
+ width: Number,
40516
+ minWidth: Number,
40526
40517
  renderHeader: Function,
40527
40518
  resizable: {
40528
40519
  type: Boolean,
@@ -40556,15 +40547,14 @@
40556
40547
  tooltip: [String, Function]
40557
40548
  },
40558
40549
  setup(props, {
40559
- slots,
40560
- expose
40550
+ slots
40561
40551
  }) {
40562
40552
  const instance = vue.getCurrentInstance();
40563
- const table = getInstance$1('table', 'tableId');
40564
- const parent = getInstance$1('table-column', 'columnId') || table;
40553
+ const table = vue.inject('vc-table');
40554
+ const parent = vue.inject('vc-table-column', table);
40565
40555
  const isSubColumn = table !== parent; // 用于多久表头
40566
40556
 
40567
- const columnId = vue.ref((parent.exposed.tableId || parent.exposed.columnId) + getUid('column'));
40557
+ const columnId = vue.ref((parent.tableId || parent.columnId) + getUid('column'));
40568
40558
  const realWidth = vue.computed(() => {
40569
40559
  return parseWidth(props.width);
40570
40560
  });
@@ -40594,7 +40584,6 @@
40594
40584
  }, {});
40595
40585
  return result;
40596
40586
  };
40597
-
40598
40587
  /**
40599
40588
  * compose 1
40600
40589
  * 对于特定类型的 column,某些属性不允许设置
@@ -40664,7 +40653,7 @@
40664
40653
  column.renderCell = data => vue.createVNode("div", {
40665
40654
  "class": "vc-table__cell"
40666
40655
  }, [originRenderCell(data)]);
40667
- table.exposed.renderExpanded.value = data => {
40656
+ table.renderExpanded.value = data => {
40668
40657
  return slots.default ? slots.default(data) : slots.default;
40669
40658
  };
40670
40659
  } else {
@@ -40683,7 +40672,7 @@
40683
40672
  style: {}
40684
40673
  };
40685
40674
  // 存在树形数组,且当前行无箭头图标且处于当前展开列,表格对齐
40686
- if (!isEmpty$1(table.exposed.store.states.treeData) && !prefix && data.isExpandColumn) {
40675
+ if (!isEmpty$1(table.store.states.treeData) && !prefix && data.isExpandColumn) {
40687
40676
  prefix = vue.createVNode("span", {
40688
40677
  "class": "vc-table-un-expand__indent"
40689
40678
  }, null);
@@ -40703,26 +40692,16 @@
40703
40692
  }
40704
40693
  return column;
40705
40694
  };
40706
- const refreshColumnBasicConfig = () => {
40695
+ const registerColumn = () => {
40707
40696
  const defaults = {
40708
40697
  ...cellStarts[props.type],
40709
- type: props.type,
40710
40698
  id: columnId.value,
40711
- align: realAlign.value,
40712
- headerAlign: realHeaderAlign.value,
40713
- prop: props.prop,
40714
- showPopover: props.showPopover,
40715
- // index 列
40716
- index: props.index
40699
+ realAlign,
40700
+ realHeaderAlign
40717
40701
  };
40718
- const basicProps = ['columnKey', 'label', 'customClass', 'labelClass', 'type', 'renderHeader', 'resizable', 'formatter', 'fixed', 'resizable']; // eslint-disable-line
40719
- const selectProps = ['selectable', 'reserveSelection'];
40720
- const sortProps = ['sortable'];
40721
- const filterProps = ['filters', 'filteredValue', 'filterMultiple', 'filter', 'filterIcon', 'filterPopupClass'];
40722
- let column = getPropsData(basicProps, selectProps, sortProps, filterProps);
40723
- column = merge$1(defaults, column);
40724
-
40725
- // 注意 compose 中函数执行的顺序是从右到左
40702
+ let column = merge$1(defaults, getPropsData(Object.keys(props)));
40703
+
40704
+ // minWidth/realWidth/renderHeader
40726
40705
  column = compose(setColumnRenders, setColumnWidth, setColumnForcedProps)(column);
40727
40706
  for (const key in column) {
40728
40707
  if (hasOwn$1(column, key)) {
@@ -40730,34 +40709,39 @@
40730
40709
  }
40731
40710
  }
40732
40711
  };
40733
- const registerComplexWatchers = () => {
40712
+ const registerWatchers = () => {
40713
+ // 赋值
40714
+ Object.keys(props).forEach(k => vue.watch(() => props[k], v => columnConfig[k] = v));
40715
+
40716
+ // 影响布局
40734
40717
  vue.watch(() => props.fixed, () => {
40735
- table.exposed.store.scheduleLayout(true);
40718
+ table.store.scheduleLayout(true);
40736
40719
  });
40737
- vue.watch(() => realWidth.value, () => {
40738
- table.exposed.store.scheduleLayout(false);
40720
+ vue.watch(() => realWidth.value, v => {
40721
+ columnConfig['width'] = v;
40722
+ columnConfig['realWidth'] = v;
40723
+ table.store.scheduleLayout(false);
40739
40724
  });
40740
40725
  vue.watch(() => realMinWidth.value, () => {
40741
- table.exposed.store.scheduleLayout(false);
40726
+ table.store.scheduleLayout(false);
40742
40727
  });
40743
40728
  };
40744
40729
  vue.onBeforeMount(() => {
40745
- refreshColumnBasicConfig();
40746
- registerComplexWatchers();
40730
+ registerColumn();
40731
+ registerWatchers();
40747
40732
  });
40748
- vue.onUpdated(refreshColumnBasicConfig);
40749
40733
  vue.onMounted(() => {
40750
- const children = isSubColumn ? parent.vnode.el.children : parent.exposed.hiddenColumns.value.children;
40734
+ const children = isSubColumn ? parent.vnode.el.children : parent.hiddenColumns.value.children;
40751
40735
 
40752
40736
  // DOM上
40753
40737
  const columnIndex = [...children].indexOf(instance.vnode.el);
40754
- table.exposed.store.insertColumn(columnConfig, columnIndex, isSubColumn && parent.exposed.columnConfig);
40738
+ table.store.insertColumn(columnConfig, columnIndex, isSubColumn && parent.columnConfig);
40755
40739
  });
40756
40740
  vue.onUnmounted(() => {
40757
40741
  if (!instance.parent) return;
40758
- table.exposed.store.removeColumn(columnConfig, isSubColumn && parent.exposed.columnConfig);
40742
+ table.store.removeColumn(columnConfig, isSubColumn && parent.columnConfig);
40759
40743
  });
40760
- expose({
40744
+ vue.provide('vc-table-column', {
40761
40745
  columnId,
40762
40746
  columnConfig
40763
40747
  });
@@ -40773,7 +40757,8 @@
40773
40757
  const renderDefault = slots?.default?.({
40774
40758
  row: {},
40775
40759
  column: {},
40776
- $index: -1
40760
+ columnIndex: -1,
40761
+ rowIndex: -1
40777
40762
  });
40778
40763
  if (renderDefault instanceof Array) {
40779
40764
  for (const childNode of renderDefault) {