zy-react-library 1.0.13 → 1.0.15

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.
@@ -47,6 +47,7 @@ const FormBuilder = (props) => {
47
47
  labelCol={labelCol}
48
48
  span={span}
49
49
  useAutoGenerateRequired={useAutoGenerateRequired}
50
+ initialValues={values}
50
51
  />
51
52
  </Row>
52
53
  {showActionButtons && (
@@ -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(form.getFieldsValue())
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(form.getFieldsValue())
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(form.getFieldsValue())
104
+ ? option.required(getFormValues())
94
105
  : (option.required ?? true);
95
106
 
96
107
  if (required) {
@@ -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
- {(form) => {
304
+ {() => {
294
305
  // 支持动态计算 hidden
295
306
  const hidden = typeof option.hidden === "function"
296
- ? option.hidden(form.getFieldsValue())
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
- if (option.hidden)
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 (
@@ -1,4 +1,4 @@
1
- import type { FC, ReactNode } from "react";
1
+ import type { CSSProperties, FC, ReactNode } from "react";
2
2
 
3
3
  export interface HeaderBackProps {
4
4
  /** 标题 */
@@ -10,6 +10,8 @@ export interface HeaderBackProps {
10
10
  };
11
11
  /** 是否显示返回按钮,默认为 true */
12
12
  previous?: boolean;
13
+ /** 自定义样式 */
14
+ style?: CSSProperties;
13
15
  }
14
16
 
15
17
  /** 头部返回组件 */
@@ -6,10 +6,10 @@ import "./index.less";
6
6
  * 头部返回组件
7
7
  */
8
8
  function HeaderBack(props) {
9
- const { title, history, previous = true } = props;
9
+ const { title, history, previous = true, style = {} } = props;
10
10
 
11
11
  return (
12
- <div className="header-back">
12
+ <div className="header-back" style={style}>
13
13
  <div className="action">
14
14
  {
15
15
  previous
@@ -1,6 +1,7 @@
1
1
  .header-back {
2
2
  padding: 10px 20px;
3
3
  border-bottom: 1px solid #dcdfe6;
4
+ margin-bottom: 10px;
4
5
 
5
6
  .action {
6
7
  display: flex;
@@ -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 = 'id',
10
+ rowKey = "id",
10
11
  ...restProps
11
12
  } = props;
12
13
 
@@ -0,0 +1,3 @@
1
+ .@{ant-prefix}-table-cell-scrollbar {
2
+ width: 15px;
3
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "1.0.13",
4
+ "version": "1.0.15",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",