import ProTable, { ProTableProps } from '@ant-design/pro-table'; import { useState } from 'react'; export type ParamsType = Record; const DEFAULT_PAGESIZE = 10; export type { ProTableProps as BaseTableProps }; /** @name 表格组件(若有额外的功能,自行在该组件封装添加) */ export default function BaseTable< DataType extends Record, Params extends ParamsType = ParamsType, ValueType = 'text', >(props: ProTableProps): JSX.Element { const { request, pagination = {}, search, ...rest } = props; const [total, setTotal] = useState(0); const [loading, setLoading] = useState(false); return ( { setLoading(true); try { const res = await request?.(params, sort, filter); const { total } = res || {}; setTotal(total || 0); setLoading(false); return res || {}; } catch (error) { setLoading(false); return {}; } }, pagination: pagination ? { defaultPageSize: DEFAULT_PAGESIZE, showQuickJumper: total > DEFAULT_PAGESIZE, showSizeChanger: total > DEFAULT_PAGESIZE, hideOnSinglePage: total <= DEFAULT_PAGESIZE, ...pagination, } : false, }, }} /> ); } BaseTable.Summary = ProTable.Summary;