zy-react-library 1.2.31 → 1.2.32
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.
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { FormInstance, FormProps } from "antd/es/form";
|
|
2
2
|
import type { Gutter } from "antd/es/grid/row";
|
|
3
|
+
import type { Store } from "rc-field-form/lib/interface";
|
|
3
4
|
import type { FC, ReactNode } from "react";
|
|
4
|
-
import type { FormOption
|
|
5
|
+
import type { FormOption } from "./FormItemsRenderer";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* FormBuilder 组件属性
|
|
8
9
|
*/
|
|
9
10
|
export interface FormBuilderProps extends Omit<FormProps, "form"> {
|
|
10
11
|
/** 表单初始值 */
|
|
11
|
-
values?:
|
|
12
|
+
values?: Store;
|
|
12
13
|
/** 表单配置项数组 */
|
|
13
14
|
options: FormOption[];
|
|
14
15
|
/** 栅格间距,默认 24 */
|
|
@@ -2,6 +2,7 @@ import type { ColProps } from "antd/es/col";
|
|
|
2
2
|
import type { FormItemProps, Rule } from "antd/es/form";
|
|
3
3
|
import type { FormListFieldData } from "antd/es/form/FormList";
|
|
4
4
|
import type { Gutter } from "antd/es/grid/row";
|
|
5
|
+
import type { Store } from "rc-field-form/lib/interface";
|
|
5
6
|
import type { FC, ReactNode } from "react";
|
|
6
7
|
import type { FORM_ITEM_RENDER_TYPE_MAP } from "../../enum/formItemRender";
|
|
7
8
|
|
|
@@ -31,11 +32,6 @@ export interface ItemsFieldConfig {
|
|
|
31
32
|
labelKey?: string | ((item: Record<string, any>) => ReactNode);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
/**
|
|
35
|
-
* 表单值类型
|
|
36
|
-
*/
|
|
37
|
-
export type FormValues = Record<string, any>;
|
|
38
|
-
|
|
39
35
|
/**
|
|
40
36
|
* Form.List 操作项
|
|
41
37
|
*/
|
|
@@ -45,7 +41,7 @@ export interface FormListOperations {
|
|
|
45
41
|
/** 当前项在列表中的索引位置 */
|
|
46
42
|
fieldIndex: number;
|
|
47
43
|
/** 新增方法 */
|
|
48
|
-
add: (defaultValue?:
|
|
44
|
+
add: (defaultValue?: Store, insertIndex?: number) => void;
|
|
49
45
|
/** 删除方法 */
|
|
50
46
|
remove: (index: number | number[]) => void;
|
|
51
47
|
/** 移动方法 */
|
|
@@ -67,15 +63,25 @@ export interface FormListUniqueProps {
|
|
|
67
63
|
/** 表单配置项 */
|
|
68
64
|
options: (field: FormListFieldData, fieldIndex: number, operations: FormListOperations) => FormOption[];
|
|
69
65
|
/** 点击新增按钮时的默认值 */
|
|
70
|
-
addDefaultValue?:
|
|
66
|
+
addDefaultValue?: Store;
|
|
71
67
|
/** 点击新增按钮时插入的索引位置 */
|
|
72
68
|
addInsertIndex?: number;
|
|
73
69
|
}
|
|
74
70
|
|
|
71
|
+
/**
|
|
72
|
+
* 条件类型辅助工具
|
|
73
|
+
*/
|
|
74
|
+
type WhenTrue<Condition extends boolean, T> = Condition extends true ? never : T;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 表单配置项属性类型辅助工具
|
|
78
|
+
*/
|
|
79
|
+
type FormOptionProperty<O extends boolean, C extends boolean, T> = WhenTrue<O, WhenTrue<C, T>>;
|
|
80
|
+
|
|
75
81
|
/**
|
|
76
82
|
* 表单配置项公共字段
|
|
77
83
|
*/
|
|
78
|
-
export interface FormOptionBase {
|
|
84
|
+
export interface FormOptionBase<O extends boolean = false, C extends boolean = false> {
|
|
79
85
|
/** React 需要的 key,如果传递了唯一的 name,则不需要 */
|
|
80
86
|
key?: string;
|
|
81
87
|
/** 表单项字段名 */
|
|
@@ -83,77 +89,102 @@ export interface FormOptionBase {
|
|
|
83
89
|
/** 表单项标签 */
|
|
84
90
|
label?: ReactNode;
|
|
85
91
|
/** 占据栅格列数,默认 12 */
|
|
86
|
-
span?: number | string
|
|
92
|
+
span?: WhenTrue<O, number | string>;
|
|
87
93
|
/** 是否必填,默认 true,支持函数动态计算 */
|
|
88
|
-
required?: boolean | ((formValues:
|
|
94
|
+
required?: FormOptionProperty<O, C, boolean | ((formValues: Store) => boolean)>;
|
|
89
95
|
/** 验证规则 */
|
|
90
|
-
rules?: Rule | Rule[]
|
|
96
|
+
rules?: FormOptionProperty<O, C, Rule | Rule[]>;
|
|
91
97
|
/** 是否使用字符验证限制 */
|
|
92
|
-
useConstraints?: boolean
|
|
98
|
+
useConstraints?: FormOptionProperty<O, C, boolean>;
|
|
93
99
|
/** 占位符文本,默认会根据传入的 render 类型自动判断(请选择、请输入)和 label 组合 */
|
|
94
|
-
placeholder?: ReactNode
|
|
100
|
+
placeholder?: FormOptionProperty<O, C, ReactNode>;
|
|
95
101
|
/** 提示信息,传入将在 label 右侧生成图标展示 tooltip */
|
|
96
|
-
tip?: ReactNode
|
|
102
|
+
tip?: FormOptionProperty<O, C, ReactNode>;
|
|
97
103
|
/** 是否隐藏,默认 false,支持函数动态计算 */
|
|
98
|
-
hidden?: boolean | ((formValues:
|
|
104
|
+
hidden?: WhenTrue<O, boolean | ((formValues: Store) => boolean)>;
|
|
99
105
|
/** 是否自定义渲染,完全交给外部控制渲染,默认 false */
|
|
100
|
-
customizeRender?:
|
|
101
|
-
/** 选项数据(用于 select、radio、checkbox) */
|
|
102
|
-
items?: OptionItem[];
|
|
103
|
-
/** 字段键配置 */
|
|
104
|
-
itemsField?: ItemsFieldConfig;
|
|
105
|
-
/** checkbox 的栅格数量,如果不传入不使用栅格,传入才使用 */
|
|
106
|
-
checkboxCol?: number;
|
|
106
|
+
customizeRender?: C;
|
|
107
107
|
/** 传递给 Form.Item 的属性,支持函数动态计算 */
|
|
108
|
-
formItemProps?: FormItemProps | ((formValues:
|
|
108
|
+
formItemProps?: FormOptionProperty<O, C, FormItemProps | ((formValues: Store) => FormItemProps)>;
|
|
109
109
|
/** label 栅格配置,默认直接使用外层的 labelCol,如果 span 等于 24,是外层的 labelCol.span 一半 */
|
|
110
|
-
labelCol?: ColProps
|
|
110
|
+
labelCol?: FormOptionProperty<O, C, ColProps>;
|
|
111
111
|
/** wrapper 栅格配置,默认 24 - labelCol.span */
|
|
112
|
-
wrapperCol?: ColProps
|
|
112
|
+
wrapperCol?: FormOptionProperty<O, C, ColProps>;
|
|
113
113
|
/** 是否应该更新(用于表单联动) */
|
|
114
|
-
shouldUpdate?: boolean | ((prevValues:
|
|
114
|
+
shouldUpdate?: FormOptionProperty<O, C, boolean | ((prevValues: Store, nextValues: Store, info: { source?: string }) => boolean)>;
|
|
115
115
|
/** 依赖字段(用于表单联动) */
|
|
116
|
-
dependencies?: FormFieldName[]
|
|
116
|
+
dependencies?: FormOptionProperty<O, C, FormFieldName[]>;
|
|
117
117
|
/** 是否仅用于保存标签,不渲染到页面上,只在表单中保存数据,默认 false */
|
|
118
|
-
onlyForLabel?:
|
|
119
|
-
/** Form.List 独有的属性 */
|
|
120
|
-
formListUniqueProps?: FormListUniqueProps | ((formValues: FormValues) => FormListUniqueProps);
|
|
118
|
+
onlyForLabel?: O;
|
|
121
119
|
}
|
|
122
120
|
|
|
123
121
|
/**
|
|
124
122
|
* 按 render 类型区分的表单项
|
|
125
123
|
*/
|
|
126
|
-
export type FormOptionByRender<
|
|
124
|
+
export type FormOptionByRender<R extends keyof FORM_ITEM_RENDER_TYPE_MAP, O extends boolean = false, C extends boolean = false> = FormOptionBase<O, C> & {
|
|
127
125
|
/** 渲染类型(写字面量时 componentProps 会按该类型推导) */
|
|
128
|
-
render:
|
|
126
|
+
render: R;
|
|
129
127
|
/** 传递给表单控件的属性,类型由 render 决定 */
|
|
130
|
-
componentProps?: FORM_ITEM_RENDER_TYPE_MAP[
|
|
128
|
+
componentProps?: FormOptionProperty<O, C, FORM_ITEM_RENDER_TYPE_MAP[R] | ((formValues: Store) => FORM_ITEM_RENDER_TYPE_MAP[R])>;
|
|
129
|
+
/** 选项数据(用于 select、radio、checkbox) */
|
|
130
|
+
items?: FormOptionProperty<O, C, R extends "select" | "radio" | "checkbox" ? OptionItem[] : never>;
|
|
131
|
+
/** 字段键配置 */
|
|
132
|
+
itemsField?: FormOptionProperty<O, C, R extends "select" | "radio" | "checkbox" ? ItemsFieldConfig : never>;
|
|
133
|
+
/** checkbox 的栅格数量,如果不传入不使用栅格,传入才使用 */
|
|
134
|
+
checkboxCol?: FormOptionProperty<O, C, R extends "checkbox" ? number : never>;
|
|
135
|
+
/** Form.List 独有的属性 */
|
|
136
|
+
formListUniqueProps?: FormOptionProperty<O, C, R extends "formList" ? FormListUniqueProps | ((formValues: Store) => FormListUniqueProps) : never>;
|
|
131
137
|
};
|
|
132
138
|
|
|
133
139
|
/**
|
|
134
140
|
* 不写 render 或 render 为 input 时的表单项(默认按输入框)
|
|
135
141
|
*/
|
|
136
|
-
export type FormOptionDefault = FormOptionBase & {
|
|
142
|
+
export type FormOptionDefault<O extends boolean = false, C extends boolean = false> = FormOptionBase<O, C> & {
|
|
143
|
+
/** 渲染类型,默认 input */
|
|
137
144
|
render?: "input" | undefined;
|
|
138
145
|
/** 传递给 Input 的属性 */
|
|
139
|
-
componentProps?: FORM_ITEM_RENDER_TYPE_MAP["input"] | ((formValues:
|
|
146
|
+
componentProps?: FORM_ITEM_RENDER_TYPE_MAP["input"] | ((formValues: Store) => FORM_ITEM_RENDER_TYPE_MAP["input"]);
|
|
147
|
+
/** 选项数据(用于 select、radio、checkbox),input 时不需要 */
|
|
148
|
+
items?: never;
|
|
149
|
+
/** 字段键配置,input 时不需要 */
|
|
150
|
+
itemsField?: never;
|
|
151
|
+
/** checkbox 的栅格数量,input 时不需要 */
|
|
152
|
+
checkboxCol?: never;
|
|
153
|
+
/** Form.List 独有的属性,input 时不需要 */
|
|
154
|
+
formListUniqueProps?: never;
|
|
140
155
|
};
|
|
141
156
|
|
|
142
157
|
/**
|
|
143
158
|
* 自定义渲染时的表单项(render 为 ReactNode 时使用)
|
|
144
159
|
*/
|
|
145
|
-
export type FormOptionCustomRender = FormOptionBase & {
|
|
146
|
-
|
|
147
|
-
|
|
160
|
+
export type FormOptionCustomRender<O extends boolean = false, C extends boolean = false> = FormOptionBase<O, C> & {
|
|
161
|
+
/** 渲染类型,默认 ReactNode */
|
|
162
|
+
render: ReactNode;
|
|
163
|
+
/** 传递给表单控件的属性,自定义渲染时不需要 */
|
|
164
|
+
componentProps?: never;
|
|
165
|
+
/** 选项数据(用于 select、radio、checkbox),自定义渲染时不需要 */
|
|
166
|
+
items?: never;
|
|
167
|
+
/** 字段键配置,自定义渲染时不需要 */
|
|
168
|
+
itemsField?: never;
|
|
169
|
+
/** checkbox 的栅格数量,自定义渲染时不需要 */
|
|
170
|
+
checkboxCol?: never;
|
|
171
|
+
/** Form.List 独有的属性,自定义渲染时不需要 */
|
|
172
|
+
formListUniqueProps?: never;
|
|
148
173
|
};
|
|
149
174
|
|
|
150
175
|
/**
|
|
151
176
|
* 表单配置项
|
|
152
177
|
*/
|
|
153
178
|
export type FormOption
|
|
154
|
-
= | FormOptionDefault
|
|
155
|
-
|
|
|
156
|
-
|
|
|
179
|
+
= | FormOptionDefault<false, false>
|
|
180
|
+
| FormOptionDefault<false, true>
|
|
181
|
+
| FormOptionDefault<true, false>
|
|
182
|
+
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, false, false> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
183
|
+
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, false, true> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
184
|
+
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, true, false> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
185
|
+
| FormOptionCustomRender<false, false>
|
|
186
|
+
| FormOptionCustomRender<false, true>
|
|
187
|
+
| FormOptionCustomRender<true, false>;
|
|
157
188
|
|
|
158
189
|
/**
|
|
159
190
|
* FormItemsRenderer 组件属性
|
|
@@ -168,7 +199,7 @@ export interface FormItemsRendererProps {
|
|
|
168
199
|
/** 自动生成必填规则,默认 true */
|
|
169
200
|
useAutoGenerateRequired?: boolean;
|
|
170
201
|
/** 初始值,用于在表单未初始化时提供默认值 */
|
|
171
|
-
initialValues?:
|
|
202
|
+
initialValues?: Store;
|
|
172
203
|
/** 栅格间距,继承自 FormBuilder */
|
|
173
204
|
gutter?: Gutter | [Gutter, Gutter];
|
|
174
205
|
/** label 栅格配置,继承自 FormBuilder */
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { FormInstance, FormProps } from "antd/es/form";
|
|
2
|
+
import type { UploadFile } from "antd/es/upload";
|
|
2
3
|
import type { FC, ReactNode } from "react";
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
* 表单值类型
|
|
6
|
-
*/
|
|
7
|
-
export type FormValues = Record<string, any>;
|
|
8
|
-
|
|
9
5
|
export interface ImportFileProps extends Omit<FormProps, "form"> {
|
|
10
6
|
/** 弹窗是否显示 */
|
|
11
7
|
visible: boolean;
|
|
@@ -16,7 +12,7 @@ export interface ImportFileProps extends Omit<FormProps, "form"> {
|
|
|
16
12
|
/** 子组件 */
|
|
17
13
|
children?: ReactNode | ((props: { form: FormInstance }) => ReactNode);
|
|
18
14
|
/** 确认回调 */
|
|
19
|
-
onConfirm: (values:
|
|
15
|
+
onConfirm: (values: { file?: UploadFile[]; [key: string]: any }) => void;
|
|
20
16
|
/** 取消回调 */
|
|
21
17
|
onCancel: () => void;
|
|
22
18
|
/** 导出模板按钮文字,默认 “导出模板” */
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { FormInstance, FormProps } from "antd/es/form";
|
|
2
|
+
import type { Store } from "rc-field-form/lib/interface";
|
|
2
3
|
import type { FC, ReactNode } from "react";
|
|
3
4
|
import type { FormOption } from "../FormBuilder/FormItemsRenderer";
|
|
4
5
|
|
|
5
|
-
type FormValues = Record<string, any>;
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Search 组件属性
|
|
9
8
|
*/
|
|
@@ -11,13 +10,13 @@ export interface SearchProps extends Omit<FormProps, "form" | "onFinish"> {
|
|
|
11
10
|
/** 表单配置项数组 */
|
|
12
11
|
options: FormOption[];
|
|
13
12
|
/** 表单值 */
|
|
14
|
-
values?:
|
|
13
|
+
values?: Store;
|
|
15
14
|
/** 搜索和重置都会触发的回调 */
|
|
16
|
-
onFinish?: (values:
|
|
15
|
+
onFinish?: (values: Store, type: "submit" | "reset") => void;
|
|
17
16
|
/** 搜索回调 */
|
|
18
|
-
onSubmit?: (values:
|
|
17
|
+
onSubmit?: (values: Store) => void;
|
|
19
18
|
/** 重置回调 */
|
|
20
|
-
onReset?: (values:
|
|
19
|
+
onReset?: (values: Store) => void;
|
|
21
20
|
/** 搜索按钮文本,默认"搜索" */
|
|
22
21
|
searchText?: string;
|
|
23
22
|
/** 重置按钮文本,默认"重置" */
|