Skip to content

Commit 1732371

Browse files
authored
Merge pull request #3793 from VisActor/fix/frozen-layout-border
Fix/frozen layout border
2 parents c24e75d + e59d758 commit 1732371

File tree

1 file changed

+51
-24
lines changed
  • packages/vtable/src/scenegraph/layout

1 file changed

+51
-24
lines changed

packages/vtable/src/scenegraph/layout/frozen.ts

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,11 @@ function moveRowFromBodyToColHeader(scene: Scenegraph) {
543543
let hasSetedHeight = false;
544544
// deal with bodyGroup
545545
for (let i = 0; i < scene.bodyGroup.childrenCount; i++) {
546-
const colGroup = scene.bodyGroup.children[i] as Group;
547-
const rowCell = colGroup.firstChild as Group;
546+
const child = scene.bodyGroup.children[i];
547+
if (!checkBeforeMove(child)) {
548+
continue;
549+
}
550+
const rowCell = child.firstChild as Group;
548551
scene.colHeaderGroup.children[i]?.appendChild(rowCell);
549552
// update container width
550553
if (!hasSetedHeight) {
@@ -559,8 +562,11 @@ function moveRowFromRowHeaderToCornerHeader(scene: Scenegraph) {
559562
let hasSetedHeight = false;
560563
// deal with rowHeaderGroup
561564
for (let i = 0; i < scene.rowHeaderGroup.childrenCount; i++) {
562-
const colGroup = scene.rowHeaderGroup.children[i] as Group;
563-
const rowCell = colGroup.firstChild as Group;
565+
const child = scene.rowHeaderGroup.children[i];
566+
if (!checkBeforeMove(child)) {
567+
continue;
568+
}
569+
const rowCell = child.firstChild as Group;
564570
scene.cornerHeaderGroup.children[i]?.appendChild(rowCell);
565571
// update container width
566572
if (!hasSetedHeight) {
@@ -578,8 +584,11 @@ function moveRowFromRightToTopRightCorner(scene: Scenegraph) {
578584
let hasSetedHeight = false;
579585
// deal with rowHeaderGroup
580586
for (let i = 0; i < scene.rightFrozenGroup.childrenCount; i++) {
581-
const colGroup = scene.rightFrozenGroup.children[i] as Group;
582-
const rowCell = colGroup.firstChild as Group;
587+
const child = scene.rightFrozenGroup.children[i];
588+
if (!checkBeforeMove(child)) {
589+
continue;
590+
}
591+
const rowCell = child.firstChild as Group;
583592
scene.rightTopCornerGroup.children[i]?.appendChild(rowCell);
584593
// update container width
585594
if (!hasSetedHeight) {
@@ -597,10 +606,17 @@ function moveRowFromColHeaderToBody(scene: Scenegraph) {
597606
let hasSetedHeight = false;
598607
// deal with bodyGroup
599608
for (let i = 0; i < scene.colHeaderGroup.childrenCount; i++) {
600-
const colGroup = scene.colHeaderGroup.children[i] as Group;
601-
const rowCell = colGroup.lastChild as Group;
602-
insertBefore(scene.bodyGroup.children[i] as Group, rowCell, scene.bodyGroup.children[i].firstChild as Group);
603-
// update container width
609+
const child = scene.colHeaderGroup.children[i];
610+
if (!checkBeforeMove(child)) {
611+
continue;
612+
}
613+
const target = scene.bodyGroup.children[i] as Group;
614+
if (!target) {
615+
continue;
616+
}
617+
const rowCell = child.lastChild as Group;
618+
insertBefore(target, rowCell, target.firstChild as Group);
619+
// 更新高度
604620
if (!hasSetedHeight) {
605621
scene.colHeaderGroup.setAttribute('height', scene.colHeaderGroup.attribute.height - rowCell.attribute.height);
606622
scene.bodyGroup.setAttribute('height', scene.bodyGroup.attribute.height + rowCell.attribute.height);
@@ -613,14 +629,17 @@ function moveRowFromCornerHeaderToRowHeader(scene: Scenegraph) {
613629
let hasSetedHeight = false;
614630
// deal with rowHeaderGroup
615631
for (let i = 0; i < scene.cornerHeaderGroup.childrenCount; i++) {
616-
const colGroup = scene.cornerHeaderGroup.children[i] as Group;
617-
const rowCell = colGroup.lastChild as Group;
632+
const child = scene.cornerHeaderGroup.children[i];
633+
if (!checkBeforeMove(child)) {
634+
continue;
635+
}
636+
const target = scene.rowHeaderGroup.children[i] as Group;
637+
if (!target) {
638+
continue;
639+
}
640+
const rowCell = child.lastChild as Group;
618641
// scene.rowHeaderGroup.children[i]?.appendChild(rowCell);
619-
insertBefore(
620-
scene.rowHeaderGroup.children[i] as Group,
621-
rowCell,
622-
scene.rowHeaderGroup.children[i].firstChild as Group
623-
);
642+
insertBefore(target, rowCell, target.firstChild as Group);
624643
// update container width
625644
if (!hasSetedHeight) {
626645
scene.cornerHeaderGroup.setAttribute(
@@ -637,14 +656,17 @@ function moveRowFromTopRightCornerToRight(scene: Scenegraph) {
637656
let hasSetedHeight = false;
638657
// deal with rowHeaderGroup
639658
for (let i = 0; i < scene.rightTopCornerGroup.childrenCount; i++) {
640-
const colGroup = scene.rightTopCornerGroup.children[i] as Group;
641-
const rowCell = colGroup.lastChild as Group;
659+
const child = scene.rightTopCornerGroup.children[i];
660+
if (!checkBeforeMove(child)) {
661+
continue;
662+
}
663+
const target = scene.rightFrozenGroup.children[i] as Group;
664+
if (!target) {
665+
continue;
666+
}
667+
const rowCell = child.lastChild as Group;
642668
// scene.rightFrozenGroup.children[i]?.appendChild(rowCell);
643-
insertBefore(
644-
scene.rightFrozenGroup.children[i] as Group,
645-
rowCell,
646-
scene.rightFrozenGroup.children[i].firstChild as Group
647-
);
669+
insertBefore(target, rowCell, target.firstChild as Group);
648670
// update container width
649671
if (!hasSetedHeight) {
650672
scene.rightTopCornerGroup.setAttribute(
@@ -656,3 +678,8 @@ function moveRowFromTopRightCornerToRight(scene: Scenegraph) {
656678
}
657679
}
658680
}
681+
682+
function checkBeforeMove(child: any) {
683+
// 跳过非 Group 类型或名为 'table-border-rect' 的边框节点
684+
return child instanceof Group && child?.name !== 'table-border-rect';
685+
}

0 commit comments

Comments
 (0)