fix(ui): 修复固定列表头并优化官网指标配置

This commit is contained in:
zhanjunhao
2026-11-17 17:47:57 +08:00
parent d878f0db21
commit 737c353d84
28 changed files with 351 additions and 108 deletions
+28 -22
View File
@@ -68,29 +68,34 @@ const CenterTable = forwardRef(function CenterTable(
const cells = [...root.querySelectorAll(`td.${marker}`)].filter(
(element) => element.getBoundingClientRect().width > 0,
);
const cell = cells.find((candidate) =>
candidate.querySelector('button, a, [role="button"]'),
);
const controls = cell
? [...cell.querySelectorAll('button, a, [role="button"]')].filter(
(element) => element.getBoundingClientRect().width > 0,
)
: [];
const cellStyle = getComputedStyle(cell || header);
const padding =
(Number.parseFloat(cellStyle.paddingLeft) || 0) +
(Number.parseFloat(cellStyle.paddingRight) || 0);
const gap = Number.parseFloat(cellStyle.columnGap) || 8;
const contentWidth = controls.length
? controls.reduce(
const widths = cells.map((cell) => {
const controls = [
...cell.querySelectorAll('button, a, [role="button"]'),
].filter((element) => element.getBoundingClientRect().width > 0);
if (!controls.length) return 0;
let group = controls[0].parentElement;
while (
group !== cell &&
!controls.every((control) => group.contains(control))
)
group = group.parentElement;
const cellStyle = getComputedStyle(cell);
const padding =
(Number.parseFloat(cellStyle.paddingLeft) || 0) +
(Number.parseFloat(cellStyle.paddingRight) || 0);
const gap = Number.parseFloat(getComputedStyle(group).columnGap) || 8;
return (
controls.reduce(
(total, element) => total + element.getBoundingClientRect().width,
0,
) +
gap * Math.max(0, controls.length - 1)
: Math.max(...cells.map((candidate) => candidate.scrollWidth), 0) -
padding;
next[marker.replace('center-fixed-index-', '')] =
contentWidth + padding;
gap * Math.max(0, controls.length - 1) +
padding
);
});
const measured = Math.max(...widths, 0);
if (measured > 0)
next[marker.replace('center-fixed-index-', '')] = measured;
});
setMeasuredActionWidths((current) => {
const same =
@@ -101,15 +106,16 @@ const CenterTable = forwardRef(function CenterTable(
return same ? current : next;
});
};
requestAnimationFrame(measureActionWidths);
const frame = requestAnimationFrame(measureActionWidths);
const observer = new ResizeObserver(update);
observer.observe(root);
return () => {
observer.disconnect();
cancelAnimationFrame(frame);
if (scroller && previousTabIndex === null)
scroller.removeAttribute('tabindex');
};
}, [enabled, width]);
}, [enabled, width, columns, props.dataSource]);
return (
<Table
{...props}