UNPKG

@ccs-design/rc-pro

Version:

ccs design basic react component

151 lines (150 loc) 4.61 kB
import { TableProps } from 'antd/lib/table'; import { CSSProperties, ReactElement, ReactNode, ReactText, MutableRefObject } from 'react'; import { EventEmitter } from 'ahooks/lib/useEventEmitter'; import { Rule } from 'antd/lib/form'; export declare type ParamType = Record<string, any>; export declare type ItemType = FormItemType | FormItemType[]; export declare type ShowDependType = { name: string; value: any; }; export declare type SearchEventType = 'search' | 'reset' | 'reload' | 'changePage' | 'initSearch'; export interface FormItemType { /** label 标题 */ label?: string; /** form name */ name: string; /** form item element */ value: ReactElement; /** 数据依赖、依赖项对应的name数组 */ depends?: string[]; showDepends?: ShowDependType[]; rules?: Rule[]; onFormat?: (e: any) => any; } export interface CcsProTableProps<T> extends TableProps<T> { data?: TableDataType<T>; /** request 方法 */ request?: Function; /** request 额外参数 */ requestParam?: ParamType; /** 自定义渲染内容 */ render?: (data: T[]) => ReactNode; /** 异步树、父级参数名称 */ asyncTree?: { parentName: string; }; /** class name */ className?: string; /** 是否固定表头 */ fixedThead?: boolean | { theadHeight?: number; tbody?: boolean; }; /** useEventEmitter事件 */ event$?: any; style?: CSSProperties; } interface SearchBeforeType extends ParamType { query: ParamType; } export interface CcsProTableType<T> { /** api权限标识 */ auth?: string | 'ignore'; /** 标题 */ title?: string; /** 是否初始查询,默认true */ init?: boolean; /** loading */ loading?: boolean; /** 精简模式、适用于弹出框中使用、默认false */ isSimple?: boolean; /** 查询条件集合 */ formItems?: ItemType[]; /** 执行search 后回调函数 */ searchEvent?: Function; /** 查询form 初始值 */ formInitValues?: ParamType; /** 按钮 操作部分 */ toolbar?: ReactElement; /** table 头部 */ tableHeader?: ReactNode; /** table 数据区域 */ table?: CcsProTableProps<T>; /** table style */ tableStyle?: CSSProperties; /** 水印文字 */ watermark?: string; /** ref 回调方法 */ proRef?: ProTableInstanceRef<T>; /** table 占满剩余空间、默认true */ fillSpace?: boolean; /** class */ className?: string; /** style */ style?: CSSProperties; /** children */ children?: ReactNode; /** 请求前格式化参数 */ onSearchBefore?: (params: SearchBeforeType, eventType?: SearchEventType) => SearchBeforeType; /** 请求后格式化结果 */ onSearchAfter?: (data: any, eventType?: SearchEventType) => any; } export declare type ProTableInstanceRef<T = any> = MutableRefObject<ProTableInstance<T> | undefined> | React.RefObject<ProTableInstance<T>>; export interface TableDataType<T> { /** loading */ loading?: boolean; /** 总条数 */ totalNum?: number; /** 单页记录数 */ pageSize?: number; /** 页码 */ pageNo?: number; /** Array List 数据 */ result?: T[]; } export interface ProTableInstance<T = any> { /** 获取form表单数据 */ formValues: Record<string, any>; /** 获取当前表单数据 */ data: TableDataType<T>; /** 查询数据,根据条件,从第一页开始显示 */ onSearch: () => void; /** 刷新数据、根据条件,当前页 */ onReload: () => void; /** 异步树、局部刷新方法 */ onPartialReload: (id: ReactText) => void; /** 重置数据,清空选择 */ onReset: () => void; /** 改变data 数据 */ onChangeData: React.Dispatch<React.SetStateAction<TableDataType<T>>>; } export declare type CcsProEventType = EventEmitter<{ key: 'formFilter' | 'columnFilter'; columnHiddenKeys?: string[]; subscriptions: any; }>; export interface HttpResult<T = any> { code: number; success: boolean; data: T; msg: string; } export interface PageType<T> { hasNext: boolean; totalNum: number; pageNo: number; pageSize: number; result: T[]; } export interface HttpPageResult<T = any> extends Omit<HttpResult<T>, 'data'> { data: PageType<T>; } export interface PageQueryType { pageNo?: number; pageSize?: number; query?: Record<string, any>; } export declare type AnyParamType = Record<string, any>; export declare type AnyParamsType = Record<string, any>[]; export {};