fix(ui): 修复固定列表头并优化官网指标配置
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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%;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user