table-reuse
Version:
A reusable table built on top of Antd ProTable
49 lines (48 loc) • 2.12 kB
TypeScript
/// <reference types="react" />
import type { TClickAction } from "action-view";
import type { TRecord, ProColumns, TSorter, TParams } from "./proTableTypes";
import type { FilterData, FilterConfig } from "./filterConfigDataTypes";
/** 表格标签页配置(带过滤器) */
export interface TTabConfig<TFilterShape = TRecord> {
key: string;
label: React.ReactNode;
filter?: TFilterShape;
}
/** 表格组件 props */
export interface TTableProps<TItem extends TRecord, TFilterShape extends TRecord = TRecord, TTabFilterShape extends TRecord = TRecord, TApiVariableShape extends TRecord = TRecord, TSortShape = TSorter<TItem>, TResponseShape = {
data: TItem[];
total: number;
success?: boolean;
}, TRowAction = TClickAction> {
/** 表格唯一标识 key */
rowKey: string;
/** 可选标题 */
tableTitle?: string;
tableId?: string;
/** 表格列定义 */
columns: ProColumns<TItem>[];
/** 表格数据获取方法 */
onList: (params: TParams<TItem>, sort?: TSortShape, filter?: TFilterShape) => Promise<TResponseShape>;
/** ProComponent 风格的表单过滤器(支持多种控件) */
filters?: FilterData[];
/** 顶部搜索输入的额外配置 */
searchConfig?: FilterConfig["submitRenderer"];
/** 标签页配置(支持过滤) */
tabs?: TTabConfig<TTabFilterShape>[];
/** 默认选中的标签页 key */
defaultTabKey?: string;
/** 表格右上角按钮 */
pageActions?: TRowAction[];
/** 每行右侧操作按钮生成器 */
buildRowActions?: (record: TItem) => TRowAction[];
/** 将请求参数转换为 API 实际 payload */
buildApiPayload?: (filter: TFilterShape) => TApiVariableShape;
/** 用于处理 API 响应 */
buildResponse?: (res: unknown) => TResponseShape;
/** 最大显示几个行操作按钮,其他合并为下拉 */
maxVisibleRowActions?: number;
/** 自动轮询刷新间隔(毫秒) */
pullInterval?: number;
/** 数据变化是否自动刷新 */
reloadOnDataChange?: boolean;
}