/// import { ColumnProps, TableProps } from 'antd/lib/table'; import { TableRowSelection } from 'antd/lib/table/interface'; import { IObject } from '../../util'; export interface IBaseApi { setReadOnly: (readonly?: boolean) => void; on: (event: string, callback: (...args: any[]) => void, once?: boolean) => void; } export interface ITableProps extends TableProps { /** * @description 业务主键,多个用英文逗号分隔 */ busKey?: string; /** * @description 唯一主键字段,不配置则自动使用Symbol变量 */ keyField?: string; /** * @description 业务字段,用于返回数据行时字段过滤(默认返回全部字段) */ busFields?: Array; /** * @description 配置固定数据源 */ dataSource?: object[]; /** * @description 原始值 */ rawData?: object[]; /** * @description 已选行的主键数组 */ selectedRowKeys?: React.Key[]; tableName?: string; /** * @description 单元格数据水平方向位置 */ align?: 'left' | 'center' | 'right'; /** * @description 数据源请求,支持返回promise对象 */ request?: (params: any, table: any) => Promise; /** * @description 拦截请求数据,处理以后返回 */ response?: (res: any) => { total?: number; record: Array; }; /** * @description 是个对象就能选择,undefined则不能选择 */ rowSelection?: TableRowSelection; /** * @description 是否可编辑 */ disabled?: Boolean; /** * @description 请求数据返回后 */ onDataLoad?: (...args: any[]) => void; /** * @description 空白页,添加的额外方法 */ emptyFunc?: () => React.ReactNode; /** * @description 设置行属性(例如:onClick、onDoubleClick等react事件) */ onRow?: (record: any, index: any) => IObject; /** * @description 是否加载中 * @default false */ loading?: false; } export interface IColumnProps extends ColumnProps { /** * @description 列标题 */ title?: string; /** * @description 列标题,支持自定义表头单元格 */ header?: (({ title, dataIndex, column, table }: { title: any; dataIndex: any; column: any; table: any; }) => React.ReactNode) | String; /** * @description 数据源的字段(必须且唯一,dataIndexField存在时仅作为key使用) */ dataIndex?: string; /** * @description 数据源的字段(可重复,优先级比dataIndex高) */ dataIndexField?: string | string[]; /** * @description 数据类型 */ valueType?: any; /** * @description 编辑列属性配置 */ editor?: Boolean; /** * @description 单元格渲染函数 */ render?: ({ table, row, value, dataIndex, rowIndex, pageIndex, pageSize }: { table: any; row: any; value: any; dataIndex: any; rowIndex: any; pageIndex: any; pageSize: any; }) => React.ReactNode; /** * @description 格式化显示内容,不改变数据源值($D:所有行、$R:当前行、$V:当前单元格、$DI:dataIndex) */ format?: any; /** * @description 为true,则列表隐藏 * @default false */ listHidden?: boolean; /** * @description 为true,则编辑时隐藏 * @default false */ formHidden?: boolean; } export interface TableInstance extends IBaseApi { /** * @description 订阅消息事件(暂时支持: 编辑前、编辑后、编辑状态的键盘事件) */ subscribe?: (fn: Function, type: 'updateRow' | 'onDataLoad') => void; /** * @description 获取行索引,参数为函数时类似于数组的findIndex */ getRowIndex?: (row: IObject | Function) => number; /** * @description 获取指定行的行数据 */ getRow?: (rowIndex: number) => object; /** * @description 根据主键value值获取行数据 */ getRowByKey?: (keyValue: any) => object; /** * @description 返回所有行数据 */ getRows?: () => Array; /** * @description 设置数据源, 参数dataSource为函数时当前数据源状态会作为参数传递,参数updateRaw表示是否更新原始数据(默认为true,影响行状态) */ setDataSource?: (dataSource: Array | Function) => void; /** * @description 更新行数据 */ updateRowDataByIndex?: (rowIndex: number, rowData: object) => void; /** * @description 增加行,默认从末尾新增,数组表示增加多行 */ addRows?: (rows?: Array | IObject, insertIndex?: number, callback?: (...args: any[]) => void) => void; /** * @description 删除行 */ deleteRows?: (rowIndexes: number[] | number) => void; /** * @description 删除多选选中的行(需要设置checkbox属性) */ deleteCheckedRows?: () => void; /** * @description 获取checkbox选中的行索引 */ getCheckedIndexes?: () => Array; /** * @description 若设置了checkbox属性,返回 getCheckedData,否则返回 [getSelectedRow()] */ getSelectedData?: () => Array; /** * @description 若设置了checkbox属性,设置行多选,否则选中单行 */ setSelected?: (rowIndexes: number[] | number, selected?: boolean) => void; /** * @description 重新发起request请求,覆盖之前的查询参数 */ query?: (params?: IObject | Function, callback?: any) => void; /** * @description 刷新数据源(重新发起请求) */ refreshData?: () => void; getStore?: () => any; } interface IResult

{ isChanged: boolean; table: P; } declare type NewDataType = { key: string; newRow: Array>; }; declare type ChangeDataType = NewDataType & { modifiedRow: Array>; deletedRow: Array>; }; export interface ITableInstance extends TableInstance { /** * @description 返回所有数据行,包含行状态 */ getAllData?: (ignoreUnChanged?: boolean) => IResult>; }>; /** * @description 返回更新的行 */ getChange?: (config: { initRows?: any[]; }) => IResult; } export {};