zy-react-library 1.3.3 → 1.3.4
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.
|
@@ -2,9 +2,13 @@ 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 { NamePath
|
|
5
|
+
import type { NamePath } from "rc-field-form/lib/interface";
|
|
6
6
|
import type { ReactElement, ReactNode } from "react";
|
|
7
7
|
import type { FORM_ITEM_RENDER_TYPE_MAP } from "../../enum/formItemRender";
|
|
8
|
+
import type { DeepPartial } from "./FormBuilder";
|
|
9
|
+
|
|
10
|
+
export type FormListOptionName<Values> = [number, NamePath<Values>];
|
|
11
|
+
export type FormListOptionDependencies<Values> = Array<(NamePath<Values> | number)[]> | NamePath<Values>;
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* 选择项数据类型
|
|
@@ -32,13 +36,13 @@ export interface ItemsFieldConfig {
|
|
|
32
36
|
/**
|
|
33
37
|
* Form.List 操作项
|
|
34
38
|
*/
|
|
35
|
-
export interface FormListOperations {
|
|
39
|
+
export interface FormListOperations<Values = any> {
|
|
36
40
|
/** 当前表单项的数据字段信息 */
|
|
37
41
|
field: FormListFieldData;
|
|
38
42
|
/** 当前项在列表中的索引位置 */
|
|
39
43
|
fieldIndex: number;
|
|
40
44
|
/** 新增方法 */
|
|
41
|
-
add: (defaultValue?:
|
|
45
|
+
add: (defaultValue?: DeepPartial<Values>, insertIndex?: number) => void;
|
|
42
46
|
/** 删除方法 */
|
|
43
47
|
remove: (index: number | number[]) => void;
|
|
44
48
|
/** 移动方法 */
|
|
@@ -48,7 +52,7 @@ export interface FormListOperations {
|
|
|
48
52
|
/**
|
|
49
53
|
* Form.List 独有的属性
|
|
50
54
|
*/
|
|
51
|
-
export interface FormListUniqueProps {
|
|
55
|
+
export interface FormListUniqueProps<Values = any, AllValues = Values> {
|
|
52
56
|
/** 是否显示新增按钮,默认 true */
|
|
53
57
|
showAddButton?: boolean;
|
|
54
58
|
/** 是否显示删除按钮,默认 true */
|
|
@@ -58,9 +62,9 @@ export interface FormListUniqueProps {
|
|
|
58
62
|
/** 删除按钮的文本,默认 '删除' */
|
|
59
63
|
removeButtonText?: string;
|
|
60
64
|
/** 表单配置项 */
|
|
61
|
-
options: (field: FormListFieldData, fieldIndex: number, operations: FormListOperations) => FormListOption[];
|
|
65
|
+
options: (field: FormListFieldData, fieldIndex: number, operations: FormListOperations<Values>) => FormListOption<Values, AllValues>[];
|
|
62
66
|
/** 点击新增按钮时的默认值 */
|
|
63
|
-
addDefaultValue?:
|
|
67
|
+
addDefaultValue?: DeepPartial<Values>;
|
|
64
68
|
/** 点击新增按钮时插入的索引位置 */
|
|
65
69
|
addInsertIndex?: number;
|
|
66
70
|
}
|
|
@@ -78,7 +82,14 @@ type FormOptionProperty<IsOnlyForLabel extends boolean, IsCustomizeRender extend
|
|
|
78
82
|
/**
|
|
79
83
|
* 表单配置项公共字段
|
|
80
84
|
*/
|
|
81
|
-
export interface FormOptionBase<
|
|
85
|
+
export interface FormOptionBase<
|
|
86
|
+
Values = any,
|
|
87
|
+
AllValues = Values,
|
|
88
|
+
IsOnlyForLabel extends boolean = false,
|
|
89
|
+
IsCustomizeRender extends boolean = false,
|
|
90
|
+
Name = NamePath<Values>,
|
|
91
|
+
Dependencies = NamePath<Values>,
|
|
92
|
+
> {
|
|
82
93
|
/** React 需要的 key,如果传递了唯一的 name,则不需要 */
|
|
83
94
|
key?: string;
|
|
84
95
|
/** 表单项字段名 */
|
|
@@ -88,7 +99,7 @@ export interface FormOptionBase<Values = any, IsOnlyForLabel extends boolean = f
|
|
|
88
99
|
/** 占据栅格列数,默认 12 */
|
|
89
100
|
span?: WhenTrue<IsOnlyForLabel, number | string>;
|
|
90
101
|
/** 是否必填,默认 true,支持函数动态计算 */
|
|
91
|
-
required?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, boolean | ((formValues:
|
|
102
|
+
required?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, boolean | ((formValues: AllValues) => boolean)>;
|
|
92
103
|
/** 验证规则 */
|
|
93
104
|
rules?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, Rule | Rule[]>;
|
|
94
105
|
/** 是否使用字符验证限制 */
|
|
@@ -98,19 +109,19 @@ export interface FormOptionBase<Values = any, IsOnlyForLabel extends boolean = f
|
|
|
98
109
|
/** 提示信息,传入将在 label 右侧生成图标展示 tooltip */
|
|
99
110
|
tip?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, ReactNode>;
|
|
100
111
|
/** 是否隐藏,默认 false,支持函数动态计算 */
|
|
101
|
-
hidden?: WhenTrue<IsOnlyForLabel, boolean | ((formValues:
|
|
112
|
+
hidden?: WhenTrue<IsOnlyForLabel, boolean | ((formValues: AllValues) => boolean)>;
|
|
102
113
|
/** 是否自定义渲染,完全交给外部控制渲染,默认 false */
|
|
103
114
|
customizeRender?: IsCustomizeRender;
|
|
104
115
|
/** 传递给 Form.Item 的属性,支持函数动态计算 */
|
|
105
|
-
formItemProps?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, FormItemProps | ((formValues:
|
|
116
|
+
formItemProps?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, FormItemProps | ((formValues: AllValues) => FormItemProps)>;
|
|
106
117
|
/** label 栅格配置,默认直接使用外层的 labelCol,如果 span 等于 24,是外层的 labelCol.span 一半 */
|
|
107
118
|
labelCol?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, ColProps>;
|
|
108
119
|
/** wrapper 栅格配置,默认 24 - labelCol.span */
|
|
109
120
|
wrapperCol?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, ColProps>;
|
|
110
121
|
/** 是否应该更新(用于表单联动) */
|
|
111
|
-
shouldUpdate?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, boolean | ((prevValues:
|
|
122
|
+
shouldUpdate?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, boolean | ((prevValues: AllValues, nextValues: AllValues, info: { source?: string }) => boolean)>;
|
|
112
123
|
/** 依赖字段(用于表单联动) */
|
|
113
|
-
dependencies?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender,
|
|
124
|
+
dependencies?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, Dependencies[]>;
|
|
114
125
|
/** 是否仅用于保存标签,不渲染到页面上,只在表单中保存数据,默认 false */
|
|
115
126
|
onlyForLabel?: IsOnlyForLabel;
|
|
116
127
|
}
|
|
@@ -118,11 +129,19 @@ export interface FormOptionBase<Values = any, IsOnlyForLabel extends boolean = f
|
|
|
118
129
|
/**
|
|
119
130
|
* 按 render 类型区分的表单项
|
|
120
131
|
*/
|
|
121
|
-
export type FormOptionByRender<
|
|
132
|
+
export type FormOptionByRender<
|
|
133
|
+
RenderType extends keyof FORM_ITEM_RENDER_TYPE_MAP,
|
|
134
|
+
Values = any,
|
|
135
|
+
AllValues = Values,
|
|
136
|
+
IsOnlyForLabel extends boolean = false,
|
|
137
|
+
IsCustomizeRender extends boolean = false,
|
|
138
|
+
Name = NamePath<Values>,
|
|
139
|
+
Dependencies = NamePath<Values>,
|
|
140
|
+
> = FormOptionBase<Values, AllValues, IsOnlyForLabel, IsCustomizeRender, Name, Dependencies> & {
|
|
122
141
|
/** 渲染类型(写字面量时 componentProps 会按该类型推导) */
|
|
123
142
|
render: RenderType;
|
|
124
143
|
/** 传递给表单控件的属性,类型由 render 决定 */
|
|
125
|
-
componentProps?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, FORM_ITEM_RENDER_TYPE_MAP[RenderType] | ((formValues:
|
|
144
|
+
componentProps?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, FORM_ITEM_RENDER_TYPE_MAP[RenderType] | ((formValues: AllValues) => FORM_ITEM_RENDER_TYPE_MAP[RenderType])>;
|
|
126
145
|
/** 选项数据(用于 select、radio、checkbox) */
|
|
127
146
|
items?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, RenderType extends "select" | "radio" | "checkbox" ? OptionItem[] : never>;
|
|
128
147
|
/** 字段键配置 */
|
|
@@ -130,17 +149,24 @@ export type FormOptionByRender<RenderType extends keyof FORM_ITEM_RENDER_TYPE_MA
|
|
|
130
149
|
/** checkbox 的栅格数量,如果不传入不使用栅格,传入才使用 */
|
|
131
150
|
checkboxCol?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, RenderType extends "checkbox" ? number : never>;
|
|
132
151
|
/** Form.List 独有的属性 */
|
|
133
|
-
formListUniqueProps?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, RenderType extends "formList" ? FormListUniqueProps | ((formValues:
|
|
152
|
+
formListUniqueProps?: FormOptionProperty<IsOnlyForLabel, IsCustomizeRender, RenderType extends "formList" ? FormListUniqueProps | ((formValues: AllValues) => FormListUniqueProps) : never>;
|
|
134
153
|
};
|
|
135
154
|
|
|
136
155
|
/**
|
|
137
156
|
* 不写 render 或 render 为 input 时的表单项(默认按输入框)
|
|
138
157
|
*/
|
|
139
|
-
export type FormOptionDefault<
|
|
158
|
+
export type FormOptionDefault<
|
|
159
|
+
Values = any,
|
|
160
|
+
AllValues = Values,
|
|
161
|
+
IsOnlyForLabel extends boolean = false,
|
|
162
|
+
IsCustomizeRender extends boolean = false,
|
|
163
|
+
Name = NamePath<Values>,
|
|
164
|
+
Dependencies = NamePath<Values>,
|
|
165
|
+
> = FormOptionBase<Values, AllValues, IsOnlyForLabel, IsCustomizeRender, Name, Dependencies> & {
|
|
140
166
|
/** 渲染类型,默认 input */
|
|
141
167
|
render?: "input" | undefined;
|
|
142
168
|
/** 传递给 Input 的属性 */
|
|
143
|
-
componentProps?: FORM_ITEM_RENDER_TYPE_MAP["input"] | ((formValues:
|
|
169
|
+
componentProps?: FORM_ITEM_RENDER_TYPE_MAP["input"] | ((formValues: AllValues) => FORM_ITEM_RENDER_TYPE_MAP["input"]);
|
|
144
170
|
/** 选项数据(用于 select、radio、checkbox),input 时不需要 */
|
|
145
171
|
items?: never;
|
|
146
172
|
/** 字段键配置,input 时不需要 */
|
|
@@ -154,7 +180,14 @@ export type FormOptionDefault<Values = any, IsOnlyForLabel extends boolean = fal
|
|
|
154
180
|
/**
|
|
155
181
|
* 自定义渲染时的表单项(render 为 ReactNode 时使用)
|
|
156
182
|
*/
|
|
157
|
-
export type FormOptionCustomRender<
|
|
183
|
+
export type FormOptionCustomRender<
|
|
184
|
+
Values = any,
|
|
185
|
+
AllValues = Values,
|
|
186
|
+
IsOnlyForLabel extends boolean = false,
|
|
187
|
+
IsCustomizeRender extends boolean = false,
|
|
188
|
+
Name = NamePath<Values>,
|
|
189
|
+
Dependencies = NamePath<Values>,
|
|
190
|
+
> = FormOptionBase<Values, AllValues, IsOnlyForLabel, IsCustomizeRender, Name, Dependencies> & {
|
|
158
191
|
/** 渲染类型,默认 ReactNode */
|
|
159
192
|
render: ReactNode;
|
|
160
193
|
/** 传递给表单控件的属性,自定义渲染时不需要 */
|
|
@@ -170,32 +203,32 @@ export type FormOptionCustomRender<Values = any, IsOnlyForLabel extends boolean
|
|
|
170
203
|
};
|
|
171
204
|
|
|
172
205
|
/**
|
|
173
|
-
*
|
|
206
|
+
* 普通表单配置项
|
|
174
207
|
*/
|
|
175
|
-
export type FormOption<Values = any>
|
|
176
|
-
= | FormOptionDefault<Values, false, false>
|
|
177
|
-
| FormOptionDefault<Values, false, true>
|
|
178
|
-
| FormOptionDefault<Values, true, false>
|
|
179
|
-
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values, false, false> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
180
|
-
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values, false, true> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
181
|
-
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values, true, false> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
182
|
-
| FormOptionCustomRender<Values, false, false>
|
|
183
|
-
| FormOptionCustomRender<Values, false, true>
|
|
184
|
-
| FormOptionCustomRender<Values, true, false>;
|
|
208
|
+
export type FormOption<Values = any, AllValues = Values>
|
|
209
|
+
= | FormOptionDefault<Values, AllValues, false, false>
|
|
210
|
+
| FormOptionDefault<Values, AllValues, false, true>
|
|
211
|
+
| FormOptionDefault<Values, AllValues, true, false>
|
|
212
|
+
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values, AllValues, false, false> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
213
|
+
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values, AllValues, false, true> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
214
|
+
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values, AllValues, true, false> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
215
|
+
| FormOptionCustomRender<Values, AllValues, false, false>
|
|
216
|
+
| FormOptionCustomRender<Values, AllValues, false, true>
|
|
217
|
+
| FormOptionCustomRender<Values, AllValues, true, false>;
|
|
185
218
|
|
|
186
219
|
/**
|
|
187
|
-
* Form.List
|
|
220
|
+
* Form.List 子项表单配置项
|
|
188
221
|
*/
|
|
189
|
-
export type FormListOption<Values = any>
|
|
190
|
-
= | FormOptionDefault<Values,
|
|
191
|
-
| FormOptionDefault<Values, false, true,
|
|
192
|
-
| FormOptionDefault<Values, true, false,
|
|
193
|
-
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values,
|
|
194
|
-
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values, false, true,
|
|
195
|
-
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values, true, false,
|
|
196
|
-
| FormOptionCustomRender<Values,
|
|
197
|
-
| FormOptionCustomRender<Values, false, true,
|
|
198
|
-
| FormOptionCustomRender<Values, true, false,
|
|
222
|
+
export type FormListOption<Values = any, AllValues = Values>
|
|
223
|
+
= | FormOptionDefault<Values, AllValues, false, false, FormListOptionName<Values>, FormListOptionDependencies<AllValues>>
|
|
224
|
+
| FormOptionDefault<Values, AllValues, false, true, FormListOptionName<Values>, FormListOptionDependencies<AllValues>>
|
|
225
|
+
| FormOptionDefault<Values, AllValues, true, false, FormListOptionName<Values>, FormListOptionDependencies<AllValues>>
|
|
226
|
+
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values, AllValues, false, false, FormListOptionName<Values>, FormListOptionDependencies<AllValues>> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
227
|
+
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values, AllValues, false, true, FormListOptionName<Values>, FormListOptionDependencies<AllValues>> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
228
|
+
| { [K in keyof FORM_ITEM_RENDER_TYPE_MAP]: FormOptionByRender<K, Values, AllValues, true, false, FormListOptionName<Values>, FormListOptionDependencies<AllValues>> }[keyof FORM_ITEM_RENDER_TYPE_MAP]
|
|
229
|
+
| FormOptionCustomRender<Values, AllValues, false, false, FormListOptionName<Values>, FormListOptionDependencies<AllValues>>
|
|
230
|
+
| FormOptionCustomRender<Values, AllValues, false, true, FormListOptionName<Values>, FormListOptionDependencies<AllValues>>
|
|
231
|
+
| FormOptionCustomRender<Values, AllValues, true, false, FormListOptionName<Values>, FormListOptionDependencies<AllValues>>;
|
|
199
232
|
|
|
200
233
|
/**
|
|
201
234
|
* FormItemsRenderer 组件属性
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{InfoCircleOutlined as e}from"@ant-design/icons";import{Input as r,DatePicker as n,Form as t,Col as l,Divider as s,Row as a,Button as o,Checkbox as d,Radio as i,Select as u,InputNumber as p,Tooltip as c}from"antd";import m from"dayjs";import{FORM_ITEM_RENDER_ENUM as h}from"../../enum/formItemRender/index.js";import{jsx as
|
|
1
|
+
import{InfoCircleOutlined as e}from"@ant-design/icons";import{Input as r,DatePicker as n,Form as t,Col as l,Divider as s,Row as a,Button as o,Checkbox as d,Radio as i,Select as u,InputNumber as p,Tooltip as c}from"antd";import m from"dayjs";import{FORM_ITEM_RENDER_ENUM as h}from"../../enum/formItemRender/index.js";import{getDataType as y}from"../../utils/index.js";import{jsx as E,Fragment as f,jsxs as T}from"react/jsx-runtime";const{TextArea:b}=r,{RangePicker:v}=n,I=({options:I,labelCol:A,gutter:R=24,span:Y=12,collapse:D=!1,useAutoGenerateRequired:C=!0,initialValues:N})=>{const w=t.useFormInstance(),M=()=>{const e=w.getFieldsValue();return 0===Object.keys(e).length&&N?N:e},U=e=>"function"==typeof e.componentProps?e.componentProps(M()):e.componentProps||{},P=e=>{const r="function"==typeof e.formItemProps?e.formItemProps(M()):e.formItemProps||{};return[h.DATE,h.DATE_MONTH,h.DATE_YEAR,h.DATETIME].includes(e.render)&&(r.getValueFromEvent=(e,r)=>r,r.getValueProps=e=>({value:e?m(e):void 0})),[h.DATE_WEEK].includes(e.render)&&(r.getValueFromEvent=(e,r)=>r,r.getValueProps=e=>({value:e?m(e,"YYYY-wo"):void 0})),[h.DATE_RANGE,h.DATETIME_RANGE].includes(e.render)&&(r.getValueFromEvent=(e,r)=>r,r.getValueProps=e=>({value:Array.isArray(e)?e.map(e=>e?m(e):void 0):void 0})),r},x=e=>"function"==typeof e?e(M()):e??!0,g=e=>{if(e.render===h.DIVIDER)return[];const r=[];switch(e.render||h.INPUT){case h.INPUT:!1!==e.useConstraints&&r.push({max:50,message:"最多输入50字符"});break;case h.TEXTAREA:!1!==e.useConstraints&&r.push({max:500,message:"最多输入500字符"});break;case h.INPUT_NUMBER:case h.NUMBER:!1!==e.useConstraints&&r.push({pattern:/^(\d+)(\.\d{1,2})?$/,message:"请输入正确的数字,最多保留两位小数"}),!1!==e.useConstraints&&r.push({validator:(e,r)=>r&&Math.abs(Number.parseFloat(r))>999999999?Promise.reject("输入数值超出安全范围"):Promise.resolve()});break;case h.INTEGER:!1!==e.useConstraints&&r.push({pattern:/^(\d+)$/,message:"请输入正确的整数"}),!1!==e.useConstraints&&r.push({validator:(e,r)=>r&&Math.abs(Number.parseFloat(r))>999999999?Promise.reject("输入数值超出安全范围"):Promise.resolve()})}if(!C)return e.rules?Array.isArray(e.rules)?[...e.rules,...r]:[e.rules,...r]:r;if(x(e.required)){const n=!e.render||[h.INPUT,h.TEXTAREA,h.INPUT_NUMBER,h.NUMBER,h.INTEGER].includes(e.render);return r.push({required:!0,message:`${n?"请输入":"请选择"}${e.label}`}),e.rules&&(Array.isArray(e.rules)?r.push(...e.rules):r.push(e.rules)),r}return e.rules?Array.isArray(e.rules)?[...e.rules,...r]:[e.rules,...r]:r},_=e=>e.key||("Array"===y(e.name)?e.name.join("."):e.name),B=e=>{const r=e.render===h.DIVIDER?24:e.span??Y,n=e.labelCol??(24===r?{span:A.span/2}:A);return{span:r,labelCol:n,wrapperCol:e.wrapperCol??{span:24-n.span}}},F=e=>"function"==typeof e?e(M()):e??!1,k=(e,r)=>({value:e[r.valueKey],label:"function"==typeof r.labelKey?r.labelKey(e):e[r.labelKey],disabled:e.disabled}),L=e=>{const t=U(e),s=(e=>({valueKey:e?.itemsField?.valueKey||"bianma",labelKey:e?.itemsField?.labelKey||"name"}))(e),o=e.render??h.INPUT,c=e.placeholder??`请${[h.INPUT,h.TEXTAREA,h.INPUT_NUMBER,h.NUMBER,h.INTEGER].includes(o)?"输入":"选择"}${e.label}`;switch(o){case h.INPUT:return E(r,{placeholder:c,maxLength:!1!==e.useConstraints?50:9999,...t});case h.TEXTAREA:return E(b,{placeholder:c,maxLength:!1!==e.useConstraints?500:9999,showCount:!0,rows:3,...t});case h.INPUT_NUMBER:case h.NUMBER:case h.INTEGER:return E(p,{placeholder:c,style:{width:"100%"},...t});case h.SELECT:return E(u,{placeholder:c,showSearch:!0,allowClear:!0,optionFilterProp:"children",...t,children:(e.items||[]).map(e=>{const{value:r,label:n,disabled:t}=k(e,s);return E(u.Option,{value:r,disabled:t,children:n},r)})});case h.RADIO:return E(i.Group,{...t,children:(e.items||[]).map(e=>{const{value:r,label:n,disabled:t}=k(e,s);return E(i,{value:r,disabled:t,children:n},r)})});case h.CHECKBOX:return E(d.Group,{...t,children:e.checkboxCol?E(a,{children:(e.items||[]).map(r=>{const{value:n,label:t,disabled:a}=k(r,s);return E(l,{span:e.checkboxCol,children:E(d,{value:n,disabled:a,children:t})},n)})}):(e.items||[]).map(e=>{const{value:r,label:n,disabled:t}=k(e,s);return E(d,{value:r,disabled:t,children:n},r)})});case h.DATE:return E(n,{placeholder:c,format:"YYYY-MM-DD",style:{width:"100%"},...t});case h.DATE_MONTH:return E(n,{picker:"month",placeholder:c,format:"YYYY-MM",style:{width:"100%"},...t});case h.DATE_YEAR:return E(n,{picker:"year",placeholder:c,format:"YYYY",style:{width:"100%"},...t});case h.DATE_WEEK:return E(n,{picker:"week",placeholder:c,format:"YYYY-wo",style:{width:"100%"},...t});case h.DATE_RANGE:return E(v,{placeholder:[`请选择开始${e.label}`,`请选择结束${e.label}`],format:"YYYY-MM-DD",style:{width:"100%"},...t});case h.DATETIME:return E(n,{showTime:!0,placeholder:c,format:"YYYY-MM-DD HH:mm:ss",style:{width:"100%"},...t});case h.DATETIME_RANGE:return E(v,{showTime:!0,placeholder:[`请选择开始${e.label}`,`请选择结束${e.label}`],format:"YYYY-MM-DD HH:mm:ss",style:{width:"100%"},...t});case h.DIVIDER:return null;default:return o}},V=r=>r.tip?T(f,{children:[r.label,E(c,{title:r.tip,children:E(e,{style:{marginLeft:4,fontSize:12}})})]}):r.label,$=({option:e,style:r,col:n,index:s,preserve:a})=>{const o=P(e);return delete o.dependencies,delete o.shouldUpdate,F(e.hidden)?null:E(l,{span:n.span,style:r,children:E(t.Item,{name:e.name,label:V(e),rules:g(e),labelCol:n.labelCol,wrapperCol:n.wrapperCol,preserve:a,required:" "!==V(e)&&x(e.required),colon:" "!==V(e),...o,children:L(e)})},_(e)||s)},G=({option:e,style:r,col:n,index:a,preserve:o})=>{const d=U(e);return e.customizeRender?E(l,{span:n.span,style:r,children:e.render},_(e)||a):e.onlyForLabel?E(t.Item,{name:e.name,noStyle:!0,preserve:o,children:E("input",{type:"hidden"})},_(e)||a):e.render===h.DIVIDER?E(l,{span:n.span,style:r,children:E(s,{orientation:"left",...d,children:e.label})},_(e)||a):null},K=({option:e,index:r,style:n,col:l,preserve:s})=>{const a=P(e);return E(t.Item,{noStyle:!0,preserve:s,shouldUpdate:e.shouldUpdate??a.shouldUpdate,dependencies:e.dependencies??a.dependencies,children:()=>$({option:e,style:n,col:l,index:r,preserve:s})},_(e)||r)},q=({option:e,index:r,col:n,style:s})=>{const d=(e=>{const r={showAddButton:!0,showRemoveButton:!0,addButtonText:"添加",removeButtonText:"删除",options:[],addDefaultValue:{},addInsertIndex:void 0};return"function"==typeof e.formListUniqueProps?{...r,...e.formListUniqueProps(M())}:{...r,...e.formListUniqueProps||{}}})(e),i=U(e);return E(l,{span:n.span,style:s,children:E(t.List,{name:e.name,...i,children:(e,{add:r,remove:n,move:i})=>E(f,{children:e.map((e,u)=>{const p=((e,r,n,t,l,s)=>"function"==typeof e?e(r,n,{field:r,fieldIndex:n,add:t,remove:l,move:s}):e??[])(d.options,e,u,r,n,i);return E(a,{gutter:R,children:p.map((a,i)=>{if(F(a.hidden))return null;const c=B(a),m=P(a),y={option:a,style:s,col:c,index:`${u}_${i}`,preserve:!0},f=G(y);if(f)return f;if(a.render===h.FORM_LIST)return q(y);if((a.shouldUpdate??a.dependencies)||(m.shouldUpdate??m.dependencies))return K(y);const b=e=>!F(e.hidden)&&!e.onlyForLabel,v=p[i+1],I=v&&v.render===h.FORM_LIST,A=v&&!b(v);return i===(()=>{for(let e=p.length-1;e>=0;e--){const r=p[e];if(r.render===h.FORM_LIST)return e;if(b(r))return e}return-1})()||I||A?(delete m.dependencies,delete m.shouldUpdate,E(l,{span:c.span,style:s,children:E(t.Item,{label:V(a),labelCol:c.labelCol,wrapperCol:c.wrapperCol,preserve:!1,required:" "!==V(a)&&x(a.required),colon:" "!==V(a),...m,children:T("div",{style:{display:"flex",gap:10,alignItems:"center",justifyContent:"space-between"},children:[E("div",{style:{flex:1},children:E(t.Item,{noStyle:!0,rules:g(a),name:a.name,children:L(a)})}),u>=1?d.showRemoveButton&&E(o,{type:"primary",danger:!0,onClick:()=>n(e.name),children:d.removeButtonText}):d.showAddButton&&E(o,{type:"primary",onClick:()=>r(d.addDefaultValue,d.addInsertIndex),children:d.addButtonText})]})})},_(a)||i)):$(y)})},e.key)})})})},_(e)||r)};return E(f,{children:I.map((e,r)=>{const n=B(e),t=(e=>D&&e>=3?{display:"none"}:void 0)(r),l=P(e),s={option:e,style:t,col:n,index:r,preserve:!1};return G(s)||(e.render===h.FORM_LIST?q(s):(e.shouldUpdate??e.dependencies)||(l.shouldUpdate??l.dependencies)?K(s):$(s))})})};I.displayName="FormItemsRenderer";export{I as default};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { FormOption } from "./FormItemsRenderer";
|
|
1
|
+
import type { FormListOption, FormListUniqueProps, FormOption } from "./FormItemsRenderer";
|
|
2
|
+
|
|
2
3
|
import FormBuilder from "./FormBuilder";
|
|
3
4
|
|
|
4
|
-
export type { FormOption };
|
|
5
|
+
export type { FormListOption, FormListUniqueProps, FormOption };
|
|
5
6
|
|
|
6
7
|
export default FormBuilder;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { FormInstance, FormProps } from "antd/es/form";
|
|
2
2
|
import type { ReactElement, ReactNode } from "react";
|
|
3
|
-
import type { FormOption } from "../FormBuilder";
|
|
3
|
+
import type { FormListOption, FormListUniqueProps, FormOption } from "../FormBuilder";
|
|
4
4
|
import type { DeepPartial } from "../FormBuilder/FormBuilder";
|
|
5
5
|
|
|
6
|
-
export type { FormOption };
|
|
6
|
+
export type { FormListOption, FormListUniqueProps, FormOption };
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Search 组件属性
|