fix(ui): 完善界面交互与开发配置
This commit is contained in:
@@ -17,7 +17,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { forwardRef, useLayoutEffect, useRef, useState } from 'react';
|
||||
import React, {
|
||||
forwardRef,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { Table, theme } from 'antd';
|
||||
import { colord } from 'colord';
|
||||
import { isCenterTableScope, prepareCenterColumns } from './centerTablePolicy';
|
||||
@@ -56,8 +62,21 @@ const CenterTable = forwardRef(function CenterTable(
|
||||
const scroller = root.querySelector('.ant-table-content,.ant-table-body');
|
||||
const previousTabIndex = scroller?.getAttribute('tabindex');
|
||||
if (scroller && previousTabIndex === null) scroller.tabIndex = 0;
|
||||
const update = () => setWidth(root.clientWidth);
|
||||
update();
|
||||
const observer = new ResizeObserver(([entry]) => {
|
||||
// ResizeObserver already measured the box; avoid a synchronous layout read.
|
||||
setWidth(entry.contentRect.width);
|
||||
});
|
||||
observer.observe(root);
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
if (scroller && previousTabIndex === null)
|
||||
scroller.removeAttribute('tabindex');
|
||||
};
|
||||
}, [enabled]);
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
const root = tableRef.current?.nativeElement;
|
||||
if (!root) return;
|
||||
const measureActionWidths = () => {
|
||||
const next = {};
|
||||
root.querySelectorAll('th.center-action-cell').forEach((header) => {
|
||||
@@ -69,9 +88,15 @@ const CenterTable = forwardRef(function CenterTable(
|
||||
(element) => element.getBoundingClientRect().width > 0,
|
||||
);
|
||||
const widths = cells.map((cell) => {
|
||||
const controls = [
|
||||
const controlsWithWidths = [
|
||||
...cell.querySelectorAll('button, a, [role="button"]'),
|
||||
].filter((element) => element.getBoundingClientRect().width > 0);
|
||||
]
|
||||
.map((element) => ({
|
||||
element,
|
||||
width: element.getBoundingClientRect().width,
|
||||
}))
|
||||
.filter(({ width }) => width > 0);
|
||||
const controls = controlsWithWidths.map(({ element }) => element);
|
||||
if (!controls.length) return 0;
|
||||
let group = controls[0].parentElement;
|
||||
while (
|
||||
@@ -85,10 +110,7 @@ const CenterTable = forwardRef(function CenterTable(
|
||||
(Number.parseFloat(cellStyle.paddingRight) || 0);
|
||||
const gap = Number.parseFloat(getComputedStyle(group).columnGap) || 8;
|
||||
return (
|
||||
controls.reduce(
|
||||
(total, element) => total + element.getBoundingClientRect().width,
|
||||
0,
|
||||
) +
|
||||
controlsWithWidths.reduce((total, { width }) => total + width, 0) +
|
||||
gap * Math.max(0, controls.length - 1) +
|
||||
padding
|
||||
);
|
||||
@@ -107,13 +129,8 @@ const CenterTable = forwardRef(function CenterTable(
|
||||
});
|
||||
};
|
||||
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, columns, props.dataSource]);
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user