From 045fc006725c014455def9fed19f93c781633d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Thu, 24 Sep 2026 18:36:03 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E5=85=A8=E9=AB=98?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=20hook=20=E4=B8=8E=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=BA=A2=E5=87=BA=E4=BA=92=E7=9B=B8=E5=8F=8D=E9=A6=88=20?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=20el-table=20=E6=BB=9A=E5=8A=A8=E6=9D=A1?= =?UTF-8?q?=E6=8A=BD=E6=90=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/table/useFullHeightTable.ts | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/hooks/table/useFullHeightTable.ts b/src/hooks/table/useFullHeightTable.ts index acb4f9f..b3957c1 100644 --- a/src/hooks/table/useFullHeightTable.ts +++ b/src/hooks/table/useFullHeightTable.ts @@ -18,6 +18,7 @@ interface TableState { bodyMaxHeight: string; bodyOverflowY: string; bodyOverflowX: string; + appliedHeight?: number; } const tableStates = new WeakMap(); @@ -70,11 +71,6 @@ const getTableComponent = (table: HTMLElement) => { return getTableComponentHost(table)?.proxy; }; -const getPageOverflowHeight = () => { - const documentElement = document.documentElement; - return Math.max(0, documentElement.scrollHeight - documentElement.clientHeight); -}; - const rememberTableState = (table: HTMLElement) => { if (tableStates.has(table)) return; @@ -112,14 +108,22 @@ const resetAllTables = () => { }; const calculateTableHeight = (table: HTMLElement) => { - const rect = table.getBoundingClientRect(); + let layoutTop = 0; + let node: HTMLElement | null = table; + while (node) { + layoutTop += node.offsetTop; + node = node.offsetParent as HTMLElement | null; + } + + // Keep the calculation tied to the page layout. Using the current scroll + // position here would make scrolling change the table height again. const viewportBottom = window.innerHeight; const followingHeight = getFollowingHeight(table); const bottomPadding = getBottomPadding(table); const bottomOffset = window.innerWidth < 768 ? 28 : 32; const minHeight = window.innerWidth < 768 ? 220 : 260; - return Math.max(minHeight, Math.floor(viewportBottom - rect.top - followingHeight - bottomPadding - bottomOffset)); + return Math.max(minHeight, Math.floor(viewportBottom - layoutTop - followingHeight - bottomPadding - bottomOffset)); }; const applyTableHeightValue = (table: HTMLElement, tableHeight: number) => { @@ -153,14 +157,11 @@ const applyTableHeightValue = (table: HTMLElement, tableHeight: number) => { const applyTableHeight = (table: HTMLElement) => { rememberTableState(table); - const minHeight = window.innerWidth < 768 ? 220 : 260; const tableHeight = calculateTableHeight(table); + const state = tableStates.get(table); + if (state?.appliedHeight === tableHeight) return; + if (state) state.appliedHeight = tableHeight; applyTableHeightValue(table, tableHeight); - - const overflowHeight = getPageOverflowHeight(); - if (overflowHeight > 0 && tableHeight > minHeight) { - applyTableHeightValue(table, Math.max(minHeight, tableHeight - overflowHeight - 4)); - } }; const canManageTable = (table: HTMLElement) => { @@ -195,7 +196,6 @@ export function useFullHeightTable() { const nextElements = new Set([ ...Array.from(document.querySelectorAll('.app-main, .app-main .p-2, .app-main .table-panel')), ...Array.from(document.querySelectorAll('.app-main .search-panel, .app-main .tree-panel-shell')), - ...getManagedTables() ]); observedElements.forEach(element => {