style(frontend): 全项目表格统一百分比布局并居中
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { Table as AntTable } from 'antd'
|
||||
import type { TableProps } from 'antd'
|
||||
|
||||
import { normalizePercentColumns } from '@/utils/percent-table-layout'
|
||||
|
||||
/**
|
||||
* 全项目统一表格:列宽转百分比、表头与内容居中。
|
||||
*
|
||||
* 业务表格仍按原列宽数值表达相对比例,由这里统一归一化为 100%。
|
||||
* rowSelection / expandable 会额外占用 AntD 内置列,因此预留少量百分比。
|
||||
*/
|
||||
export default function PercentTable<RecordType extends object = Record<string, unknown>>(
|
||||
props: TableProps<RecordType>,
|
||||
) {
|
||||
const { columns, scroll, tableLayout: _tableLayout, ...rest } = props
|
||||
const reservedPercent =
|
||||
(props.rowSelection ? 4 : 0) +
|
||||
(props.expandable && typeof props.expandable === 'object' ? 4 : 0)
|
||||
const normalizedColumns = columns
|
||||
? normalizePercentColumns(columns, { reservedPercent })
|
||||
: columns
|
||||
const scrollConfig = typeof scroll === 'object' && scroll ? scroll : {}
|
||||
|
||||
return (
|
||||
<AntTable<RecordType>
|
||||
{...rest}
|
||||
columns={normalizedColumns}
|
||||
tableLayout="fixed"
|
||||
scroll={{ ...scrollConfig, x: '100%' }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user