vxe-table 4.17.2 → 4.17.4

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.
@@ -2,7 +2,7 @@ import { h, ref, inject, nextTick, onMounted, onUnmounted } from 'vue';
2
2
  import { defineVxeComponent } from '../../ui/src/comp';
3
3
  import XEUtils from 'xe-utils';
4
4
  import { VxeUI } from '../../ui';
5
- import { getOffsetSize, calcTreeLine, getRowid, createHandleGetRowId, getCellRestHeight } from './util';
5
+ import { getRowid, createHandleGetRowId, getCellRestHeight } from './util';
6
6
  import { updateCellTitle, getPropClass } from '../../ui/src/dom';
7
7
  import { isEnableConf } from '../../ui/src/utils';
8
8
  import { getSlotVNs } from '../../ui/src/vn';
@@ -40,22 +40,38 @@ export default defineVxeComponent({
40
40
  };
41
41
  const renderLine = (rowid, params, cellHeight) => {
42
42
  const { column } = params;
43
- const { afterFullData } = tableInternalData;
44
43
  const { treeConfig } = tableProps;
44
+ const cellOpts = computeCellOpts.value;
45
+ const rowOpts = computeRowOpts.value;
46
+ const defaultRowHeight = computeDefaultRowHeight.value;
45
47
  const treeOpts = computeTreeOpts.value;
46
48
  const { slots, treeNode } = column;
47
49
  const { fullAllDataRowIdData } = tableInternalData;
48
- if (slots && slots.line) {
49
- return $xeTable.callSlot(slots.line, params);
50
- }
51
- const rowRest = fullAllDataRowIdData[rowid];
52
- let rLevel = 0;
53
- let prevRow = null;
54
- if (rowRest) {
55
- rLevel = rowRest.level;
56
- prevRow = rowRest.items[rowRest.treeIndex - 1];
57
- }
58
50
  if (treeConfig && treeNode && (treeOpts.showLine || treeOpts.line)) {
51
+ if (slots && slots.line) {
52
+ return $xeTable.callSlot(slots.line, params);
53
+ }
54
+ const rowRest = fullAllDataRowIdData[rowid];
55
+ let rLevel = 0;
56
+ let prevRow = null;
57
+ let parentRow = null;
58
+ let lineHeight = '';
59
+ if (rowRest) {
60
+ rLevel = rowRest.level;
61
+ prevRow = rowRest.items[rowRest.treeIndex - 1];
62
+ parentRow = rowRest.parent;
63
+ }
64
+ if (!rLevel && !treeOpts.showRootLine) {
65
+ return [];
66
+ }
67
+ if (prevRow) {
68
+ const prevRowRest = fullAllDataRowIdData[getRowid($xeTable, prevRow)] || {};
69
+ lineHeight = `${prevRowRest.lineHeight || 0}px`;
70
+ }
71
+ else if (rLevel && parentRow) {
72
+ const parentRowRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)] || {};
73
+ lineHeight = `calc(-1em + ${Math.floor(cellHeight / 2 + getCellRestHeight(parentRowRest, cellOpts, rowOpts, defaultRowHeight) / 2)}px)`;
74
+ }
59
75
  return [
60
76
  h('div', {
61
77
  key: 'tl',
@@ -64,9 +80,9 @@ export default defineVxeComponent({
64
80
  h('div', {
65
81
  class: 'vxe-tree--line',
66
82
  style: {
67
- height: `${getRowid($xeTable, afterFullData[0]) === rowid ? 1 : calcTreeLine(params, prevRow)}px`,
83
+ height: lineHeight,
68
84
  bottom: `-${Math.floor(cellHeight / 2)}px`,
69
- left: `${(rLevel * treeOpts.indent) + (rLevel ? 2 - getOffsetSize($xeTable) : 0) + 16}px`
85
+ left: `calc(${(rLevel * treeOpts.indent)}px + 1em)`
70
86
  }
71
87
  })
72
88
  ])
@@ -1510,7 +1510,7 @@ export default defineVxeComponent({
1510
1510
  const customOpts = computeCustomOpts.value;
1511
1511
  const { storage, storeOptions } = customOpts;
1512
1512
  const isAllCustom = storage === true;
1513
- const storageOpts = isAllCustom ? {} : Object.assign({}, storage || {}, storeOptions);
1513
+ const storageOpts = Object.assign({}, isAllCustom ? {} : storage || {}, storeOptions);
1514
1514
  const isCustomResizable = hangleStorageDefaultValue(storageOpts.resizable, isAllCustom);
1515
1515
  const isCustomVisible = hangleStorageDefaultValue(storageOpts.visible, isAllCustom);
1516
1516
  const isCustomFixed = hangleStorageDefaultValue(storageOpts.fixed, isAllCustom);
@@ -1603,7 +1603,7 @@ export default defineVxeComponent({
1603
1603
  const customOpts = computeCustomOpts.value;
1604
1604
  const { storage, restoreStore, storeOptions } = customOpts;
1605
1605
  const isAllCustom = storage === true;
1606
- const storageOpts = isAllCustom ? {} : Object.assign({}, storage || {}, storeOptions);
1606
+ const storageOpts = Object.assign({}, isAllCustom ? {} : storage || {}, storeOptions);
1607
1607
  const isCustomResizable = hangleStorageDefaultValue(storageOpts.resizable, isAllCustom);
1608
1608
  const isCustomVisible = hangleStorageDefaultValue(storageOpts.visible, isAllCustom);
1609
1609
  const isCustomFixed = hangleStorageDefaultValue(storageOpts.fixed, isAllCustom);
@@ -1771,6 +1771,9 @@ export default defineVxeComponent({
1771
1771
  internalData.customHeight = 300;
1772
1772
  }
1773
1773
  };
1774
+ /**
1775
+ * 计算自适应列宽
1776
+ */
1774
1777
  const calcColumnAutoWidth = (column, wrapperEl) => {
1775
1778
  const columnOpts = computeColumnOpts.value;
1776
1779
  const { autoOptions } = columnOpts;
@@ -1799,6 +1802,9 @@ export default defineVxeComponent({
1799
1802
  }
1800
1803
  return colWidth + leftRightPadding;
1801
1804
  };
1805
+ /**
1806
+ * 自适应列宽
1807
+ */
1802
1808
  const calcCellWidth = () => {
1803
1809
  const autoWidthColumnList = computeAutoWidthColumnList.value;
1804
1810
  const { fullColumnIdData } = internalData;
@@ -1931,6 +1937,9 @@ export default defineVxeComponent({
1931
1937
  updateColumnOffsetLeft();
1932
1938
  updateHeight();
1933
1939
  };
1940
+ /**
1941
+ * 计算自适应行高
1942
+ */
1934
1943
  const calcCellAutoHeight = (rowRest, wrapperEl) => {
1935
1944
  const cellElemList = wrapperEl.querySelectorAll(`.vxe-cell--wrapper[rowid="${rowRest.rowid}"]`);
1936
1945
  let colHeight = rowRest.height;
@@ -1948,12 +1957,17 @@ export default defineVxeComponent({
1948
1957
  }
1949
1958
  return colHeight;
1950
1959
  };
1960
+ /**
1961
+ * 自适应行高
1962
+ */
1951
1963
  const calcCellHeight = () => {
1964
+ const { treeConfig } = props;
1952
1965
  const { tableData, isAllOverflow, scrollYLoad, scrollXLoad } = reactData;
1953
1966
  const { fullAllDataRowIdData } = internalData;
1967
+ const treeOpts = computeTreeOpts.value;
1954
1968
  const defaultRowHeight = computeDefaultRowHeight.value;
1955
1969
  const el = refElem.value;
1956
- if (!isAllOverflow && (scrollYLoad || scrollXLoad) && el) {
1970
+ if (!isAllOverflow && (scrollYLoad || scrollXLoad || (treeConfig && treeOpts.showLine)) && el) {
1957
1971
  const { handleGetRowId } = createHandleGetRowId($xeTable);
1958
1972
  el.setAttribute('data-calc-row', 'Y');
1959
1973
  tableData.forEach(row => {
@@ -3245,6 +3259,9 @@ export default defineVxeComponent({
3245
3259
  calcScrollbar();
3246
3260
  updateStyle();
3247
3261
  updateRowExpandStyle();
3262
+ if (reFull) {
3263
+ updateTreeLineStyle();
3264
+ }
3248
3265
  return computeScrollLoad().then(() => {
3249
3266
  // 初始化时需要在列计算之后再执行优化运算,达到最优显示效果
3250
3267
  if (reWidth) {
@@ -3262,6 +3279,9 @@ export default defineVxeComponent({
3262
3279
  updateRowOffsetTop();
3263
3280
  }
3264
3281
  updateRowExpandStyle();
3282
+ if (reFull) {
3283
+ updateTreeLineStyle();
3284
+ }
3265
3285
  if (reFull) {
3266
3286
  return computeScrollLoad();
3267
3287
  }
@@ -3602,6 +3622,7 @@ export default defineVxeComponent({
3602
3622
  }
3603
3623
  reactData.isRowLoading = false;
3604
3624
  handleRecalculateStyle(false, false, false);
3625
+ updateTreeLineStyle();
3605
3626
  // 如果是自动行高,特殊情况需调用 recalculate 手动刷新
3606
3627
  if (!props.showOverflow) {
3607
3628
  setTimeout(() => {
@@ -3615,6 +3636,7 @@ export default defineVxeComponent({
3615
3636
  .then(() => {
3616
3637
  handleRecalculateStyle(false, true, true);
3617
3638
  updateRowOffsetTop();
3639
+ updateTreeLineStyle();
3618
3640
  resolve();
3619
3641
  });
3620
3642
  }
@@ -3624,6 +3646,7 @@ export default defineVxeComponent({
3624
3646
  .then(() => {
3625
3647
  handleRecalculateStyle(false, true, true);
3626
3648
  updateRowOffsetTop();
3649
+ updateTreeLineStyle();
3627
3650
  resolve();
3628
3651
  });
3629
3652
  });
@@ -3979,6 +4002,7 @@ export default defineVxeComponent({
3979
4002
  }
3980
4003
  reactData.treeExpandedFlag++;
3981
4004
  return Promise.all(result).then(() => {
4005
+ updateTreeLineStyle();
3982
4006
  return $xeTable.recalculate();
3983
4007
  });
3984
4008
  };
@@ -4419,7 +4443,89 @@ export default defineVxeComponent({
4419
4443
  * 更新树连接线样式
4420
4444
  */
4421
4445
  const updateTreeLineStyle = () => {
4422
- // 待优化
4446
+ const { treeConfig } = props;
4447
+ if (!treeConfig) {
4448
+ return;
4449
+ }
4450
+ const { tableData } = reactData;
4451
+ const { fullAllDataRowIdData, treeExpandedMaps } = internalData;
4452
+ const cellOpts = computeCellOpts.value;
4453
+ const rowOpts = computeRowOpts.value;
4454
+ const defaultRowHeight = computeDefaultRowHeight.value;
4455
+ const treeOpts = computeTreeOpts.value;
4456
+ const { transform, mapChildrenField } = treeOpts;
4457
+ const childrenField = treeOpts.children || treeOpts.childrenField;
4458
+ const { handleGetRowId } = createHandleGetRowId($xeTable);
4459
+ const expParentList = [];
4460
+ const handleNodeRow = (row, rIndex, rows) => {
4461
+ const rowid = handleGetRowId(row);
4462
+ const rowRest = fullAllDataRowIdData[rowid] || {};
4463
+ const childList = row[transform ? mapChildrenField : childrenField];
4464
+ const prevRow = rows[rIndex - 1] || null;
4465
+ const nextRow = rows[rIndex + 1] || null;
4466
+ if (childList && childList.length && treeExpandedMaps[rowid]) {
4467
+ expParentList.push({ row, prevRow, nextRow });
4468
+ childList.forEach((childRow, crIndex) => {
4469
+ const childRowid = handleGetRowId(childRow);
4470
+ if (treeExpandedMaps[childRowid]) {
4471
+ handleNodeRow(childRow, crIndex, childList);
4472
+ }
4473
+ });
4474
+ }
4475
+ else {
4476
+ if (nextRow) {
4477
+ const nextRowid = handleGetRowId(nextRow);
4478
+ const nextRowRest = fullAllDataRowIdData[nextRowid] || {};
4479
+ const currCellHeight = getCellRestHeight(rowRest, cellOpts, rowOpts, defaultRowHeight);
4480
+ const nextCellHeight = getCellRestHeight(nextRowRest, cellOpts, rowOpts, defaultRowHeight);
4481
+ rowRest.oHeight = currCellHeight;
4482
+ rowRest.lineHeight = Math.floor(currCellHeight / 2 + nextCellHeight / 2);
4483
+ }
4484
+ else {
4485
+ rowRest.oHeight = 0;
4486
+ rowRest.lineHeight = 0;
4487
+ }
4488
+ }
4489
+ };
4490
+ tableData.forEach((row, rIndex) => {
4491
+ handleNodeRow(row, rIndex, tableData);
4492
+ });
4493
+ XEUtils.lastArrayEach(expParentList, ({ row, nextRow }) => {
4494
+ const rowid = handleGetRowId(row);
4495
+ const childList = row[transform ? mapChildrenField : childrenField];
4496
+ const rowRest = fullAllDataRowIdData[rowid];
4497
+ if (rowRest) {
4498
+ const currCellHeight = getCellRestHeight(rowRest, cellOpts, rowOpts, defaultRowHeight);
4499
+ let countOffsetHeight = currCellHeight;
4500
+ let countLineHeight = 0;
4501
+ childList.forEach((childRow) => {
4502
+ const childRowid = handleGetRowId(childRow);
4503
+ const childRowRest = fullAllDataRowIdData[childRowid] || {};
4504
+ const childList = childRow[transform ? mapChildrenField : childrenField];
4505
+ if (treeExpandedMaps[childRowid] && childList && childList.length) {
4506
+ countOffsetHeight += (childRowRest.oHeight || 0);
4507
+ countLineHeight += (childRowRest.oHeight || 0);
4508
+ }
4509
+ else {
4510
+ const cellHeight = getCellRestHeight(childRowRest, cellOpts, rowOpts, defaultRowHeight);
4511
+ childRowRest.oHeight = cellHeight;
4512
+ childRowRest.lineHeight = cellHeight;
4513
+ countOffsetHeight += cellHeight;
4514
+ countLineHeight += cellHeight;
4515
+ }
4516
+ });
4517
+ if (nextRow) {
4518
+ const nextRowid = handleGetRowId(nextRow);
4519
+ const nextRowRest = fullAllDataRowIdData[nextRowid] || {};
4520
+ const currCellHeight = getCellRestHeight(rowRest, cellOpts, rowOpts, defaultRowHeight);
4521
+ const nextCellHeight = getCellRestHeight(nextRowRest, cellOpts, rowOpts, defaultRowHeight);
4522
+ countOffsetHeight += currCellHeight;
4523
+ countLineHeight += Math.floor(currCellHeight / 2 + nextCellHeight / 2);
4524
+ }
4525
+ rowRest.lineHeight = countLineHeight;
4526
+ rowRest.oHeight = countOffsetHeight;
4527
+ }
4528
+ });
4423
4529
  };
4424
4530
  const handleRowExpandScroll = () => {
4425
4531
  const { elemStore } = internalData;
@@ -6841,6 +6947,7 @@ export default defineVxeComponent({
6841
6947
  }
6842
6948
  reactData.treeExpandedFlag++;
6843
6949
  }).then(() => {
6950
+ updateTreeLineStyle();
6844
6951
  if (expList.length) {
6845
6952
  return $xeTable.recalculate();
6846
6953
  }
@@ -7204,7 +7311,7 @@ export default defineVxeComponent({
7204
7311
  const { fullColumnFieldData, collectColumn } = internalData;
7205
7312
  const { storage, checkMethod, storeOptions } = customOpts;
7206
7313
  const isAllCustom = storage === true;
7207
- const storageOpts = isAllCustom ? {} : Object.assign({}, storage || {}, storeOptions);
7314
+ const storageOpts = Object.assign({}, isAllCustom ? {} : storage || {}, storeOptions);
7208
7315
  const isCustomResizable = hangleStorageDefaultValue(storageOpts.resizable, isAllCustom);
7209
7316
  const isCustomVisible = hangleStorageDefaultValue(storageOpts.visible, isAllCustom);
7210
7317
  const isCustomFixed = hangleStorageDefaultValue(storageOpts.fixed, isAllCustom);
@@ -8821,7 +8928,7 @@ export default defineVxeComponent({
8821
8928
  const customOpts = computeCustomOpts.value;
8822
8929
  const { updateStore, storage, storeOptions } = customOpts;
8823
8930
  const isAllCustom = storage === true;
8824
- const storageOpts = isAllCustom ? {} : Object.assign({}, storage || {}, storeOptions);
8931
+ const storageOpts = Object.assign({}, isAllCustom ? {} : storage || {}, storeOptions);
8825
8932
  const isCustomResizable = hangleStorageDefaultValue(storageOpts.resizable, isAllCustom);
8826
8933
  const isCustomVisible = hangleStorageDefaultValue(storageOpts.visible, isAllCustom);
8827
8934
  const isCustomFixed = hangleStorageDefaultValue(storageOpts.fixed, isAllCustom);
@@ -12763,7 +12870,7 @@ export default defineVxeComponent({
12763
12870
  }
12764
12871
  handleUpdateRowGroup(groupFields);
12765
12872
  nextTick(() => {
12766
- const { data, exportConfig, importConfig, treeConfig, showOverflow, highlightCurrentRow, highlightCurrentColumn } = props;
12873
+ const { data, exportConfig, importConfig, treeConfig, highlightCurrentRow, highlightCurrentColumn } = props;
12767
12874
  const { scrollXStore, scrollYStore } = internalData;
12768
12875
  const editOpts = computeEditOpts.value;
12769
12876
  const treeOpts = computeTreeOpts.value;
@@ -12795,9 +12902,9 @@ export default defineVxeComponent({
12795
12902
  if (props.editConfig && (editOpts.showStatus || editOpts.showUpdateStatus || editOpts.showInsertStatus) && !props.keepSource) {
12796
12903
  warnLog('vxe.error.reqProp', ['keep-source']);
12797
12904
  }
12798
- if (treeConfig && (treeOpts.showLine || treeOpts.line) && !showOverflow) {
12799
- warnLog('vxe.error.reqProp', ['show-overflow']);
12800
- }
12905
+ // if (treeConfig && (treeOpts.showLine || treeOpts.line) && !showOverflow) {
12906
+ // warnLog('vxe.error.reqProp', ['show-overflow'])
12907
+ // }
12801
12908
  if (treeConfig && !treeOpts.transform && props.stripe) {
12802
12909
  warnLog('vxe.error.noTree', ['stripe']);
12803
12910
  }
@@ -560,70 +560,6 @@ export function getLastChildColumn(column) {
560
560
  }
561
561
  return column;
562
562
  }
563
- const lineOffsetSizes = {
564
- mini: 3,
565
- small: 2,
566
- medium: 1,
567
- large: 0
568
- };
569
- function countTreeExpandSize(prevRow, params) {
570
- let count = 1;
571
- if (!prevRow) {
572
- return count;
573
- }
574
- const { $table } = params;
575
- const reactData = $table.reactData;
576
- const { treeExpandedFlag } = reactData;
577
- const internalData = $table.internalData;
578
- const { treeExpandedMaps } = internalData;
579
- const { computeTreeOpts } = $table.getComputeMaps();
580
- const treeOpts = computeTreeOpts.value;
581
- const { transform, mapChildrenField } = treeOpts;
582
- const childrenField = treeOpts.children || treeOpts.childrenField;
583
- const rowChildren = prevRow[transform ? mapChildrenField : childrenField];
584
- if (rowChildren && treeExpandedFlag && treeExpandedMaps[getRowid($table, prevRow)]) {
585
- for (let index = 0; index < rowChildren.length; index++) {
586
- count += countTreeExpandSize(rowChildren[index], params);
587
- }
588
- }
589
- return count;
590
- }
591
- export function getOffsetSize($xeTable) {
592
- const { computeSize } = $xeTable.getComputeMaps();
593
- const vSize = computeSize.value;
594
- if (vSize) {
595
- return lineOffsetSizes[vSize] || 0;
596
- }
597
- return 0;
598
- }
599
- export function calcTreeLine(params, prevRow) {
600
- const { $table, row } = params;
601
- const tableProps = $table.props;
602
- const tableReactData = $table.reactData;
603
- const tableInternalData = $table.internalData;
604
- const { showOverflow } = tableProps;
605
- const { scrollYLoad } = tableReactData;
606
- const { fullAllDataRowIdData } = tableInternalData;
607
- const { computeRowOpts, computeCellOpts, computeDefaultRowHeight } = $table.getComputeMaps();
608
- const rowOpts = computeRowOpts.value;
609
- const cellOpts = computeCellOpts.value;
610
- const defaultRowHeight = computeDefaultRowHeight.value;
611
- const rowid = getRowid($table, row);
612
- const rowRest = fullAllDataRowIdData[rowid];
613
- const currCellHeight = rowRest.resizeHeight || cellOpts.height || rowOpts.height || rowRest.height || defaultRowHeight;
614
- let expandSize = 1;
615
- if (prevRow) {
616
- expandSize = countTreeExpandSize(prevRow, params);
617
- }
618
- let cellHeight = currCellHeight;
619
- const vnHeight = rowRest.height;
620
- if (scrollYLoad) {
621
- if (!showOverflow) {
622
- cellHeight = vnHeight || currCellHeight;
623
- }
624
- }
625
- return cellHeight * expandSize - (prevRow ? 1 : (12 - getOffsetSize($table)));
626
- }
627
563
  export function clearTableDefaultStatus($xeTable) {
628
564
  const { props, internalData } = $xeTable;
629
565
  internalData.initStatus = false;
package/es/ui/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { VxeUI } from '@vxe-ui/core';
2
2
  import { getFuncText } from './src/utils';
3
- export const version = "4.17.2";
3
+ export const version = "4.17.4";
4
4
  VxeUI.version = version;
5
5
  VxeUI.tableVersion = version;
6
6
  VxeUI.setConfig({
@@ -172,7 +172,8 @@ VxeUI.setConfig({
172
172
  hasChildField: 'hasChild',
173
173
  mapChildrenField: '_X_ROW_CHILD',
174
174
  indent: 20,
175
- showIcon: true
175
+ showIcon: true,
176
+ showRootLine: true
176
177
  },
177
178
  expandConfig: {
178
179
  // trigger: 'default',
package/es/ui/src/log.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { VxeUI } from '@vxe-ui/core';
2
2
  const { log } = VxeUI;
3
- const version = `table v${"4.17.2"}`;
3
+ const version = `table v${"4.17.4"}`;
4
4
  export const warnLog = log.create('warn', version);
5
5
  export const errLog = log.create('error', version);