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

This commit is contained in:
zhanjunhao
2026-11-17 17:47:57 +08:00
parent 92380ebab6
commit dfa5c1edd6
28 changed files with 351 additions and 108 deletions
+1 -1
View File
@@ -230,7 +230,7 @@
margin-inline-start: auto;
}
.console-page .console-table .ant-table-thead > tr > th {
background: var(--console-fill);
--center-table-head-bg: var(--console-fill);
color: var(--console-muted);
font-weight: 500;
}
@@ -96,16 +96,6 @@
opacity: 0.65;
}
/* Sticky headers need an opaque surface below the translucent header tint. */
.console-page[data-console-page='models']
.console-table
.ant-table-thead
> tr
> th.ant-table-cell-fix-right {
background-color: var(--console-surface);
background-image: linear-gradient(var(--console-fill), var(--console-fill));
}
.models-vendor-actions {
display: flex;
flex-shrink: 0;
+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}
+14 -10
View File
@@ -3,30 +3,34 @@
max-width: 100%;
}
.center-action-table .ant-table-tbody > tr > .center-fixed-cell {
z-index: 2;
.center-action-table .ant-table-tbody > tr > .ant-table-cell-fix {
background: var(--center-table-bg);
background-clip: padding-box;
}
.center-action-table .ant-table-thead > tr > .center-fixed-cell {
z-index: 3;
background: var(--ur-head-bg, var(--center-table-head-bg));
.center-action-table .ant-table-thead > tr > .ant-table-cell {
/* Composite the header tint over an opaque surface, including sticky cells. */
background-color: var(--center-table-bg);
background-image: linear-gradient(
var(--center-table-head-bg),
var(--center-table-head-bg)
);
background-clip: padding-box;
white-space: nowrap;
}
.center-action-table .ant-table-tbody > tr:hover > .center-fixed-cell {
.center-action-table .ant-table-tbody > tr:hover > .ant-table-cell-fix {
background: var(--center-table-hover-bg);
}
.center-action-table
.ant-table-tbody
> tr.ant-table-row-selected
> .center-fixed-cell {
> .ant-table-cell-fix {
background: var(--center-table-selected-bg);
}
.center-action-table .center-fixed-cell {
.center-action-table .ant-table-tbody > tr > .center-fixed-cell {
white-space: normal;
overflow-wrap: anywhere;
}
@@ -50,6 +54,6 @@
.admin-tokens-row-actions,
.website-insights-row-actions
) {
flex-wrap: nowrap;
max-width: none;
flex-wrap: wrap;
max-width: 100%;
}
+26 -2
View File
@@ -89,11 +89,15 @@ const markFixedRight = (
index,
action = false,
measuredWidths = {},
containerWidth = 0,
) => ({
...column,
fixed: 'right',
width: action
? actionWidth(column, measuredWidths[index])
? Math.min(
actionWidth(column, measuredWidths[index]),
containerWidth > 0 ? Math.max(56, containerWidth) : Infinity,
)
: columnWidth(column),
...(action ? { title: i18next.t('操作') || '操作' } : {}),
className: [
@@ -110,6 +114,22 @@ export function prepareCenterColumns(columns, width = 0, measuredWidths = {}) {
const leaves = leafColumns(columns);
const last = leaves.at(-1);
const hasAction = last && isActionColumn(last);
const pinnedWidth = hasAction
? leaves.reduce(
(total, column, index) =>
total +
(column === last
? Math.min(
actionWidth(column, measuredWidths[index]),
width || Infinity,
)
: column.fixed
? columnWidth(column)
: 0),
0,
)
: 0;
const releaseOtherFixed = width > 0 && pinnedWidth > width;
const estimatedTotal = leaves.reduce(
(total, column) => total + columnWidth(column),
0,
@@ -125,8 +145,12 @@ export function prepareCenterColumns(columns, width = 0, measuredWidths = {}) {
return { ...column, children: column.children.map(mapColumn) };
const columnIndex = index++;
if (hasAction && column === last)
return markFixedRight(column, columnIndex, true, measuredWidths);
return markFixedRight(column, columnIndex, true, measuredWidths, width);
if (fallback.has(column)) return markFixedRight(column, columnIndex);
if (releaseOtherFixed && column.fixed) {
const { fixed: _fixed, ...scrollable } = column;
return scrollable;
}
if (column.fixed) return { ...column, width: columnWidth(column) };
return column;
});