zy-react-library 1.0.14 → 1.0.16
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/components/FormBuilder/FormBuilder.js +1 -0
- package/components/FormBuilder/FormItemsRenderer.d.ts +3 -1
- package/components/FormBuilder/FormItemsRenderer.js +23 -7
- package/components/Search/index.js +1 -0
- package/components/Table/index.js +2 -1
- package/components/Table/index.less +3 -0
- package/package.json +1 -1
|
@@ -9,7 +9,7 @@ import type { FORM_ITEM_RENDER_ENUM } from "../../enum/formItemRender";
|
|
|
9
9
|
*/
|
|
10
10
|
export type FormItemRenderType
|
|
11
11
|
= | (typeof FORM_ITEM_RENDER_ENUM)[keyof typeof FORM_ITEM_RENDER_ENUM]
|
|
12
|
-
| ((props: any) => ReactNode);
|
|
12
|
+
| ((props: { formValues: FormValues; [key: string]: any }) => ReactNode);
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* 选项项数据类型
|
|
@@ -91,6 +91,8 @@ export interface FormItemsRendererProps {
|
|
|
91
91
|
collapse?: boolean;
|
|
92
92
|
/** 自动生成必填规则,默认 true */
|
|
93
93
|
useAutoGenerateRequired?: boolean;
|
|
94
|
+
/** 初始值,用于在表单未初始化时提供默认值 */
|
|
95
|
+
initialValues?: FormValues;
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
/**
|
|
@@ -26,20 +26,31 @@ const FormItemsRenderer = ({
|
|
|
26
26
|
span = 12,
|
|
27
27
|
collapse = false,
|
|
28
28
|
useAutoGenerateRequired = true,
|
|
29
|
+
initialValues,
|
|
29
30
|
}) => {
|
|
30
31
|
const form = Form.useFormInstance();
|
|
31
32
|
|
|
33
|
+
// 获取表单值,优先使用 initialValues
|
|
34
|
+
const getFormValues = () => {
|
|
35
|
+
const formValues = form.getFieldsValue();
|
|
36
|
+
// 如果表单值为空但有 initialValues,则使用 initialValues
|
|
37
|
+
if (Object.keys(formValues).length === 0 && initialValues) {
|
|
38
|
+
return initialValues;
|
|
39
|
+
}
|
|
40
|
+
return formValues;
|
|
41
|
+
};
|
|
42
|
+
|
|
32
43
|
// 获取传给组件的属性
|
|
33
44
|
const getComponentProps = (option) => {
|
|
34
45
|
return typeof option.componentProps === "function"
|
|
35
|
-
? option.componentProps(
|
|
46
|
+
? option.componentProps(getFormValues())
|
|
36
47
|
: (option.componentProps || {});
|
|
37
48
|
};
|
|
38
49
|
|
|
39
50
|
// 获取传给formItem的属性
|
|
40
51
|
const getFormItemProps = (option) => {
|
|
41
52
|
const formItemProps = typeof option.formItemProps === "function"
|
|
42
|
-
? option.formItemProps(
|
|
53
|
+
? option.formItemProps(getFormValues())
|
|
43
54
|
: (option.formItemProps || {});
|
|
44
55
|
|
|
45
56
|
// 为日期组件添加特殊处理
|
|
@@ -90,7 +101,7 @@ const FormItemsRenderer = ({
|
|
|
90
101
|
|
|
91
102
|
// 支持动态计算 required
|
|
92
103
|
const required = typeof option.required === "function"
|
|
93
|
-
? option.required(
|
|
104
|
+
? option.required(getFormValues())
|
|
94
105
|
: (option.required ?? true);
|
|
95
106
|
|
|
96
107
|
if (required) {
|
|
@@ -237,7 +248,7 @@ const FormItemsRenderer = ({
|
|
|
237
248
|
// 支持传入自定义组件
|
|
238
249
|
if (typeof render === "function") {
|
|
239
250
|
const CustomComponent = render;
|
|
240
|
-
return <CustomComponent {...componentProps} />;
|
|
251
|
+
return <CustomComponent {...componentProps} formValues={getFormValues()} />;
|
|
241
252
|
}
|
|
242
253
|
return <Input placeholder={placeholder} {...componentProps} />;
|
|
243
254
|
}
|
|
@@ -290,10 +301,10 @@ const FormItemsRenderer = ({
|
|
|
290
301
|
shouldUpdate={option.shouldUpdate ?? option?.componentProps?.shouldUpdate}
|
|
291
302
|
dependencies={option.dependencies || option?.componentProps?.dependencies}
|
|
292
303
|
>
|
|
293
|
-
{(
|
|
304
|
+
{() => {
|
|
294
305
|
// 支持动态计算 hidden
|
|
295
306
|
const hidden = typeof option.hidden === "function"
|
|
296
|
-
? option.hidden(
|
|
307
|
+
? option.hidden(getFormValues())
|
|
297
308
|
: (option.hidden ?? false);
|
|
298
309
|
|
|
299
310
|
if (hidden)
|
|
@@ -319,7 +330,12 @@ const FormItemsRenderer = ({
|
|
|
319
330
|
}
|
|
320
331
|
|
|
321
332
|
// 普通表单项(静态配置)
|
|
322
|
-
|
|
333
|
+
// 支持动态计算 hidden
|
|
334
|
+
const hidden = typeof option.hidden === "function"
|
|
335
|
+
? option.hidden(getFormValues())
|
|
336
|
+
: (option.hidden ?? false);
|
|
337
|
+
|
|
338
|
+
if (hidden)
|
|
323
339
|
return null;
|
|
324
340
|
|
|
325
341
|
return (
|
|
@@ -84,6 +84,7 @@ const Search = (props) => {
|
|
|
84
84
|
span={6}
|
|
85
85
|
collapse={collapse}
|
|
86
86
|
useAutoGenerateRequired={false}
|
|
87
|
+
initialValues={values}
|
|
87
88
|
/>
|
|
88
89
|
<Col span={showCollapseButton ? (collapse ? 6 : span) : span}>
|
|
89
90
|
<Form.Item label=" " colon={false} style={{ textAlign: "right" }}>
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import Table from "@cqsjjb/jjb-react-admin-component/Table";
|
|
2
2
|
import { getIndexColumn } from "../../utils/index";
|
|
3
|
+
import "./index.less";
|
|
3
4
|
|
|
4
5
|
function TablePro(props) {
|
|
5
6
|
const {
|
|
6
7
|
columns = [],
|
|
7
8
|
showIndex = true,
|
|
8
9
|
useAlignCenter = true,
|
|
9
|
-
rowKey =
|
|
10
|
+
rowKey = "id",
|
|
10
11
|
...restProps
|
|
11
12
|
} = props;
|
|
12
13
|
|