xph-crud 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -0
- package/dist/index.js +3246 -0
- package/dist/index.umd.cjs +25 -0
- package/dist/style.css +1 -0
- package/dist/types/common/index.d.ts +3 -0
- package/dist/types/common/src/componnets/actions/actions.d.ts +4 -0
- package/dist/types/common/src/componnets/actions/components/button.d.ts +4 -0
- package/dist/types/common/src/componnets/actions/components/dropdown.d.ts +4 -0
- package/dist/types/common/src/componnets/actions/components/index.d.ts +5 -0
- package/dist/types/common/src/componnets/actions/components/more.d.ts +7 -0
- package/dist/types/common/src/componnets/actions/hooks/index.d.ts +8 -0
- package/dist/types/common/src/componnets/actions/hooks/useActionItems.d.ts +6 -0
- package/dist/types/common/src/componnets/actions/hooks/useActionsProps.d.ts +5 -0
- package/dist/types/common/src/componnets/actions/hooks/useExtendActions.d.ts +5 -0
- package/dist/types/common/src/componnets/actions/hooks/useRenderContent.d.ts +6 -0
- package/dist/types/common/src/componnets/actions/types/actionItem.d.ts +67 -0
- package/dist/types/common/src/componnets/actions/types/actions.d.ts +15 -0
- package/dist/types/common/src/componnets/actions/types/index.d.ts +2 -0
- package/dist/types/common/src/componnets/dialog/dialog.d.ts +2 -0
- package/dist/types/common/src/componnets/dialog/types/dialog.d.ts +9 -0
- package/dist/types/common/src/componnets/index.d.ts +5 -0
- package/dist/types/common/src/hooks/index.d.ts +3 -0
- package/dist/types/common/src/hooks/useExtendCompProps.d.ts +45 -0
- package/dist/types/common/src/utils/index.d.ts +1 -0
- package/dist/types/form/index.d.ts +5 -0
- package/dist/types/form/src/components/ActionGroup/index.d.ts +6 -0
- package/dist/types/form/src/components/ApiAutoComplete/index.d.ts +15 -0
- package/dist/types/form/src/components/ApiSelect/index.d.ts +15 -0
- package/dist/types/form/src/components/ApiTransfer/index.d.ts +13 -0
- package/dist/types/form/src/components/ApiTreeSelect/index.d.ts +15 -0
- package/dist/types/form/src/components/AutoUpload/index.d.ts +28 -0
- package/dist/types/form/src/components/Collapse/index.d.ts +7 -0
- package/dist/types/form/src/components/FormItem/index.d.ts +11 -0
- package/dist/types/form/src/components/index.d.ts +5 -0
- package/dist/types/form/src/form.d.ts +8 -0
- package/dist/types/form/src/helper.d.ts +14 -0
- package/dist/types/form/src/hooks/index.d.ts +16 -0
- package/dist/types/form/src/hooks/useApiComonentCache.d.ts +24 -0
- package/dist/types/form/src/hooks/useExtendForm.d.ts +5 -0
- package/dist/types/form/src/hooks/useForm.d.ts +20 -0
- package/dist/types/form/src/hooks/useFormAction.d.ts +12 -0
- package/dist/types/form/src/hooks/useFormCollapse.d.ts +11 -0
- package/dist/types/form/src/hooks/useFormItem.d.ts +40 -0
- package/dist/types/form/src/hooks/useFormProps.d.ts +6 -0
- package/dist/types/form/src/hooks/useFormValues.d.ts +11 -0
- package/dist/types/form/src/types/component.d.ts +35 -0
- package/dist/types/form/src/types/form.d.ts +86 -0
- package/dist/types/form/src/types/formItem.d.ts +54 -0
- package/dist/types/form/src/types/index.d.ts +3 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/table/index.d.ts +4 -0
- package/dist/types/table/src/components/searchForm/components/cacheForm/index.d.ts +6 -0
- package/dist/types/table/src/components/searchForm/index.d.ts +9 -0
- package/dist/types/table/src/components/table/components/cellFunc/cellFunc.d.ts +5 -0
- package/dist/types/table/src/components/table/components/cellFunc/components/actions.d.ts +5 -0
- package/dist/types/table/src/components/table/components/cellFunc/components/index.d.ts +12 -0
- package/dist/types/table/src/components/table/components/cellFunc/components/link.d.ts +5 -0
- package/dist/types/table/src/components/table/components/cellFunc/types/cellFunc.d.ts +43 -0
- package/dist/types/table/src/components/table/components/cellFunc/types/index.d.ts +1 -0
- package/dist/types/table/src/components/table/index.d.ts +9 -0
- package/dist/types/table/src/hooks/index.d.ts +18 -0
- package/dist/types/table/src/hooks/useExtendTable.d.ts +7 -0
- package/dist/types/table/src/hooks/usePagination.d.ts +18 -0
- package/dist/types/table/src/hooks/useRowSelection.d.ts +9 -0
- package/dist/types/table/src/hooks/useSearchForm.d.ts +6 -0
- package/dist/types/table/src/hooks/useTable.d.ts +24 -0
- package/dist/types/table/src/hooks/useTableColumns.d.ts +6 -0
- package/dist/types/table/src/hooks/useTableProps.d.ts +6 -0
- package/dist/types/table/src/hooks/useTableScroll.d.ts +10 -0
- package/dist/types/table/src/hooks/useTopToolbar.d.ts +7 -0
- package/dist/types/table/src/table.d.ts +8 -0
- package/dist/types/table/src/types/apiTable.d.ts +35 -0
- package/dist/types/table/src/types/column.d.ts +32 -0
- package/dist/types/table/src/types/crudForm.d.ts +3 -0
- package/dist/types/table/src/types/index.d.ts +5 -0
- package/dist/types/table/src/types/searchForm.d.ts +9 -0
- package/dist/types/table/src/types/table.d.ts +25 -0
- package/package.json +63 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { default as useFormItem } from './useFormItem';
|
|
2
|
+
export * from './useFormItem';
|
|
3
|
+
export { default as useForm } from './useForm';
|
|
4
|
+
export * from './useForm';
|
|
5
|
+
export { default as useFormValues } from './useFormValues';
|
|
6
|
+
export * from './useFormValues';
|
|
7
|
+
export { default as useFormAction } from './useFormAction';
|
|
8
|
+
export * from './useFormAction';
|
|
9
|
+
export { default as useFormProps } from './useFormProps';
|
|
10
|
+
export * from './useFormProps';
|
|
11
|
+
export { default as useApiComonentCache } from './useApiComonentCache';
|
|
12
|
+
export * from './useApiComonentCache';
|
|
13
|
+
export { default as useFormCollapse } from './useFormCollapse';
|
|
14
|
+
export * from './useFormCollapse';
|
|
15
|
+
export { default as useExtendForm } from './useExtendForm';
|
|
16
|
+
export * from './useExtendForm';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 该钩子解决的问题:
|
|
3
|
+
* 1、使用了Form.useWatch的FormItem,至少都会触发两次组件更新,导致api首次请求的情况不一致
|
|
4
|
+
* 2、每次value的更新,都会导致组件的重新渲染,导致api每次都会请求(处理成当params不一致才重新请求)
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param api 请求的api
|
|
9
|
+
* @param apiCallback 请求之后的回调
|
|
10
|
+
* @param immediate 首次是否立即执行apiCallback
|
|
11
|
+
* @param params 请求的参数
|
|
12
|
+
* @param isUseWatch 是否使用了Form.useWatch
|
|
13
|
+
*/
|
|
14
|
+
interface IUseComonentCacheProps {
|
|
15
|
+
api?: (...args: any[]) => Promise<any>;
|
|
16
|
+
immediate?: boolean;
|
|
17
|
+
params: any;
|
|
18
|
+
apiCallback: (...args: any[]) => void;
|
|
19
|
+
isUseWatch: boolean;
|
|
20
|
+
}
|
|
21
|
+
declare const useApiComonentCache: (props: IUseComonentCacheProps) => {
|
|
22
|
+
getApiData: () => void;
|
|
23
|
+
};
|
|
24
|
+
export default useApiComonentCache;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IFormProps, IFormActionType, IRegister, TFormItemProps } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 注意:
|
|
5
|
+
* useWatch会监听整个表单值得变化,导致重新渲染formItem,所以要根据实际情况来判断到底是否需要监听表单得值,
|
|
6
|
+
* 何时需要监听:只有使用model的formItem属性才需要监听,即当show、ifShow、required、disabled、componentProps、render有其中之一为函数时才需要监听
|
|
7
|
+
* 所以当没有使用model的表单项尽量使用值写法,使用函数写法对表单性能开销很大
|
|
8
|
+
*/
|
|
9
|
+
export declare const useFormModel: (formProps: IFormProps, itemProps: TFormItemProps) => {
|
|
10
|
+
rewritingModel: any;
|
|
11
|
+
isusewatch: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @description 用于注册form的方法
|
|
16
|
+
* @description form组件会先于parent组件挂载,挂载完后调用register方法,将methods注册到useForm中给parent使用
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
declare const useForm: () => [IRegister, IFormActionType];
|
|
20
|
+
export default useForm;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FormInstance } from 'antd';
|
|
2
|
+
import { NamePath } from 'antd/lib/form/interface';
|
|
3
|
+
import { Recordable } from '../types';
|
|
4
|
+
|
|
5
|
+
declare const useFormAction: (instance: FormInstance, formatRenderValues: any, formatReturnValues: any) => {
|
|
6
|
+
getFieldsValue: (...values: any[]) => Recordable<any>;
|
|
7
|
+
setFieldsValue: (values: Recordable<any>) => void;
|
|
8
|
+
resetFields: () => Promise<void>;
|
|
9
|
+
validator: (nameList?: NamePath[]) => Promise<any>;
|
|
10
|
+
scrollToField: (name: NamePath, options?: ScrollOptions) => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export default useFormAction;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IFormProps } from '../types';
|
|
2
|
+
import { RefObject } from 'react';
|
|
3
|
+
|
|
4
|
+
declare const useFormCollapse: (formProps: IFormProps, formItemRefs: RefObject<Map<string, RefObject<any>>>) => {
|
|
5
|
+
collapsible: boolean | undefined;
|
|
6
|
+
collapseNum: number;
|
|
7
|
+
collapseRef: import('react').MutableRefObject<any>;
|
|
8
|
+
onClickCollapseToTrue: () => void;
|
|
9
|
+
onClickCollapseToFalse: () => void;
|
|
10
|
+
};
|
|
11
|
+
export default useFormCollapse;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { IFormProps, TFormItemProps, Recordable } from '../types';
|
|
3
|
+
import { RuleObject } from 'antd/es/form';
|
|
4
|
+
import { ColProps } from 'antd';
|
|
5
|
+
|
|
6
|
+
export declare const useFormItemShow: (item: TFormItemProps, model: any, collapseRef: RefObject<any>) => {
|
|
7
|
+
isShow: boolean;
|
|
8
|
+
isIfShow: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const useFormItemCollapse: (formProps: IFormProps, index: number) => {
|
|
11
|
+
itemCollapse: boolean;
|
|
12
|
+
setItemCollapse: import('react').Dispatch<import('react').SetStateAction<boolean>>;
|
|
13
|
+
};
|
|
14
|
+
export declare const useFormItemRules: ({ item, model, isShow, componentProps, }: {
|
|
15
|
+
item: TFormItemProps;
|
|
16
|
+
model: any;
|
|
17
|
+
isShow: boolean;
|
|
18
|
+
componentProps: Recordable<any>;
|
|
19
|
+
}) => {
|
|
20
|
+
rules: RuleObject[];
|
|
21
|
+
};
|
|
22
|
+
export declare const useFormItemDisabled: (formProps: IFormProps, item: TFormItemProps, model: any) => {
|
|
23
|
+
disabled: boolean | undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare const useFormItemComponentProps: (item: TFormItemProps, model: any) => {
|
|
26
|
+
componentProps: Recordable<any>;
|
|
27
|
+
};
|
|
28
|
+
export declare const useFormItemColProps: (itemProps: TFormItemProps, formProps: IFormProps) => {
|
|
29
|
+
colProps: ColProps;
|
|
30
|
+
};
|
|
31
|
+
declare const useFormItem: ({ formProps }: {
|
|
32
|
+
formProps: IFormProps;
|
|
33
|
+
}) => {
|
|
34
|
+
formItems: (({
|
|
35
|
+
render?: undefined;
|
|
36
|
+
} & import('../types').IComponentFormItemProps) | ({
|
|
37
|
+
component?: undefined;
|
|
38
|
+
} & import('../types').IRenderFormItemProps))[];
|
|
39
|
+
};
|
|
40
|
+
export default useFormItem;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { IFormProps, Recordable, TFormItemProps } from '../types';
|
|
3
|
+
|
|
4
|
+
declare const useFormValues: (formItems: TFormItemProps[], formProps: IFormProps, formItemRefs: RefObject<Map<string, RefObject<any>>>) => {
|
|
5
|
+
handleFormatRenderValues: (values: Recordable<any>) => {
|
|
6
|
+
renderValues: Recordable<any>;
|
|
7
|
+
validKeys: string[];
|
|
8
|
+
};
|
|
9
|
+
handleFormatReturnValues: (values: Recordable<any>) => Recordable<any>;
|
|
10
|
+
};
|
|
11
|
+
export default useFormValues;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SelectProps, InputProps, InputNumberProps, TreeSelectProps, TransferProps, SwitchProps, ButtonProps, RadioProps, CheckboxProps, CascaderProps, TimePickerProps, DatePickerProps, AutoCompleteProps, UploadProps } from 'antd';
|
|
2
|
+
import { IApiSelectProps } from '../components/ApiSelect';
|
|
3
|
+
import { IApiTreeSelectProps } from '../components/ApiTreeSelect';
|
|
4
|
+
import { IApiTransferProps } from '../components/ApiTransfer';
|
|
5
|
+
import { IApiAutoCompleteProps } from '../components/ApiAutoComplete';
|
|
6
|
+
import { IAutoUploadProps } from '../components/AutoUpload';
|
|
7
|
+
|
|
8
|
+
export type TComponentPropsMap = {
|
|
9
|
+
Select: SelectProps;
|
|
10
|
+
Input: InputProps;
|
|
11
|
+
InputNumber: InputNumberProps;
|
|
12
|
+
TreeSelect: TreeSelectProps;
|
|
13
|
+
Transfer: TransferProps;
|
|
14
|
+
Switch: SwitchProps;
|
|
15
|
+
Button: ButtonProps;
|
|
16
|
+
Radio: RadioProps;
|
|
17
|
+
RadioGroup: RadioProps;
|
|
18
|
+
Checkbox: CheckboxProps;
|
|
19
|
+
CheckboxGroup: CheckboxProps;
|
|
20
|
+
Cascader: CascaderProps;
|
|
21
|
+
TimePicker: TimePickerProps;
|
|
22
|
+
DatePicker: DatePickerProps;
|
|
23
|
+
MonthPicker: DatePickerProps;
|
|
24
|
+
WeekPicker: DatePickerProps;
|
|
25
|
+
RangePicker: DatePickerProps;
|
|
26
|
+
InputPassword: InputProps;
|
|
27
|
+
InputTextArea: InputProps;
|
|
28
|
+
AutoComplete: AutoCompleteProps;
|
|
29
|
+
Upload: UploadProps;
|
|
30
|
+
ApiSelect: IApiSelectProps;
|
|
31
|
+
ApiTreeSelect: IApiTreeSelectProps;
|
|
32
|
+
ApiTransfer: IApiTransferProps;
|
|
33
|
+
ApiAutoComplete: IApiAutoCompleteProps;
|
|
34
|
+
AutoUpload: IAutoUploadProps;
|
|
35
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { TFormItemProps, Recordable } from './formItem';
|
|
2
|
+
import { ColProps } from 'antd';
|
|
3
|
+
import { NamePath } from 'antd/lib/form/interface';
|
|
4
|
+
|
|
5
|
+
export interface IRegister {
|
|
6
|
+
(methods: IFormActionType): void;
|
|
7
|
+
}
|
|
8
|
+
export interface IFormProps {
|
|
9
|
+
items: TFormItemProps[] /** 表单项配置集合 */;
|
|
10
|
+
/**
|
|
11
|
+
* @description 表单布局方式(默认horizontal)
|
|
12
|
+
* @description 排除了antd的inline,因为可以使用colProps实现inline布局
|
|
13
|
+
*/
|
|
14
|
+
layout?: "horizontal" | "vertical";
|
|
15
|
+
/** 表示是否显示 label 后面的冒号 (只有在属性 layout 为 horizontal 时有效) */
|
|
16
|
+
colon?: boolean;
|
|
17
|
+
/** 设置表单组件禁用,仅对 antd 组件有效 */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/** 表单项组件布局方式(wrapperCol的span与labelCol的span形成24栅格布局) */
|
|
20
|
+
wrapperCol?: ColProps;
|
|
21
|
+
/** label 标签的文本换行方式 */
|
|
22
|
+
labelWrap?: boolean;
|
|
23
|
+
/** label 标签的文本对齐方式 */
|
|
24
|
+
labelAlign?: "left" | "right";
|
|
25
|
+
/** 表单项label标签布局方式(wrapperCol的span与labelCol的span形成24栅格布局) */
|
|
26
|
+
labelCol?: ColProps;
|
|
27
|
+
/** 表单项的栅格配置 */
|
|
28
|
+
colProps?: ColProps;
|
|
29
|
+
/** 提交失败自动滚动到第一个错误字段 */
|
|
30
|
+
scrollToFirstError?: boolean;
|
|
31
|
+
/** 设置字段组件的尺寸(仅限 antd 组件) */
|
|
32
|
+
size?: "large" | "middle" | "small";
|
|
33
|
+
/** 是否可折叠,默认超过5个折叠 */
|
|
34
|
+
collapsible?: boolean;
|
|
35
|
+
/** 超过多少进行折叠,collapsible为true才生效 */
|
|
36
|
+
collapseNum?: number;
|
|
37
|
+
/** 渲染操作组,用于渲染表单项的操作,这是一个预留项,是否需要操作组由业务自己决定(会跟折叠同行显示) */
|
|
38
|
+
renderActions?: () => React.ReactElement;
|
|
39
|
+
/** 时间返回统一处理函数 */
|
|
40
|
+
transformDateFunc?: (date: any, format: string) => string;
|
|
41
|
+
/**
|
|
42
|
+
* @description 用于将表单内时间区域的应设成 2 个字段,见下方说明
|
|
43
|
+
* @description 如果表单内有时间区间组件,获取到的值是一个数组,但是往往我们传递到后台需要是 2 个字段
|
|
44
|
+
* @example
|
|
45
|
+
* fieldMapToTime: [
|
|
46
|
+
* // data为时间组件在表单内的字段,startTime,endTime为转化后的开始时间与结束时间
|
|
47
|
+
* // 'YYYY-MM-DD'为时间格式,参考moment
|
|
48
|
+
* ['datetime', ['startTime', 'endTime'], 'YYYY-MM-DD'],
|
|
49
|
+
* // 支持多个字段
|
|
50
|
+
* ['datetime1', ['startTime1', 'endTime1'], 'YYYY-MM-DD HH:mm:ss'],
|
|
51
|
+
* ]
|
|
52
|
+
*
|
|
53
|
+
* // fieldMapToTime没写的时候表单获取到的值
|
|
54
|
+
* {
|
|
55
|
+
* datetime: [Date(),Date()]
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* // ['datetime', ['startTime', 'endTime'], 'YYYY-MM-DD'],等同于 dayjs(Date()).format('YYYY-MM-DD'). 之后
|
|
59
|
+
* {
|
|
60
|
+
* startTime: '2020-08-12',
|
|
61
|
+
* endTime: '2020-08-15',
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* // ['datetime', ['startTime', 'endTime'], 'timestamp'],等同于 dayjs(Date()).unix(). 之后
|
|
65
|
+
* {
|
|
66
|
+
* startTime: 1597190400,
|
|
67
|
+
* endTime: 1597449600,
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* // ['datetime', ['startTime', 'endTime'], 'timestampStartDay'],等同于 dayjs(Date()).startOf('day').unix(). 之后
|
|
71
|
+
* {
|
|
72
|
+
* startTime: 1597190400,
|
|
73
|
+
* endTime: 1597449600,
|
|
74
|
+
* }
|
|
75
|
+
*/
|
|
76
|
+
fieldMapToTime?: [string, [string, string], (string | [string, string])?][];
|
|
77
|
+
/** 注册事件(useForm使用,form组件会在挂载后调用) */
|
|
78
|
+
register?: IRegister;
|
|
79
|
+
}
|
|
80
|
+
export interface IFormActionType {
|
|
81
|
+
getFieldsValue: (...values: any[]) => Recordable<any>;
|
|
82
|
+
setFieldsValue: (values: Recordable<any>) => void;
|
|
83
|
+
resetFields: () => Promise<void>;
|
|
84
|
+
validator: (nameList?: NamePath[]) => Promise<any>;
|
|
85
|
+
scrollToField: (name: NamePath, options?: ScrollOptions) => Promise<void>;
|
|
86
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { TComponentPropsMap } from './component';
|
|
2
|
+
import { Rule } from 'antd/es/form';
|
|
3
|
+
import { default as React } from 'react';
|
|
4
|
+
import { ColProps } from 'antd';
|
|
5
|
+
import { IFormActionType } from './form';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 字符串类型对象
|
|
9
|
+
*/
|
|
10
|
+
export type Recordable<T> = Record<string, T>;
|
|
11
|
+
export type TFunction<T> = T | ((args: Recordable<any>) => T);
|
|
12
|
+
export interface IBaseFormItemProps {
|
|
13
|
+
name: string /** 字段名 */;
|
|
14
|
+
label: string /** 标签名 */;
|
|
15
|
+
valuePropName?: string /** 子节点的值的属性,如 Switch、Checkbox 的是 checked */;
|
|
16
|
+
show?: TFunction<boolean> /** 是否显示(相当于display:none) */;
|
|
17
|
+
ifShow?: TFunction<boolean> /** 是否显示(会新增或删除节点) */;
|
|
18
|
+
required?: TFunction<boolean> /** 是否必填 */;
|
|
19
|
+
disabled?: TFunction<boolean> /** 是否禁用(当和 Form 同时设置时,以 Item 为准) */;
|
|
20
|
+
componentProps?: TFunction<Recordable<any>> /** 组件属性 */;
|
|
21
|
+
rules?: Rule[] /** 校验规则 */;
|
|
22
|
+
wrapperCol?: ColProps /** 表单项组件的布局方式(当和 Form 同时设置时,以 Item 为准) */;
|
|
23
|
+
labelCol?: ColProps /** 表单项label标签布局方式(当和 Form 同时设置时,以 Item 为准) */;
|
|
24
|
+
colProps?: ColProps /** 表单项的栅格配置(当和 Form 同时设置时,以 Item 为准) */;
|
|
25
|
+
forceRow?: boolean /** 是否强制换一行显示该表单项(强制换行后续会跟随换行表单项) */;
|
|
26
|
+
initialValue?: any /** 默认值 */;
|
|
27
|
+
}
|
|
28
|
+
/** 自定义渲染函数的props */
|
|
29
|
+
export interface IFRenderProps {
|
|
30
|
+
name: string;
|
|
31
|
+
disabled: boolean;
|
|
32
|
+
componentProps: Recordable<any>;
|
|
33
|
+
model: any;
|
|
34
|
+
methods: IFormActionType;
|
|
35
|
+
}
|
|
36
|
+
/** render props */
|
|
37
|
+
/**
|
|
38
|
+
* @description: 自定义渲染组件,若根节点为antd组件,就会和form组件进行双向绑定,model也是响应式的;若根节点为非antd组件,就不会和form组件进行双向绑定,需根据实际业务手动处理表单项的值
|
|
39
|
+
*/
|
|
40
|
+
export interface IRenderFormItemProps extends IBaseFormItemProps {
|
|
41
|
+
render: (props: IFRenderProps) => React.ReactNode /** 自定义渲染组件 */;
|
|
42
|
+
}
|
|
43
|
+
/** component props */
|
|
44
|
+
export interface IComponentFormItemProps extends IBaseFormItemProps {
|
|
45
|
+
component: keyof TComponentPropsMap /** 映射组件 */;
|
|
46
|
+
}
|
|
47
|
+
type Without<T, K> = {
|
|
48
|
+
[P in Exclude<keyof T, K>]?: never;
|
|
49
|
+
};
|
|
50
|
+
type XOR<T, U> = T | U extends object ? (Without<T, keyof U> & U) | (Without<U, keyof T> & T) : T | U;
|
|
51
|
+
export type TFormItemProps = XOR<IRenderFormItemProps, IComponentFormItemProps>;
|
|
52
|
+
export declare function isComponentFormItemProps(item: TFormItemProps): item is IComponentFormItemProps;
|
|
53
|
+
export declare function isRenderFormItemProps(item: TFormItemProps): item is IRenderFormItemProps;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { default as XphTable } from './src/table';
|
|
2
|
+
import { TTableProps as TXphTableProps, TTableActionType as TXphTableActionType, TDataSourceItem as TXphDataSourceItem, TColumnProps as TXphColumnProps, TApiTableProps as TXphApiTableProps, TSearchFormProps as TXphSearchFormProps, TCrudFormProps as TXphCrudFormProps } from './src/types';
|
|
3
|
+
|
|
4
|
+
export { XphTable, TXphTableProps, TXphTableActionType, TXphDataSourceItem, TXphColumnProps, TXphApiTableProps, TXphSearchFormProps, TXphCrudFormProps, };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TSearchFormActionType } from '../../../../types';
|
|
2
|
+
|
|
3
|
+
declare const _default: import('react').MemoExoticComponent<import('react').ForwardRefExoticComponent<{
|
|
4
|
+
getBindProps: () => any;
|
|
5
|
+
} & import('react').RefAttributes<TSearchFormActionType>>>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { TTableActionType, TSearchFormActionType } from '../../types';
|
|
3
|
+
|
|
4
|
+
declare const SearchForm: import('react').ForwardRefExoticComponent<import('../../../..').IXphFormProps & {
|
|
5
|
+
showSearch?: boolean | undefined;
|
|
6
|
+
} & {
|
|
7
|
+
tableRef: RefObject<TTableActionType>;
|
|
8
|
+
} & import('react').RefAttributes<TSearchFormActionType>>;
|
|
9
|
+
export default SearchForm;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ICurCellFuncProps, IMainProps } from '../types';
|
|
3
|
+
|
|
4
|
+
declare const Actions: (Comp: React.ReactElement, curCellFuncProps: ICurCellFuncProps<"actions">, mainProps: IMainProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export default Actions;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare const cellComponentMap: {
|
|
3
|
+
/** 超链接 */
|
|
4
|
+
link: {
|
|
5
|
+
Comp: (Comp: import('react').JSXElementConstructor<any>, curCellFuncProps: import('../types').ICurCellFuncProps<"link">, mainProps: import('../types').IMainProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
};
|
|
7
|
+
/** 操作组 */
|
|
8
|
+
actions: {
|
|
9
|
+
Comp: (Comp: import('react').ReactElement<any, string | import('react').JSXElementConstructor<any>>, curCellFuncProps: import('../types').ICurCellFuncProps<"actions">, mainProps: import('../types').IMainProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export { cellComponentMap };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ICurCellFuncProps, IMainProps } from '../types';
|
|
3
|
+
|
|
4
|
+
declare const Link: (Comp: React.JSXElementConstructor<any>, curCellFuncProps: ICurCellFuncProps<"link">, mainProps: IMainProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export default Link;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { IXphActionsProps } from '../../../../../../../common';
|
|
2
|
+
|
|
3
|
+
export type TCellComponentType = "link" | "actions";
|
|
4
|
+
/** cellFunc中每一项对应的组件componentProps属性映射 */
|
|
5
|
+
export interface ICellComponentPropsMap {
|
|
6
|
+
link: {
|
|
7
|
+
/** 超链接,点击超链接跳转 */
|
|
8
|
+
url?: string;
|
|
9
|
+
/** 点击事件(优先级最高) */
|
|
10
|
+
onClick?: () => void;
|
|
11
|
+
};
|
|
12
|
+
actions: IXphActionsProps;
|
|
13
|
+
}
|
|
14
|
+
/** cellFunc中每一项的配置 */
|
|
15
|
+
export interface ICellProps<T extends TCellComponentType = TCellComponentType> {
|
|
16
|
+
component: T;
|
|
17
|
+
componentProps?: ICellComponentPropsMap[T];
|
|
18
|
+
}
|
|
19
|
+
/** CellFunc组件的props */
|
|
20
|
+
export interface ICellFuncProps<T = unknown, U extends TCellComponentType = TCellComponentType> {
|
|
21
|
+
dslConfig: ICellProps<U>[];
|
|
22
|
+
renderPrams: {
|
|
23
|
+
text: any;
|
|
24
|
+
record: T;
|
|
25
|
+
index: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** cellFunc中每一项对应的组件的props */
|
|
29
|
+
export interface ICurCellFuncProps<T extends TCellComponentType = TCellComponentType> {
|
|
30
|
+
curComponentProps?: ICellComponentPropsMap[T];
|
|
31
|
+
cellFuncProps: ICellFuncProps<unknown, T>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* 因为渲染是从cellFuncs中的最后一项开始的,所以mainClick是排在后面的组件传递到前面的
|
|
36
|
+
*
|
|
37
|
+
* 目的:目的是为了将自定义组件的点击事件交给最底层的组件进行调用
|
|
38
|
+
* 注意:因为多个自定义组件可能都有mainClick,所以也需要保证其他组件的正常调用(即:传递给子组件Comp的时候,需要把父组件传递过来的mainClick给手动执行一下)
|
|
39
|
+
*/
|
|
40
|
+
export interface IMainProps {
|
|
41
|
+
mainClick?: () => void;
|
|
42
|
+
mainStyle?: React.CSSProperties;
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cellFunc';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { TTableProps, TSearchFormActionType, TTableActionType } from '../../types';
|
|
3
|
+
|
|
4
|
+
declare const Table: import('react').ForwardRefExoticComponent<{
|
|
5
|
+
fullHeight?: boolean | undefined;
|
|
6
|
+
tableProps: TTableProps;
|
|
7
|
+
searchFormRef: RefObject<TSearchFormActionType>;
|
|
8
|
+
} & import('react').RefAttributes<TTableActionType>>;
|
|
9
|
+
export default Table;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { default as useSearchForm } from './useSearchForm';
|
|
2
|
+
export * from './useSearchForm';
|
|
3
|
+
export { default as useTableColumns } from './useTableColumns';
|
|
4
|
+
export * from './useTableColumns';
|
|
5
|
+
export { default as useTableProps } from './useTableProps';
|
|
6
|
+
export * from './useTableProps';
|
|
7
|
+
export { default as usePagination } from './usePagination';
|
|
8
|
+
export * from './usePagination';
|
|
9
|
+
export { default as useTable } from './useTable';
|
|
10
|
+
export * from './useTable';
|
|
11
|
+
export { default as useRowSelection } from './useRowSelection';
|
|
12
|
+
export * from './useRowSelection';
|
|
13
|
+
export { default as useTableScroll } from './useTableScroll';
|
|
14
|
+
export * from './useTableScroll';
|
|
15
|
+
export { default as useTopToolbar } from './useTopToolbar';
|
|
16
|
+
export * from './useTopToolbar';
|
|
17
|
+
export { default as useExtendTable } from './useExtendTable';
|
|
18
|
+
export * from './useExtendTable';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TTableProps } from '../types';
|
|
2
|
+
import { RefObject } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface IPagination {
|
|
5
|
+
pageSize: number;
|
|
6
|
+
current: number;
|
|
7
|
+
total: number;
|
|
8
|
+
pageSizeOptions: number[];
|
|
9
|
+
}
|
|
10
|
+
export interface IUsePagination {
|
|
11
|
+
show: boolean;
|
|
12
|
+
model: IPagination | false;
|
|
13
|
+
update: (props: Partial<IPagination>) => void;
|
|
14
|
+
}
|
|
15
|
+
export default function usePagination(props: TTableProps): {
|
|
16
|
+
pagination: IUsePagination;
|
|
17
|
+
lastPaginationState: RefObject<IPagination | false>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TTableProps, TDataSourceItem } from '../types';
|
|
2
|
+
import { IUseTable } from './useTable';
|
|
3
|
+
import { TableRowSelection } from 'antd/es/table/interface';
|
|
4
|
+
|
|
5
|
+
declare const useRowSelection: (props: TTableProps, table: IUseTable) => {
|
|
6
|
+
rowSelection: TableRowSelection<TDataSourceItem> | undefined;
|
|
7
|
+
getNewRowSelection: () => TableRowSelection<TDataSourceItem> | undefined;
|
|
8
|
+
};
|
|
9
|
+
export default useRowSelection;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TTableProps, TSearchFormActionType } from '../types';
|
|
2
|
+
|
|
3
|
+
export default function useSearchForm({ searchForm }: TTableProps): {
|
|
4
|
+
searchFormRef: import('react').RefObject<TSearchFormActionType>;
|
|
5
|
+
searchFormProps: import('../types').TSearchFormProps | undefined;
|
|
6
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TTableProps, TDataSourceItem, TSearchFormActionType } from '../types';
|
|
2
|
+
import { RefObject } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface ITable {
|
|
5
|
+
loading: boolean;
|
|
6
|
+
dataSource: TDataSourceItem[];
|
|
7
|
+
selection: TDataSourceItem[];
|
|
8
|
+
/** 存储一份备用数据(只有前端做分页时才使用到) */
|
|
9
|
+
backupsDataSource?: TDataSourceItem[];
|
|
10
|
+
}
|
|
11
|
+
export interface IUseTable {
|
|
12
|
+
model: ITable;
|
|
13
|
+
update: (props: Partial<ITable>) => void;
|
|
14
|
+
}
|
|
15
|
+
export default function useTable(props: TTableProps, searchFormRef: RefObject<TSearchFormActionType>): {
|
|
16
|
+
table: IUseTable;
|
|
17
|
+
pagination: import('./usePagination').IUsePagination;
|
|
18
|
+
firstGetTableData: () => Promise<void>;
|
|
19
|
+
onPaginationChange: (page: number, pageSize: number) => void;
|
|
20
|
+
onAllChange: (...args: any[]) => Promise<void>;
|
|
21
|
+
resetData: () => Promise<void>;
|
|
22
|
+
resetAllData: () => Promise<void>;
|
|
23
|
+
reloadData: () => Promise<void>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TTableProps } from '../types';
|
|
2
|
+
|
|
3
|
+
export default function useTableScroll(tableProps: TTableProps, fullHeight?: boolean): {
|
|
4
|
+
divRef: import('react').RefObject<HTMLDivElement>;
|
|
5
|
+
scroll: {
|
|
6
|
+
x: string | number | true;
|
|
7
|
+
y?: string | number | undefined;
|
|
8
|
+
scrollToFirstRowOnChange?: boolean | undefined;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TTableProps } from '../types';
|
|
2
|
+
import { IUseTable } from '../hooks';
|
|
3
|
+
import { IXphActionsProps } from '../../../common';
|
|
4
|
+
|
|
5
|
+
export default function useTopToolbar(tableProps: TTableProps, table: IUseTable): {
|
|
6
|
+
getTopToolbarBindProps: () => IXphActionsProps;
|
|
7
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ForwardedRef } from 'react';
|
|
2
|
+
import { TTableProps, TTableActionType, TDataSourceItem } from './types';
|
|
3
|
+
|
|
4
|
+
declare const XphTable: <T extends TDataSourceItem>(props: TTableProps<T>, ref: ForwardedRef<TTableActionType>) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
declare const ForwardedXphTable: <RecordType extends TDataSourceItem = TDataSourceItem>(props: TTableProps<RecordType> & {
|
|
6
|
+
ref?: ForwardedRef<TTableActionType> | undefined;
|
|
7
|
+
}) => ReturnType<typeof XphTable>;
|
|
8
|
+
export default ForwardedXphTable;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { TableProps, PaginationProps } from 'antd';
|
|
2
|
+
import { TableRowSelection, RowSelectionType } from 'antd/lib/table/interface';
|
|
3
|
+
import { IXphActionsProps } from '../../../common';
|
|
4
|
+
import { TDataSourceItem } from './table';
|
|
5
|
+
import { TColumnProps } from './column';
|
|
6
|
+
|
|
7
|
+
export interface IFunctionToolbarParams<RecordType = TDataSourceItem> {
|
|
8
|
+
loading: boolean;
|
|
9
|
+
selection: RecordType[];
|
|
10
|
+
}
|
|
11
|
+
/** 扩展antd table的属性 */
|
|
12
|
+
export type TApiTableProps<RecordType = TDataSourceItem> = {
|
|
13
|
+
/** 列配置项 */
|
|
14
|
+
columns?: TColumnProps<RecordType>[];
|
|
15
|
+
/** 首次是否自动请求 */
|
|
16
|
+
autoRequest?: boolean;
|
|
17
|
+
/** 获取datasource的api */
|
|
18
|
+
api?: (params: any) => Promise<any>;
|
|
19
|
+
/** 格式化返回的datasource */
|
|
20
|
+
formatDataSource?: (data: any) => any[];
|
|
21
|
+
/** 是否开启前端自动分页(当api不支持分页时可用) */
|
|
22
|
+
autoPagination?: boolean;
|
|
23
|
+
/** 单选 / 多选 */
|
|
24
|
+
rowSelection?: RowSelectionType | TableRowSelection<RecordType>;
|
|
25
|
+
/** 分页配置(因为分页器是独立出来的,使用table的分页器布局需要修改样式) */
|
|
26
|
+
pagination?: false | PaginationProps;
|
|
27
|
+
/** 表格撑满父容器(virtual为true时,默认fullHeight为true) */
|
|
28
|
+
fullHeight?: boolean;
|
|
29
|
+
/** 顶部操作栏配置,函数时可以传递参数,参数是什么由调用方决定 */
|
|
30
|
+
toolbar?: IXphActionsProps | ((e: IFunctionToolbarParams<RecordType>) => IXphActionsProps);
|
|
31
|
+
/** 排序、筛选变化时触发 */
|
|
32
|
+
onChange?: (filters: any, sorter: any, extra: any) => void;
|
|
33
|
+
} & Omit<TableProps<RecordType>,
|
|
34
|
+
/** 内部控制的属性/重写的属性 */
|
|
35
|
+
"rowSelection" | "columns" | "loading" | "dataSource" | "pagination">;
|