fix: when collapse tree node occor error #2600

This commit is contained in:
fangsmile 2024-10-20 21:56:11 +08:00
parent 5d996f6a09
commit be0e27ddf3
6 changed files with 50 additions and 24 deletions

View File

@ -893,22 +893,22 @@ export class ListTable extends BaseTable implements ListTableAPI {
this.internalProps.useOneRowHeightFillAll = false;
// this.scenegraph.updateHierarchyIcon(col, row);// 添加了updateCells:[{ col, row }] 就不需要单独更新图标了(只更新图标针对有自定义元素的情况 会有更新不到问题)'
const updateCells = [{ col, row }];
// // 如果需要移出的节点超过了当前加载部分最后一行 则转变成更新对应的行
// if (
// diffPositions.removeCellPositions?.length > 0 &&
// diffPositions.removeCellPositions[diffPositions.removeCellPositions.length - 1].row >=
// this.scenegraph.proxy.rowEnd
// ) {
// for (let i = 0; i <= diffPositions.removeCellPositions.length - 1; i++) {
// if (diffPositions.removeCellPositions[i].row <= this.scenegraph.proxy.rowEnd) {
// updateCells.push({
// col: diffPositions.removeCellPositions[i].col,
// row: diffPositions.removeCellPositions[i].row
// });
// }
// }
// diffPositions.removeCellPositions = [];
// }
// 如果需要移出的节点超过了当前加载部分最后一行 则转变成更新对应的行
if (
diffPositions.removeCellPositions?.length > 0 &&
diffPositions.removeCellPositions[diffPositions.removeCellPositions.length - 1].row >=
this.scenegraph.proxy.rowEnd
) {
for (let i = 0; i <= diffPositions.removeCellPositions.length - 1; i++) {
if (diffPositions.removeCellPositions[i].row <= this.scenegraph.proxy.rowEnd) {
updateCells.push({
col: diffPositions.removeCellPositions[i].col,
row: diffPositions.removeCellPositions[i].row
});
}
}
diffPositions.removeCellPositions = [];
}
this.scenegraph.updateRow(diffPositions.removeCellPositions, diffPositions.addCellPositions, updateCells);
if (checkHasChart) {
// 检查更新节点状态后总宽高未撑满autoFill是否在起作用

View File

@ -2553,7 +2553,11 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
* @returns
*/
getTargetRowAt(absoluteY: number): RowInfo | null {
return getTargetRowAt(absoluteY, this);
const targetRow = getTargetRowAt(absoluteY, this);
if (targetRow) {
targetRow.row = Math.min(targetRow.row, this.rowCount - 1);
}
return targetRow;
}
/**

View File

@ -215,7 +215,7 @@ function updateColGroupContentAsync(colGroup: Group, proxy: SceneProxy) {
}
const screenTopRow = proxy.screenTopRow;
const topRow = Math.max(proxy.bodyTopRow, screenTopRow - proxy.screenRowCount * 1);
const bottomRow = Math.min(proxy.bodyBottomRow, screenTopRow + proxy.screenRowCount * 2);
const bottomRow = Math.min(proxy.bodyBottomRow, screenTopRow + proxy.screenRowCount * 2, proxy.table.rowCount - 1);
for (let row = topRow; row <= bottomRow; row++) {
// const cellGroup = proxy.table.scenegraph.getCell(col, row);

View File

@ -91,7 +91,11 @@ async function moveCell(
syncBottomRow = distEndRow;
} else {
const topRow = Math.max(proxy.bodyTopRow, screenTopRow - proxy.screenRowCount * 1);
const bottomRow = Math.min(proxy.bodyBottomRow, screenTopRow + proxy.screenRowCount * 2);
const bottomRow = Math.min(
proxy.bodyBottomRow,
screenTopRow + proxy.screenRowCount * 2,
proxy.table.rowCount - 1
);
// get coincide of distStartRow&distEndRow and topRow&BottomRow
// syncTopRow = Math.max(distStartRow, topRow);
// syncBottomRow = Math.min(distEndRow, bottomRow);
@ -162,7 +166,11 @@ async function moveCell(
proxy.currentRow = direction === 'up' ? proxy.currentRow + count : proxy.currentRow - count;
proxy.totalRow = Math.max(
0,
Math.min(proxy.bodyBottomRow, direction === 'up' ? proxy.totalRow + count : proxy.totalRow - count)
Math.min(
proxy.bodyBottomRow,
direction === 'up' ? proxy.totalRow + count : proxy.totalRow - count,
proxy.table.rowCount - 1
)
);
proxy.referenceRow = proxy.rowStart + Math.floor((proxy.rowEnd - proxy.rowStart) / 2);
// proxy.referenceRow = screenTopRow;
@ -178,7 +186,10 @@ async function moveCell(
await proxy.progress();
} else {
const distStartRow = direction === 'up' ? proxy.rowStart + count : proxy.rowStart - count;
const distEndRow = direction === 'up' ? proxy.rowEnd + count : proxy.rowEnd - count;
const distEndRow = Math.min(
proxy.table.rowCount - 1,
direction === 'up' ? proxy.rowEnd + count : proxy.rowEnd - count
);
const distStartRowY = proxy.table.getRowsHeight(proxy.bodyTopRow, distStartRow - 1);
let syncTopRow;
@ -188,7 +199,7 @@ async function moveCell(
syncBottomRow = distEndRow;
} else {
syncTopRow = Math.max(proxy.bodyTopRow, screenTopRow - proxy.screenRowCount * 1);
syncBottomRow = Math.min(proxy.bodyBottomRow, screenTopRow + proxy.screenRowCount * 2);
syncBottomRow = Math.min(proxy.bodyBottomRow, screenTopRow + proxy.screenRowCount * 2, proxy.table.rowCount - 1);
}
computeRowsHeight(proxy.table, syncTopRow, syncBottomRow, false);
@ -256,7 +267,11 @@ async function moveCell(
proxy.currentRow = direction === 'up' ? proxy.currentRow + count : proxy.currentRow - count;
proxy.totalRow = Math.max(
0,
Math.min(proxy.bodyBottomRow, direction === 'up' ? proxy.totalRow + count : proxy.totalRow - count)
Math.min(
proxy.bodyBottomRow,
direction === 'up' ? proxy.totalRow + count : proxy.totalRow - count,
proxy.table.rowCount - 1
)
);
proxy.referenceRow = proxy.rowStart + Math.floor((proxy.rowEnd - proxy.rowStart) / 2);
// proxy.referenceRow = screenTopRow;

View File

@ -23,7 +23,11 @@ export async function sortVertical(proxy: SceneProxy) {
syncBottomRow = proxy.rowEnd;
} else {
syncTopRow = Math.max(proxy.bodyTopRow, proxy.screenTopRow - proxy.screenRowCount * 1);
syncBottomRow = Math.min(proxy.bodyBottomRow, proxy.screenTopRow + proxy.screenRowCount * 2);
syncBottomRow = Math.min(
proxy.bodyBottomRow,
proxy.screenTopRow + proxy.screenRowCount * 2,
proxy.table.rowCount - 1
);
}
// console.log('sort更新同步范围', syncTopRow, syncBottomRow);

View File

@ -1948,6 +1948,9 @@ export class Scenegraph {
) {
this.table.scenegraph.recalculateRowHeights();
} else if (this.table.heightMode === 'autoHeight') {
if (updateCells.length > 0) {
this.table.scenegraph.recalculateRowHeights();
}
for (let i = 0; i < updateRows.length; i++) {
const row = updateRows[i];
const oldHeight = this.table.getRowHeight(row);