zy-react-library 1.0.50 → 1.0.52

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.
@@ -4,26 +4,12 @@ import type { NamePath } from "rc-field-form/lib/interface";
4
4
  import type { FC, ReactNode } from "react";
5
5
  import type { FORM_ITEM_RENDER_ENUM } from "../../enum/formItemRender";
6
6
 
7
- /**
8
- * 自定义渲染组件的属性
9
- */
10
- export interface CustomRenderProps {
11
- /** 表单当前值 */
12
- formValues: FormValues;
13
- /** 字段值 */
14
- value?: any;
15
- /** 值变化回调 */
16
- onChange?: (value: any) => void;
17
- /** 其他属性 */
18
- [key: string]: any;
19
- }
20
-
21
7
  /**
22
8
  * 表单项渲染类型
23
9
  */
24
10
  export type FormItemRenderType
25
11
  = | (typeof FORM_ITEM_RENDER_ENUM)[keyof typeof FORM_ITEM_RENDER_ENUM]
26
- | ((props: CustomRenderProps) => ReactNode);
12
+ | ReactNode;
27
13
 
28
14
  /**
29
15
  * 选项项数据类型
@@ -55,6 +41,8 @@ export type FormValues = Record<string, any>;
55
41
  * 表单配置项
56
42
  */
