|
|
@ -10,142 +10,151 @@ import type { |
|
|
|
TableSetting, |
|
|
|
TableSetting, |
|
|
|
} from './types/table' |
|
|
|
} from './types/table' |
|
|
|
import { DEFAULT_FILTER_FN, DEFAULT_SIZE, DEFAULT_SORT_FN, FETCH_SETTING } from './const' |
|
|
|
import { DEFAULT_FILTER_FN, DEFAULT_SIZE, DEFAULT_SORT_FN, FETCH_SETTING } from './const' |
|
|
|
|
|
|
|
import type { EditRecordRow } from './components/editable' |
|
|
|
import type { FormProps } from '@/components/Form' |
|
|
|
import type { FormProps } from '@/components/Form' |
|
|
|
|
|
|
|
|
|
|
|
import { propTypes } from '@/utils/propTypes' |
|
|
|
import { propTypes } from '@/utils/propTypes' |
|
|
|
|
|
|
|
|
|
|
|
export const basicProps = { |
|
|
|
export function defineTableProps<T>() { |
|
|
|
clickToRowSelect: { type: Boolean, default: true }, |
|
|
|
return { |
|
|
|
isTreeTable: Boolean, |
|
|
|
clickToRowSelect: { type: Boolean, default: true }, |
|
|
|
tableSetting: propTypes.shape<TableSetting>({}), |
|
|
|
isTreeTable: Boolean, |
|
|
|
inset: Boolean, |
|
|
|
tableSetting: propTypes.shape<TableSetting>({}), |
|
|
|
sortFn: { |
|
|
|
inset: Boolean, |
|
|
|
type: Function as PropType<(sortInfo: SorterResult) => any>, |
|
|
|
sortFn: { |
|
|
|
default: DEFAULT_SORT_FN, |
|
|
|
type: Function as PropType<(sortInfo: SorterResult) => any>, |
|
|
|
}, |
|
|
|
default: DEFAULT_SORT_FN, |
|
|
|
filterFn: { |
|
|
|
}, |
|
|
|
type: Function as PropType<(data: Partial<Recordable<string[]>>) => any>, |
|
|
|
filterFn: { |
|
|
|
default: DEFAULT_FILTER_FN, |
|
|
|
type: Function as PropType<(data: Partial<Recordable<string[]>>) => any>, |
|
|
|
}, |
|
|
|
default: DEFAULT_FILTER_FN, |
|
|
|
showTableSetting: Boolean, |
|
|
|
}, |
|
|
|
autoCreateKey: { type: Boolean, default: true }, |
|
|
|
showTableSetting: Boolean, |
|
|
|
striped: { type: Boolean, default: true }, |
|
|
|
autoCreateKey: { type: Boolean, default: true }, |
|
|
|
showSummary: Boolean, |
|
|
|
striped: { type: Boolean, default: true }, |
|
|
|
summaryFunc: { |
|
|
|
showSummary: Boolean, |
|
|
|
type: [Function, Array] as PropType<(...arg: any[]) => any[]>, |
|
|
|
summaryFunc: { |
|
|
|
default: null, |
|
|
|
type: [Function, Array] as PropType<(...arg: any[]) => any[]>, |
|
|
|
}, |
|
|
|
default: null, |
|
|
|
summaryData: { |
|
|
|
}, |
|
|
|
type: Array as PropType<Recordable[]>, |
|
|
|
summaryData: { |
|
|
|
default: null, |
|
|
|
type: Array as PropType<Recordable[]>, |
|
|
|
}, |
|
|
|
default: null, |
|
|
|
indentSize: propTypes.number.def(24), |
|
|
|
}, |
|
|
|
canColDrag: { type: Boolean, default: true }, |
|
|
|
indentSize: propTypes.number.def(24), |
|
|
|
api: { |
|
|
|
canColDrag: { type: Boolean, default: true }, |
|
|
|
type: Function as PropType<(...arg: any[]) => Promise<any>>, |
|
|
|
api: { |
|
|
|
default: null, |
|
|
|
type: Function as PropType< |
|
|
|
}, |
|
|
|
(...arg: any[]) => Promise< |
|
|
|
beforeFetch: { |
|
|
|
| T[] |
|
|
|
type: Function as PropType<Fn>, |
|
|
|
| { list: T[], pageNo?: number, pageSize?: number, total?: number } |
|
|
|
default: null, |
|
|
|
> |
|
|
|
}, |
|
|
|
>, |
|
|
|
afterFetch: { |
|
|
|
default: null, |
|
|
|
type: Function as PropType<Fn>, |
|
|
|
}, |
|
|
|
default: null, |
|
|
|
beforeFetch: { |
|
|
|
}, |
|
|
|
type: Function as PropType<Fn>, |
|
|
|
handleSearchInfoFn: { |
|
|
|
default: null, |
|
|
|
type: Function as PropType<Fn>, |
|
|
|
}, |
|
|
|
default: null, |
|
|
|
afterFetch: { |
|
|
|
}, |
|
|
|
type: Function as PropType<Fn>, |
|
|
|
fetchSetting: { |
|
|
|
default: null, |
|
|
|
type: Object as PropType<FetchSetting>, |
|
|
|
}, |
|
|
|
default: () => { |
|
|
|
handleSearchInfoFn: { |
|
|
|
return FETCH_SETTING |
|
|
|
type: Function as PropType<Fn>, |
|
|
|
}, |
|
|
|
default: null, |
|
|
|
}, |
|
|
|
}, |
|
|
|
// 立即请求接口
|
|
|
|
fetchSetting: { |
|
|
|
immediate: { type: Boolean, default: true }, |
|
|
|
type: Object as PropType<FetchSetting>, |
|
|
|
emptyDataIsShowTable: { type: Boolean, default: true }, |
|
|
|
default: () => { |
|
|
|
// 额外的请求参数
|
|
|
|
return FETCH_SETTING |
|
|
|
searchInfo: { |
|
|
|
}, |
|
|
|
type: Object as PropType<Recordable>, |
|
|
|
}, |
|
|
|
default: null, |
|
|
|
// 立即请求接口
|
|
|
|
}, |
|
|
|
immediate: { type: Boolean, default: true }, |
|
|
|
// 默认的排序参数
|
|
|
|
emptyDataIsShowTable: { type: Boolean, default: true }, |
|
|
|
defSort: { |
|
|
|
// 额外的请求参数
|
|
|
|
type: Object as PropType<Recordable>, |
|
|
|
searchInfo: { |
|
|
|
default: null, |
|
|
|
type: Object as PropType<Recordable>, |
|
|
|
}, |
|
|
|
default: null, |
|
|
|
// 使用搜索表单
|
|
|
|
}, |
|
|
|
useSearchForm: propTypes.bool, |
|
|
|
// 默认的排序参数
|
|
|
|
// 表单配置
|
|
|
|
defSort: { |
|
|
|
formConfig: { |
|
|
|
type: Object as PropType<Recordable>, |
|
|
|
type: Object as PropType<Partial<FormProps>>, |
|
|
|
default: null, |
|
|
|
default: null, |
|
|
|
}, |
|
|
|
}, |
|
|
|
// 使用搜索表单
|
|
|
|
columns: { |
|
|
|
useSearchForm: propTypes.bool, |
|
|
|
type: Array as PropType<BasicColumn[]>, |
|
|
|
// 表单配置
|
|
|
|
default: () => [], |
|
|
|
formConfig: { |
|
|
|
}, |
|
|
|
type: Object as PropType<Partial<FormProps>>, |
|
|
|
showIndexColumn: { type: Boolean, default: true }, |
|
|
|
default: null, |
|
|
|
indexColumnProps: { |
|
|
|
}, |
|
|
|
type: Object as PropType<BasicColumn>, |
|
|
|
columns: { |
|
|
|
default: null, |
|
|
|
type: Array as PropType<BasicColumn[]>, |
|
|
|
}, |
|
|
|
default: () => [], |
|
|
|
actionColumn: { |
|
|
|
}, |
|
|
|
type: Object as PropType<BasicColumn>, |
|
|
|
showIndexColumn: { type: Boolean, default: true }, |
|
|
|
default: null, |
|
|
|
indexColumnProps: { |
|
|
|
}, |
|
|
|
type: Object as PropType<BasicColumn>, |
|
|
|
ellipsis: { type: Boolean, default: true }, |
|
|
|
default: null, |
|
|
|
isCanResizeParent: { type: Boolean, default: false }, |
|
|
|
}, |
|
|
|
canResize: { type: Boolean, default: true }, |
|
|
|
actionColumn: { |
|
|
|
clearSelectOnPageChange: propTypes.bool, |
|
|
|
type: Object as PropType<BasicColumn>, |
|
|
|
resizeHeightOffset: propTypes.number.def(0), |
|
|
|
default: null, |
|
|
|
rowSelection: { |
|
|
|
}, |
|
|
|
type: Object as PropType<TableRowSelection | null>, |
|
|
|
ellipsis: { type: Boolean, default: true }, |
|
|
|
default: null, |
|
|
|
isCanResizeParent: { type: Boolean, default: false }, |
|
|
|
}, |
|
|
|
canResize: { type: Boolean, default: true }, |
|
|
|
title: { |
|
|
|
clearSelectOnPageChange: propTypes.bool, |
|
|
|
type: [String, Function] as PropType<string | ((data: Recordable) => string)>, |
|
|
|
resizeHeightOffset: propTypes.number.def(0), |
|
|
|
default: null, |
|
|
|
rowSelection: { |
|
|
|
}, |
|
|
|
type: Object as PropType<TableRowSelection<EditRecordRow<T>> | null>, |
|
|
|
titleHelpMessage: { |
|
|
|
default: null, |
|
|
|
type: [String, Array] as PropType<string | string[]>, |
|
|
|
}, |
|
|
|
}, |
|
|
|
title: { |
|
|
|
maxHeight: propTypes.number, |
|
|
|
type: [String, Function] as PropType<string | ((data: Recordable) => string)>, |
|
|
|
dataSource: { |
|
|
|
default: null, |
|
|
|
type: Array as PropType<Recordable[]>, |
|
|
|
}, |
|
|
|
default: null, |
|
|
|
titleHelpMessage: { |
|
|
|
}, |
|
|
|
type: [String, Array] as PropType<string | string[]>, |
|
|
|
rowKey: { |
|
|
|
}, |
|
|
|
type: [String, Function] as PropType<string | ((record: Recordable) => string)>, |
|
|
|
maxHeight: propTypes.number, |
|
|
|
default: '', |
|
|
|
dataSource: { |
|
|
|
}, |
|
|
|
type: Array as PropType<T[]>, |
|
|
|
bordered: propTypes.bool, |
|
|
|
default: null, |
|
|
|
pagination: { |
|
|
|
}, |
|
|
|
type: [Object, Boolean] as PropType<PaginationProps | boolean>, |
|
|
|
rowKey: { |
|
|
|
default: null, |
|
|
|
// eslint-disable-next-line ts/ban-types
|
|
|
|
}, |
|
|
|
type: [String, Function] as PropType<keyof T | ((record: T) => keyof T) | (string & {})>, |
|
|
|
loading: propTypes.bool, |
|
|
|
default: '', |
|
|
|
rowClassName: { |
|
|
|
}, |
|
|
|
type: Function as PropType<(record: TableCustomRecord<any>, index: number) => string>, |
|
|
|
bordered: propTypes.bool, |
|
|
|
}, |
|
|
|
pagination: { |
|
|
|
scroll: { |
|
|
|
type: [Object, Boolean] as PropType<PaginationProps | boolean>, |
|
|
|
type: Object as PropType<{ x: number | string | true, y: number | string }>, |
|
|
|
default: null, |
|
|
|
default: null, |
|
|
|
}, |
|
|
|
}, |
|
|
|
loading: propTypes.bool, |
|
|
|
beforeEditSubmit: { |
|
|
|
rowClassName: { |
|
|
|
type: Function as PropType< |
|
|
|
type: Function as PropType<(record: TableCustomRecord<any>, index: number) => string>, |
|
|
|
(data: { |
|
|
|
}, |
|
|
|
record: Recordable |
|
|
|
scroll: { |
|
|
|
index: number |
|
|
|
type: Object as PropType<{ x: number | string | true, y: number | string }>, |
|
|
|
key: string | number |
|
|
|
default: null, |
|
|
|
value: any |
|
|
|
}, |
|
|
|
}) => Promise<any> |
|
|
|
beforeEditSubmit: { |
|
|
|
>, |
|
|
|
type: Function as PropType< |
|
|
|
}, |
|
|
|
(data: { |
|
|
|
size: { |
|
|
|
record: T |
|
|
|
type: String as PropType<SizeType>, |
|
|
|
index: number |
|
|
|
default: DEFAULT_SIZE, |
|
|
|
key: string | number |
|
|
|
}, |
|
|
|
value: any |
|
|
|
|
|
|
|
}) => Promise<any> |
|
|
|
|
|
|
|
>, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
size: { |
|
|
|
|
|
|
|
type: String as PropType<SizeType>, |
|
|
|
|
|
|
|
default: DEFAULT_SIZE, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|