@fe6/water-pro
Version:
An enterprise-class UI design language and Vue-based implementation
328 lines (327 loc) • 10.3 kB
TypeScript
/** @format */
import type { VNodeChild } from 'vue';
import type { Options } from 'sortablejs';
import type { ColumnProps, TableRowSelection as ITableRowSelection } from '../../../table/interface';
import type { FormProps } from '../../../form';
import { VueNode } from '../../../_util/type';
import type { PaginationProps } from './pagination';
import { SortOrder } from './column';
import { ComponentType } from './component-type';
export interface TableCurrentDataSource<T = Recordable> {
currentDataSource: T[];
}
export interface TableRowSelection<T = any> extends ITableRowSelection {
/**
* Callback executed when selected rows change
* @type Function
*/
onChange?: (selectedRowKeys: string[] | number[], selectedRows: T[]) => any;
/**
* Callback executed when select/deselect one row
* @type FunctionT
*/
onSelect?: (record: T, selected: boolean, selectedRows: Object[], nativeEvent: Event) => any;
/**
* Callback executed when select/deselect all rows
* @type Function
*/
onSelectAll?: (selected: boolean, selectedRows: T[], changeRows: T[]) => any;
/**
* Callback executed when row selection is inverted
* @type Function
*/
onSelectInvert?: (selectedRows: string[] | number[]) => any;
}
export interface TableCustomRecord<T> {
record?: T;
index?: number;
}
export interface ExpandedRowRenderRecord<T> extends TableCustomRecord<T> {
indent?: number;
expanded?: boolean;
}
export interface TableCustomRecord<T = Recordable> {
record?: T;
index?: number;
}
export interface SorterResult {
column: ColumnProps;
order: SortOrder;
field: string;
columnKey: string;
}
export interface FetchParams {
searchInfo?: Recordable;
page?: number;
sortInfo?: Recordable;
filterInfo?: Recordable;
api?: (...arg: any[]) => Promise<any>;
params?: Recordable;
}
export interface GetColumnsParams {
ignoreIndex?: boolean;
ignoreAction?: boolean;
sort?: boolean;
}
export declare type SizeType = 'default' | 'middle' | 'small' | 'large';
export interface LocaleParams {
filterConfirm: string;
filterReset: string;
emptyText: string;
}
export interface TableActionType {
reload: (opt?: FetchParams) => Promise<void>;
getSelectRows: <T = Recordable>() => T[];
clearSelectedRowKeys: () => void;
getSelectRowKeys: () => string[] | number[];
deleteSelectRowByKey: (key: string) => void;
setPagination: (info: Partial<PaginationProps>) => void;
setTableData: <T = Recordable>(values: T[]) => void;
getColumns: (opt?: GetColumnsParams) => BasicColumn[];
setColumns: (columns: BasicColumn[] | string[]) => void;
getDataSource: <T = Recordable>() => T[];
setLoading: (loading: boolean) => void;
getLoading?: undefined | boolean;
setProps: (props: Partial<TableProProps>) => void;
redoHeight: () => void;
setSelectedRowKeys: (rowKeys: string[] | number[]) => void;
getPaginationRef: () => PaginationProps | boolean;
getSize: () => SizeType;
getRowSelection: () => TableRowSelection<Recordable>;
getCacheColumns: () => BasicColumn[];
emit?: EmitType;
updateTableData: (index: number, key: string, value: any) => Recordable;
setShowPagination: (show: boolean) => Promise<void>;
getShowPagination: () => boolean;
setCacheColumnsByField?: (dataIndex: string | undefined, value: BasicColumn) => void;
}
export interface FetchSetting {
pageField: string;
sizeField: string;
listField: string;
totalField: string;
}
export interface TableSetting {
reload?: boolean;
setting?: boolean;
}
export interface TableProProps<T = any> {
clickToRowSelect?: boolean;
isTreeTable?: boolean;
sortFn?: (sortInfo: SorterResult) => any;
filterFn?: (data: Partial<Recordable<string[]>>) => any;
inset?: boolean;
showTableSetting?: boolean;
tableSetting?: TableSetting;
striped?: boolean;
autoCreateKey?: boolean;
summaryFunc?: (...arg: any) => Recordable[];
summaryData?: Recordable[];
showSummary?: boolean;
api?: (...arg: any) => Promise<any>;
beforeFetch?: Fn;
afterFetch?: Fn;
handleSearchInfoFn?: Fn;
fetchSetting?: FetchSetting;
immediate?: boolean;
emptyDataIsShowTable?: boolean;
searchInfo?: Recordable;
useSearchForm?: boolean;
formConfig?: Partial<FormProps>;
columns: BasicColumn[];
cardable?: boolean;
cardTitle?: string;
showIndexColumn?: boolean;
indexColumnProps?: BasicColumn;
actionColumn?: BasicColumn;
ellipsis?: boolean;
draggable?: boolean;
canResize?: boolean;
resizeHeightOffset?: number;
clearSelectOnPageChange?: boolean;
rowKey?: string | ((record: Recordable) => string);
dataSource?: Recordable[];
titleHelpMessage?: string | string[];
maxHeight?: number;
bordered?: boolean;
pagination?: PaginationProps | boolean;
totalRender?: (total: number, range: [number, number]) => any;
loading?: boolean;
/**
* The column contains children to display
* @default 'children'
* @type string | string[]
* TODO
*/
childrenColumnName?: string | string[];
/**
* Override default table elements
* @type object
*/
/**
* Expand all rows initially
* @default false
* @type boolean
*/
defaultExpandAllRows?: boolean;
/**
* Initial expanded row keys
* @type string[]
*/
defaultExpandedRowKeys?: string[];
/**
* Current expanded row keys
* @type string[]
*/
expandedRowKeys?: string[];
/**
* Expanded container render for each row
* @type Function
*/
expandedRowRender?: (record?: ExpandedRowRenderRecord<T>) => VNodeChild | JSX.Element;
/**
* Customize row expand Icon.
* @type Function | VNodeChild
*/
expandIcon?: Function | VNodeChild | JSX.Element;
/**
* Whether to expand row by clicking anywhere in the whole row
* @default false
* @type boolean
*/
expandRowByClick?: boolean;
/**
* The index of `expandIcon` which column will be inserted when `expandIconAsCell` is false. default 0
*/
expandIconColumnIndex?: number;
/**
* Table footer renderer
* @type Function | VNodeChild
*/
footer?: Function | VNodeChild | JSX.Element;
/**
* Indent size in pixels of tree data
* @default 15
* @type number
*/
indentSize?: number;
dragOtions?: Options;
/**
* i18n text including filter, sort, empty text, etc
* @default { filterConfirm: 'Ok', filterReset: 'Reset', emptyText: 'No Data' }
* @type object
*/
/**
* Row's className
* @type Function
*/
rowClassName?: (record: TableCustomRecord<T>, index?: number) => string;
/**
* Row selection config
* @type object
*/
rowSelection?: TableRowSelection;
/**
* Set horizontal or vertical scrolling, can also be used to specify the width and height of the scroll area.
* It is recommended to set a number for x, if you want to set it to true,
* you need to add style .ant-table td { white-space: nowrap; }.
* @type object
*/
scroll?: {
x?: number | true;
y?: number;
};
/**
* Whether to show table header
* @default true
* @type boolean
*/
showHeader?: boolean;
/**
* Size of table
* @default 'default'
* @type string
*/
size?: SizeType;
/**
* Table title renderer
* @type Function | ScopedSlot
*/
title?: VNodeChild | JSX.Element | string | ((data: Recordable) => string);
/**
* Set props on per header row
* @type Function
*/
/**
* Set props on per row
* @type Function
*/
customRow?: (record: T, index: number) => object;
/**
* `table-layout` attribute of table element
* `fixed` when header/columns are fixed, or using `column.ellipsis`
*
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout
* @version 1.5.0
*/
tableLayout?: 'auto' | 'fixed' | string;
/**
* the render container of dropdowns in table
* @param triggerNode
* @version 1.5.0
*/
getPopupContainer?: (triggerNode?: HTMLElement) => HTMLElement;
/**
* Data can be changed again before rendering.
* The default configuration of general user empty data.
* You can configured globally through [ConfigProvider](https://antdv.com/components/config-provider-cn/)
*
* @version 1.5.4
*/
transformCellText?: Function;
/**
* Callback executed when pagination, filters or sorter is changed
* @param pagination
* @param filters
* @param sorter
* @param currentDataSource
*/
onChange?: (pagination: any, filters: any, sorter: any, extra: any) => void;
/**
* Callback executed when the row expand icon is clicked
*
* @param expanded
* @param record
*/
onExpand?: (expande: boolean, record: T) => void;
/**
* Callback executed when the expanded rows change
* @param expandedRows
*/
onExpandedRowsChange?: (expandedRows: string[] | number[]) => void;
}
export declare type CellFormatMap = Map<string | number, any>;
export declare type CellFormatFn = (text: string, record: Recordable, index: number) => string | number;
export declare type CellFormat = string | CellFormatFn | CellFormatMap;
export interface BasicColumn extends ColumnProps {
children?: BasicColumn[];
filters?: {
text: string;
value: string;
children?: unknown[] | (((props: Record<string, unknown>) => unknown[]) & (() => unknown[]) & (() => unknown[]));
}[];
flag?: 'INDEX' | 'DEFAULT' | 'CHECKBOX' | 'RADIO' | 'ACTION';
customTitle?: VueNode;
slots?: Indexable;
defaultHidden?: boolean;
helpMessage?: string | string[];
format?: CellFormat;
edit?: boolean;
editRow?: boolean;
editable?: boolean;
editComponent?: ComponentType;
editComponentProps?: Recordable;
editRule?: boolean | ((text: string, record: Recordable) => Promise<string>);
editValueMap?: (value: any) => string;
onEditRow?: () => void;
}