From 1fdd09130c23ac3fabebe87788d774fc9152a182 Mon Sep 17 00:00:00 2001 From: Bran <1055025755@qq.com> Date: Fri, 26 May 2023 17:59:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=98=8E=E7=BB=86=E8=A1=A8):=20=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E8=A1=A8=E5=88=97=E5=A4=B4=E9=AB=98=E5=BA=A6=E9=97=AE?= =?UTF-8?q?=E9=A2=98,=20=E5=8F=AA=E6=A0=B9=E6=8D=AE=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E5=88=97=E5=8D=95=E5=85=83=E6=A0=BC=E8=AE=A1=E7=AE=97(?= =?UTF-8?q?=E5=BF=BD=E7=95=A5=E5=BA=8F=E5=8F=B7=E5=88=97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/facet/table-facet.ts | 60 ++++++----------------- 1 file changed, 16 insertions(+), 44 deletions(-) diff --git a/packages/s2-core/src/facet/table-facet.ts b/packages/s2-core/src/facet/table-facet.ts index 04a36ea9ce..1985b9ccbc 100644 --- a/packages/s2-core/src/facet/table-facet.ts +++ b/packages/s2-core/src/facet/table-facet.ts @@ -369,39 +369,16 @@ export class TableFacet extends BaseFacet { return totalHeight; } - /** 判断 columns 中是否配置了 rowSpan */ - private isRowSpanConfiged(columns: Columns) { - return columns.some((item) => { - if (isString(item)) { - return false; - } - if (item.rowSpan) { - return true; - } - if (item.children?.length) { - const res = this.isRowSpanConfiged(item.children); - if (res) { - return true; - } - } - return false; - }); - } - - private getTreeDepth(column: string | ColumnNode) { - if (!column) { - return 0; + private getKeysOfFirstColumn(columns: Columns) { + let res = []; + const key = isString(columns?.[0]) ? columns?.[0] : columns?.[0]?.key; + if (key) { + res = res.concat(key); } - let maxDepth = 0; - if (!isString(column)) { - column?.children?.slice(0, 1)?.forEach((child) => { - const depth = this.getTreeDepth(child); - if (depth > maxDepth) { - maxDepth = depth; - } - }); + if (!isString(columns?.[0]) && columns?.[0]?.children?.length) { + res = res.concat(this.getKeysOfFirstColumn(columns?.[0]?.children)); } - return maxDepth + 1; + return res; } private calculateColNodesCoordinate( @@ -412,20 +389,15 @@ export class TableFacet extends BaseFacet { let preLeafNode = Node.blankNode(); const allNodes = colsHierarchy.getNodes(); - // 一旦设置了 rowSpan 则只根据第一列行数计算列头高度, 避免出现空白行 - const isRowSpanConfiged = this.isRowSpanConfiged(columns); - const countLines = this.getTreeDepth(columns?.[0]); - let end = colsHierarchy.sampleNodesForAllLevels.length + 1; - if (isRowSpanConfiged) { - end = countLines; - } + const keys = this.getKeysOfFirstColumn(columns); - for (const levelSample of colsHierarchy.sampleNodesForAllLevels.slice( - 0, - end, - )) { - levelSample.height = this.getColNodeHeight(levelSample); - colsHierarchy.height += levelSample.height; + const nodesOfFirstColumn = allNodes.filter((node) => { + return keys.includes(node.field); + }); + + for (const nodeSample of nodesOfFirstColumn) { + nodeSample.height = this.getColNodeHeight(nodeSample); + colsHierarchy.height += nodeSample.height; } const adaptiveColWidth = this.getAdaptiveColWidth(colLeafNodes); let currentCollIndex = 0;