57
43
  export interface FormOption {
44
+ /** React 需要的 key,如果传递了唯一的 name,则不需要 */
45
+ key?: string;
58
46
  /** 表单项字段名 */
59
47
  name?: string | string[];
60
48
  /** 表单项标签 */
@@ -133,6 +133,11 @@ const FormItemsRenderer = ({
133
133
  return option.rules ? (Array.isArray(option.rules) ? option.rules : [option.rules]) : [];
134
134
  };
135
135
 
136
+ // 获取key
137
+ const getKey = (option) => {
138
+ return option.key || option.name
139
+ }
140
+
136
141
  // 渲染表单控件
137
142
  const renderFormControl = (option) => {
138
143
  const componentProps = getComponentProps(option);
@@ -245,15 +250,7 @@ const FormItemsRenderer = ({
245
250
  return null;
246
251
 
247
252
  default:
248
- // 支持传入自定义组件
249
- if (typeof render === "function" || typeof render === "object") {
250
- const CustomComponent = render;
251
- if (typeof render === "function")
252
- return <CustomComponent {...componentProps} formValues={getFormValues()} />;
253
- if (typeof render === "object")
254
- return <CustomComponent {...componentProps} />;
255
- }
256
- return <Input placeholder={placeholder} {...componentProps} />;
253
+ return render;
257
254
  }
258
255
  };
259
256
 
@@ -286,7 +283,7 @@ const FormItemsRenderer = ({
286
283
  // 如果是分割线
287
284
  if (option.render === FORM_ITEM_RENDER_ENUM.DIVIDER) {
288
285
  return (
289
- <Col key={option.name || index} span={itemSpan} style={style}>
286
+ <Col key={getKey(option) || index} span={itemSpan} style={style}>
290
287
  <Divider orientation="left">{option.label}</Divider>
291
288
  </Col>
292
289
  );
@@ -299,7 +296,7 @@ const FormItemsRenderer = ({
299
296
  ? (renderFormControl(option))
300
297
  : (
301
298
  <Form.Item
302
- key={option.name || index}
299
+ key={getKey(option) || index}
303
300
  noStyle
304
301
  preserve={false}
305
302
  shouldUpdate={option.shouldUpdate ?? option?.componentProps?.shouldUpdate}
@@ -315,7 +312,7 @@ const FormItemsRenderer = ({
315
312
  return null;
316
313
 
317
314
  return (
318
- <Col key={option.name || index} span={itemSpan} style={style}>
315
+ <Col key={getKey(option) || index} span={itemSpan} style={style}>
319
316
  <Form.Item
320
317
  name={option.name}
321
318
  label={renderLabel(option)}
@@ -345,7 +342,7 @@ const FormItemsRenderer = ({
345
342
  return null;
346
343
 
347
344
  return (
348
- <Col key={option.name || index} span={itemSpan} style={style}>
345
+ <Col key={getKey(option) || index} span={itemSpan} style={style}>
349
346
  {
350
347
  option.customizeRender
351
348
  ? (renderFormControl(option))
@@ -1,12 +1,14 @@
1
1
  import type { FC } from "react";
2
2
  import type { BasicLeftTreeProps } from "../../Basic";
3
3
 
4
+ /**
5
+ * 请求参数
6
+ */
4
7
  export interface Params {
5
8
  /** 企业id */
6
9
  eqCorpinfoId?: string;
7
10
  /** 父级部门id */
8
11
  eqParentId?: string;
9
- [key: string]: any;
10
12
  }
11
13
 
12
14
  /**
@@ -1,32 +1,32 @@
1
- import { request } from "@cqsjjb/jjb-common-lib/http";
2
- import { useEffect, useState } from "react";
3
- import BasicLeftTree from "../../Basic";
4
-
5
- /**
6
- * 部门左侧树组件(港务局版本)
7
- */
8
- function DepartmentLeftTree(props) {
9
- const {
10
- params = {},
11
- ...restProps
12
- } = props;
13
-
14
- const [treeData, setTreeData] = useState([]);
15
-
16
- const getData = async () => {
17
- const { data } = await request("/basic-info/department/listTree", "post", params);
18
- setTreeData(data);
19
- };
20
-
21
- useEffect(() => {
22
- getData();
23
- }, []);
24
-
25
- return (
26
- <BasicLeftTree treeData={treeData} {...restProps} />
27
- );
28
- }
29
-
30
- DepartmentLeftTree.displayName = "DepartmentLeftTree";
31
-
32
- export default DepartmentLeftTree;
1
+ import { request } from "@cqsjjb/jjb-common-lib/http";
2
+ import { useEffect, useState } from "react";
3
+ import BasicLeftTree from "../../Basic";
4
+
5
+ /**
6
+ * 部门左侧树组件(港务局版本)
7
+ */
8
+ function DepartmentLeftTree(props) {
9
+ const {
10
+ params = {},
11
+ ...restProps
12
+ } = props;
13
+
14
+ const [treeData, setTreeData] = useState([]);
15
+
16
+ const getData = async () => {
17
+ const { data } = await request("/basic-info/department/listTree", "post", params);
18
+ setTreeData(data);
19
+ };
20
+
21
+ useEffect(() => {
22
+ getData();
23
+ }, []);
24
+
25
+ return (
26
+ <BasicLeftTree treeData={treeData} {...restProps} />
27
+ );
28
+ }
29
+
30
+ DepartmentLeftTree.displayName = "DepartmentLeftTree";
31
+
32
+ export default DepartmentLeftTree;
@@ -38,7 +38,7 @@ const Map = (props) => {
38
38
  </Form.Item>
39
39
  </Col>
40
40
  <Col span={12}>
41
- <Form.Item label="纬度" required={required} rules={[{ required, message: "请选择纬度" }]}>
41
+ <Form.Item label="纬度" required={required}>
42
42
  <div style={{ display: "flex", gap: 10 }}>
43
43
  <Form.Item name={latitudeProps} noStyle rules={[{ required, message: "请选择纬度" }]}>
44
44
  <Input disabled />
@@ -0,0 +1,23 @@
1
+ import type { SelectProps } from "antd/es/select";
2
+ import type { FC } from "react";
3
+
4
+ /**
5
+ * 组件属性
6
+ */
7
+ export interface BasicSelectProps extends SelectProps {
8
+ /** 数据源 */
9
+ data: Record<string, any>[];
10
+ /** 数据 label 字段,默认 name */
11
+ nameKey?: string;
12
+ /** 数据 value 字段,默认 id */
13
+ idKey?: string;
14
+ /** 占位符 */
15
+ placeholder?: string;
16
+ }
17
+
18
+ /**
19
+ * 基础下拉组件(不建议直接使用此组件,二次继承使用)
20
+ */
21
+ declare const BasicSelectTree: FC<BasicSelectProps>;
22
+
23
+ export default BasicSelectTree;
@@ -0,0 +1,32 @@
1
+ import { Select } from "antd";
2
+
3
+ /**
4
+ * 基础下拉组件(不建议直接使用此组件,二次继承使用)
5
+ */
6
+ function BasicSelect(props) {
7
+ const {
8
+ placeholder = "",
9
+ data = [],
10
+ nameKey = "name",
11
+ idKey = "id",
12
+ ...restProps
13
+ } = props;
14
+
15
+ return (
16
+ <Select placeholder={`请选择${placeholder}`} showSearch allowClear {...restProps}>
17
+ {data.map((item) => {
18
+ const value = item[idKey];
19
+ const label = item[nameKey];
20
+ return (
21
+ <Select.Option key={value} value={value}>
22
+ {label}
23
+ </Select.Option>
24
+ );
25
+ })}
26
+ </Select>
27
+ );
28
+ }
29
+
30
+ BasicSelect.displayName = "BasicSelect";
31
+
32
+ export default BasicSelect;
@@ -0,0 +1,37 @@
1
+ import type { FC } from "react";
2
+ import type { BasicSelectProps } from "../../Basic";
3
+
4
+ /**
5
+ * 请求参数
6
+ */
7
+ export interface Params {
8
+ /** 企业id */
9
+ corpinfoId?: string;
10
+ /** 岗位id */
11
+ postId?: string;
12
+ /** 部门id */
13
+ departmentId?: string;
14
+ }
15
+
16
+ /**
17
+ * 组件属性
18
+ */
19
+ export interface DepartmentSelectProps extends Omit<BasicSelectProps, "data"> {
20
+ /** 请求参数 */
21
+ params?: Params;
22
+ /** 占位符,默认"人员" */
23
+ placeholder?: string;
24
+ /** 是否需要企业id,默认 false */
25
+ isNeedCorpInfoId?: boolean;
26
+ /** 是否需要岗位id,默认 false */
27
+ isNeedPostId?: boolean;
28
+ /** 是否需要部门id,默认 true */
29
+ isNeedDepartmentId?: boolean;
30
+ }
31
+
32
+ /**
33
+ * 基础下拉组件(港务局版本)
34
+ */
35
+ declare const DepartmentSelect: FC<DepartmentSelectProps>;
36
+
37
+ export default DepartmentSelect;
@@ -0,0 +1,45 @@
1
+ import { request } from "@cqsjjb/jjb-common-lib/http";
2
+ import { useEffect, useState } from "react";
3
+ import BasicSelect from "~/components/Select/Basic";
4
+
5
+ /**
6
+ * 基础下拉组件(港务局版本)
7
+ */
8
+ function PersonnelSelect(props) {
9
+ const {
10
+ params = {},
11
+ placeholder = "人员",
12
+ isNeedCorpInfoId = false,
13
+ isNeedDepartmentId = true,
14
+ isNeedPostId = false,
15
+ ...restProps
16
+ } = props;
17
+
18
+ const [data, setData] = useState([]);
19
+
20
+ const getData = async () => {
21
+ setData([]);
22
+ // 根据参数决定是否发送请求
23
+ if (isNeedCorpInfoId && !params.corpinfoId)
24
+ return;
25
+ if (isNeedDepartmentId && !params.departmentId)
26
+ return;
27
+ if (isNeedPostId && !params.postId)
28
+ return;
29
+
30
+ const { data } = await request("/basic-info/user/listAll", "get", params);
31
+ setData(data);
32
+ };
33
+
34
+ useEffect(() => {
35
+ getData();
36
+ }, [JSON.stringify(params), isNeedCorpInfoId, isNeedDepartmentId, isNeedPostId]);
37
+
38
+ return (
39
+ <BasicSelect data={data} placeholder={placeholder} {...restProps} />
40
+ );
41
+ }
42
+
43
+ PersonnelSelect.displayName = "PersonnelSelect";
44
+
45
+ export default PersonnelSelect;
@@ -11,7 +11,6 @@ function SelectCreate(props) {
11
11
  label = "",
12
12
  maxCount = 1,
13
13
  onDelete,
14
- formValues,
15
14
  ...restProps
16
15
  } = props;
17
16
 
@@ -15,6 +15,8 @@ export interface BasicSelectTreeProps extends TreeSelectProps {
15
15
  onGetNodePathsIsIncludeOneself?: boolean;
16
16
  /** 获取父级节点 */
17
17
  onGetNodePaths?: (nodes: Record<string, any>[]) => void;
18
+ /** 占位符 */
19
+ placeholder?: string;
18
20
  }
19
21
 
20
22
  /**
@@ -11,7 +11,6 @@ function BasicSelectTree(props) {
11
11
  nameKey = "name",
12
12
  idKey = "id",
13
13
  childrenKey = "childrenList",
14
- formValues,
15
14
  ...restProps
16
15
  } = props;
17
16
 
@@ -5,13 +5,19 @@ import { Params } from "../../../LeftTree/Department/Gwj";
5
5
  /**
6
6
  * 组件属性
7
7
  */
8
- export interface DepartmentSelectTreeProps extends Omit<BasicSelectTreeProps, "treeData" | "placeholder"> {
8
+ export interface DepartmentSelectTreeProps extends Omit<BasicSelectTreeProps, "treeData"> {
9
9
  /** 请求参数 */
10
10
  params?: Params;
11
+ /** 占位符,默认"部门“ */
12
+ placeholder?: string;
13
+ /** 是否需要企业id,默认 false */
14
+ isNeedCorpInfoId?: boolean;
15
+ /** 是否需要父级部门id,默认 false */
16
+ isNeedParentId?: boolean;
11
17
  }
12
18
 
13
19
  /**
14
- * 部门下拉树组件(港务局版本)
20
+ * 基础下拉树组件(港务局版本)
15
21
  */
16
22
  declare const DepartmentSelectTree: FC<DepartmentSelectTreeProps>;
17
23
 
@@ -3,27 +3,38 @@ import { useEffect, useState } from "react";
3
3
  import BasicLeftTree from "../../Basic";
4
4
 
5
5
  /**
6
- * 部门左侧树组件(港务局版本)
6
+ * 基础下拉树组件(港务局版本)
7
7
  */
8
8
  function DepartmentSelectTree(props) {
9
9
  const {
10
10
  params = {},
11
+ placeholder = "部门",
12
+ isNeedCorpInfoId = false,
13
+ isNeedParentId = false,
11
14
  ...restProps
12
15
  } = props;
13
16
 
14
17
  const [treeData, setTreeData] = useState([]);
15
18
 
16
19
  const getData = async () => {
20
+ setTreeData([]);
21
+
22
+ // 根据参数决定是否发送请求
23
+ if (isNeedCorpInfoId && !params.eqCorpinfoId)
24
+ return;
25
+ if (isNeedParentId && !params.eqParentId)
26
+ return;
27
+
17
28
  const { data } = await request("/basic-info/department/listTree", "post", params);
18
29
  setTreeData(data);
19
30
  };
20
31
 
21
32
  useEffect(() => {
22
33
  getData();
23
- }, []);
34
+ }, [JSON.stringify(params), isNeedCorpInfoId, isNeedParentId]);
24
35
 
25
36
  return (
26
- <BasicLeftTree treeData={treeData} placeholder="部门" {...restProps} />
37
+ <BasicLeftTree treeData={treeData} placeholder={placeholder} {...restProps} />
27
38
  );
28
39
  }
29
40
 
@@ -20,7 +20,6 @@ const Upload = (props) => {
20
20
  tipContent,
21
21
  uploadButtonText: externalUploadButtonText,
22
22
  fileType: externalFileType,
23
- formValues,
24
23
  ...restProps
25
24
  } = props;
26
25
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "1.0.50",
4
+ "version": "1.0.52",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",