index.tsx
1.46 KB
import { Table, type TableProps } from 'antd';
import { useScrollbarRemeasure } from '../../hooks/useScrollbarRemeasure';
import { resolveTableLoading } from './loading';
import { withImageCell } from './imageCell';
/**
* 项目统一表格。
*
* rootClassName 统一挂 uj:表头底色、行 hover、分隔线、分页贴底这些规则
* 都在 @uj/ui 的 styles/ui.css 里以 .uj-table 为作用域,页面不需要自己写。
* 组件的几何量仍然由 themeConfig 的 Table token 下发。
*
* scrollbarRemeasure:见 FillTable 同名字段注释 —— wujie 异步注入细滚动条规则可能晚于
* 首次挂载,强制表格在规则进入文档后重挂载一次,消除表头/表体错位。
*
* loading:统一交给 resolveTableLoading 注入品牌指示器,页面仍只传 boolean。
*/
export function UTable<T>(props: TableProps<T>) {
const { size = 'middle', rootClassName, loading, ...rest } = props;
const remeasureEpoch = useScrollbarRemeasure(true);
return (
<Table<T>
key={`uj-ut-${remeasureEpoch}`}
size={size}
rootClassName={['uj-table', rootClassName].filter(Boolean).join(' ')}
loading={resolveTableLoading(loading)}
{...rest}
// 图片单元格能力收口在表格底层:原始值是图片链接的列自动渲染成可点大图的
// cover 缩略图,所有消费方(含裸用 UTable 的页面)无需各自实现。
columns={withImageCell(rest.columns)}
/>
);
}