vxe-table 4.17.3 → 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
  ])
@@ -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 => {
@@ -3608,6 +3622,7 @@ export default defineVxeComponent({
3608
3622
  }
3609
3623
  reactData.isRowLoading = false;
3610
3624
  handleRecalculateStyle(false, false, false);
3625
+ updateTreeLineStyle();
3611
3626
  // 如果是自动行高,特殊情况需调用 recalculate 手动刷新
3612
3627
  if (!props.showOverflow) {
3613
3628
  setTimeout(() => {
@@ -3621,6 +3636,7 @@ export default defineVxeComponent({
3621
3636
  .then(() => {
3622
3637
  handleRecalculateStyle(false, true, true);
3623
3638
  updateRowOffsetTop();
3639
+ updateTreeLineStyle();
3624
3640
  resolve();
3625
3641
  });
3626
3642
  }
@@ -3630,6 +3646,7 @@ export default defineVxeComponent({
3630
3646
  .then(() => {
3631
3647
  handleRecalculateStyle(false, true, true);
3632
3648
  updateRowOffsetTop();
3649
+ updateTreeLineStyle();
3633
3650
  resolve();
3634
3651
  });
3635
3652
  });
@@ -4426,32 +4443,89 @@ export default defineVxeComponent({
4426
4443
  * 更新树连接线样式
4427
4444
  */
4428
4445
  const updateTreeLineStyle = () => {
4429
- // const { tableData } = reactData
4430
- // const { rowExpandedMaps } = internalData
4431
- // const treeOpts = computeTreeOpts.value
4432
- // const { transform, mapChildrenField } = treeOpts
4433
- // const childrenField = treeOpts.children || treeOpts.childrenField
4434
- // const { handleGetRowId } = createHandleGetRowId($xeTable)
4435
- // // 待优化
4436
- // if (transform) {
4437
- // // x
4438
- // } else {
4439
- // // x
4440
- // }
4441
- // const handleNodeRow = (row: any, parentRow: any) => {
4442
- // const childList: any[] = row[transform ? mapChildrenField : childrenField]
4443
- // if (childList && childList.length) {
4444
- // childList.forEach(childRow => {
4445
- // const childRowid = handleGetRowId(childRow)
4446
- // if (rowExpandedMaps[childRowid]) {
4447
- // handleNodeRow(childRow, row)
4448
- // }
4449
- // })
4450
- // }
4451
- // }
4452
- // tableData.forEach(row => {
4453
- // handleNodeRow(row, null)
4454
- // })
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
+ });
4455
4529
  };
4456
4530
  const handleRowExpandScroll = () => {
4457
4531
  const { elemStore } = internalData;
@@ -12796,7 +12870,7 @@ export default defineVxeComponent({
12796
12870
  }
12797
12871
  handleUpdateRowGroup(groupFields);
12798
12872
  nextTick(() => {
12799
- const { data, exportConfig, importConfig, treeConfig, showOverflow, highlightCurrentRow, highlightCurrentColumn } = props;
12873
+ const { data, exportConfig, importConfig, treeConfig, highlightCurrentRow, highlightCurrentColumn } = props;
12800
12874
  const { scrollXStore, scrollYStore } = internalData;
12801
12875
  const editOpts = computeEditOpts.value;
12802
12876
  const treeOpts = computeTreeOpts.value;
@@ -12828,9 +12902,9 @@ export default defineVxeComponent({
12828
12902
  if (props.editConfig && (editOpts.showStatus || editOpts.showUpdateStatus || editOpts.showInsertStatus) && !props.keepSource) {
12829
12903
  warnLog('vxe.error.reqProp', ['keep-source']);
12830
12904
  }
12831
- if (treeConfig && (treeOpts.showLine || treeOpts.line) && !showOverflow) {
12832
- warnLog('vxe.error.reqProp', ['show-overflow']);
12833
- }
12905
+ // if (treeConfig && (treeOpts.showLine || treeOpts.line) && !showOverflow) {
12906
+ // warnLog('vxe.error.reqProp', ['show-overflow'])
12907
+ // }
12834
12908
  if (treeConfig && !treeOpts.transform && props.stripe) {
12835
12909
  warnLog('vxe.error.noTree', ['stripe']);
12836
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.3";
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.3"}`;
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);