UNPKG

tea-material-pro-table

Version:

Tea ProTable

449 lines (448 loc) 10.5 kB
import { MutableRefObject, ReactNode } from 'react'; import type { ButtonProps, SearchBoxProps, TagSearchBoxProps, BubbleProps, TableProps } from 'tea-component'; import { ProFormProps, Form } from 'tea-material-pro-form'; import { AutoTipOptions, ColumnsDraggableOptions, ColumnsResizableOptions, DraggableOptions, ExpandableAddonOptions, GroupableOptions, InjectableOptions, MergeableOptions, MultipleFilterableConfig, PageableOptions, RadioableOptions, RemoveableOptions, RowsDraggableOptions, RowTooltipAddonOption, ScrollableAddonOptions, SelectableOptions, SingleFilterableConfig, SortableOptions } from 'tea-component/lib/table/addons'; export * from 'tea-material-pro-form'; export declare type FormRef = Form; /** * ProTable Columns 除支持 Tea Table 和 proform 的基本配置外,还支持以下配置 */ export declare type Column = { /** * 隐藏此表单 */ hideForm?: boolean; /** * form align */ formAlign?: 'auto' | 'top' | 'middle'; [propName: string]: any; }; export interface PageParams { pageSize: number; current: number; pageIndex: number; } export interface ProTableProps<Params = any, Record = any> extends Omit<TableProps, 'addons' | 'columns'> { /** * 用于获取数据 * * 第一个参数 params 是查询表单和 params 参数的结合 * * 第一个参数中一定会有 pageSize 和 current, 分页使用 * * `0.0.2`版本加入 pageIndex 返回参数,等同于 current */ request?: (params: PageParams & Params) => Promise<{ data: Record[]; success: boolean; total: number; }>; /** * 数据加载成功时触发 */ onRequestSuccess?: (currentParams: PageParams & Params) => void; /** * 获取数据的额外参数,值改变就会触发一次加载 */ params?: Params; /** * 表格数据, 对于插件需要用到;普通场景 protable 推荐使用 request 加载数据 */ records?: Record[]; /** * 列表头操作工具栏配置 */ operations?: Operation[]; /** * 是否显示分页 * @default false */ pageable?: boolean; /** * 分页选项 * @default PageableOptions */ pageableOptions?: Omit<PageableOptions, 'pageIndex' | 'recordCount' | 'onPagingChange'>; /** * 是否显示查询表单,参数同 ProForm * @default false */ searchable?: Partial<ProFormProps>; /** * 数据加载失败时触发 */ onRequestError?: (error: any) => void; /** * 插件配置 */ addons?: Addon[]; /** * 外部传入插件和内部插件合并的位置 * @default after * @version 1.0.0 */ externalPluginsPosition?: 'before' | 'after'; /** * ProTable action 的引用,用于手动刷新或重置操作 */ actionRef?: MutableRefObject<ActionType | ActionType<Params, Record> | undefined>; /** * 自定义 Layout * @default false * @version 0.0.2 */ customLayout?: boolean; /** * 搜索表单的引用 * * @verion 0.0.3 */ formRef?: MutableRefObject<FormRef | undefined>; } /** * 有时我们要手动触发 table 的 reload 等操作,可以使用 actionRef。 */ export interface ActionType<Params = any, Record = any> { /** * 刷新 */ reload: () => void; /** * 刷新并清空,页码也会重置,不包括表单 */ reloadAndReset: () => void; /** * 重置到默认值,包括表单 */ reset: () => void; /** * 获取表格的参数 */ getParams: () => PageParams & Params; /** * 更新表格某一行的数据 */ updateDataSourceRecord: (nextData: Partial<Record>, isRecord: (d: Record) => boolean) => void; /** * 更新表格数据源 */ updateDataSource: (nextDataSource: Array<Partial<Record>>) => void; } export declare type Operation = DefaultOperation | CustomOperation; export declare type DefaultOperation = ButtonOperation | SearchBoxOperation | TagSearchBoxOperation | RefreshOperation | SettingOperation | DownloadOperation; /** * 自定义操作项 */ export interface CustomOperation { /** * 自定义元素 */ render: () => ReactNode; /** * 元素位置, 不传根据前一个元素位置决定 */ align?: OperationAlign; } export declare type OperationAlign = 'left' | 'right'; /** * 按钮操作 * 参数同 Tea Button * `规范中显示在左侧` */ export interface ButtonOperation extends Omit<ButtonProps, 'type'> { /** * 元素类型 */ type: 'button'; /** * 元素位置 * @default left */ align?: OperationAlign; /** * 按钮类型,同 Tea Button type 参数 */ buttonType?: ButtonProps['type']; /** * 按钮文案 */ text?: string; /** * 按钮气泡, 参数同 Tea Bubble */ bubble?: BubbleProps; } /** * 关键词搜索 * 参数同 Tea SearchBox * `规范中显示在右侧` */ export interface SearchBoxOperation extends SearchBoxProps { /** * 元素类型 */ type: 'searchbox'; /** * 元素位置 * @default right */ align?: OperationAlign; } /** * 标签搜索 * 参数同 Tea TagSearchBox * `规范中显示在右侧` */ export interface TagSearchBoxOperation extends TagSearchBoxProps { /** * 元素类型 */ type: 'tagSearchbox'; /** * 元素位置 * @default right */ align?: OperationAlign; /** * 搜索输入框的宽度 * @default 600 */ width?: number; } /** * 刷新按钮 * 参数同 Tea Button * `规范中显示在搜索右侧` */ export interface RefreshOperation extends Omit<ButtonProps, 'type'> { /** * 元素类型 */ type: 'refresh'; /** * 元素位置 * @default right */ align?: OperationAlign; /** * 默认点击会刷新,可以关闭后自定义 * @default true */ defaultRefresh?: boolean; /** * 点击后的回调 */ onClick?: () => void; } /** * 设置按钮 * 参数同 Tea Button * `规范中显示在搜索右侧` */ export interface SettingOperation extends Omit<ButtonProps, 'type'> { /** * 元素类型 */ type: 'setting'; /** * 元素位置 * @default right */ align?: OperationAlign; /** * 点击后的回调 */ onClick?: () => void; } /** * 下载按钮 * 参数同 Tea Button * `规范中显示在搜索右侧` */ export interface DownloadOperation extends Omit<ButtonProps, 'type'> { /** * 元素类型 */ type: 'download'; /** * 元素位置 * @default right */ align?: OperationAlign; /** * 点击后的回调 */ onClick?: () => void; } export declare type Addon = AutoTipAddon | SortableAddon | SingleFilterableAddon | MultipleFilterableAddon | ExpandableAddon | RadioableAddon | SelectableAddon | RemoveableAddon | ScrollableAddon | MergeableAddon | GroupableAddon | DraggableAddon | RowsDraggableAddon | ColumnsDraggableAddon | ColumnsResizableAddon | RowTooltipAddon | InjectableAddon; /** * 自动提示 * 其他参数同 Tea Table 插件 */ export interface AutoTipAddon extends AutoTipOptions { /** * 插件类型 */ type: 'autotip'; } /** * 排序 * 其他参数同 Tea Table 插件 */ export interface SortableAddon extends SortableOptions { /** * 插件类型 */ type: 'sortable'; } /** * 单选过滤 * 其他参数同 Tea Table 插件 */ export interface SingleFilterableAddon extends Omit<SingleFilterableConfig, 'type'> { /** * 插件类型 */ type: 'singleFilterable'; } /** * 多选过滤 * 其他参数同 Tea Table 插件 */ export interface MultipleFilterableAddon extends Omit<MultipleFilterableConfig, 'type'> { /** * 插件类型 */ type: 'multipleFilterable'; } /** * 行展开 * 其他参数同 Tea Table 插件 */ export interface ExpandableAddon extends ExpandableAddonOptions { /** * 插件类型 */ type: 'expandable'; } /** * 单选 * 其他参数同 Tea Table 插件 */ export interface RadioableAddon extends RadioableOptions { /** * 插件类型 */ type: 'radioable'; } /** * 多选 * 其他参数同 Tea Table 插件 */ export interface SelectableAddon extends SelectableOptions { /** * 插件类型 */ type: 'selectable'; } /** * 移除 * 其他参数同 Tea Table 插件 */ export interface RemoveableAddon extends RemoveableOptions { /** * 插件类型 */ type: 'removeable'; } /** * 滚动 * 其他参数同 Tea Table 插件 */ export interface ScrollableAddon extends ScrollableAddonOptions { /** * 插件类型 */ type: 'scrollable'; } /** * 行/列合并 * 其他参数同 Tea Table 插件 */ export interface MergeableAddon extends MergeableOptions { /** * 插件类型 */ type: 'mergeable'; } /** * 行/列合并 * 其他参数同 Tea Table 插件 */ export interface GroupableAddon extends GroupableOptions { /** * 插件类型 */ type: 'groupable'; } /** * 内置拖拽 * 其他参数同 Tea Table 插件 */ export interface DraggableAddon extends DraggableOptions { /** * 插件类型 */ type: 'draggable'; } /** * 多层级树状拖拽 * 其他参数同 Tea Table 插件 */ export interface RowsDraggableAddon extends RowsDraggableOptions { /** * 插件类型 */ type: 'rowsDraggable'; } /** * 列拖拽排序 * 其他参数同 Tea Table 插件 */ export interface ColumnsDraggableAddon extends ColumnsDraggableOptions { /** * 插件类型 */ type: 'columnsDraggable'; } /** * 列宽度调整 * 其他参数同 Tea Table 插件 */ export interface ColumnsResizableAddon extends ColumnsResizableOptions { /** * 插件类型 */ type: 'columnsResizable'; } /** * 行提示 * 其他参数同 Tea Table 插件 */ export interface RowTooltipAddon extends RowTooltipAddonOption { /** * 插件类型 */ type: 'rowtooltip'; } /** * props 注入 * 其他参数同 Tea Table 插件 */ export interface InjectableAddon extends InjectableOptions { /** * 插件类型 */ type: 'injectable'; }