zy-react-library 1.0.68 → 1.0.70

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.
Files changed (36) hide show
  1. package/components/Cascader/Area/index.d.ts +1 -1
  2. package/components/Cascader/Area/index.js +1 -8
  3. package/components/Cascader/Basic/index.d.ts +2 -2
  4. package/components/Cascader/Basic/index.js +1 -1
  5. package/components/Cascader/Dictionary/index.d.ts +23 -0
  6. package/components/Cascader/Dictionary/index.js +40 -0
  7. package/components/FormBuilder/FormBuilder.d.ts +2 -0
  8. package/components/FormBuilder/FormBuilder.js +42 -39
  9. package/components/LeftTree/Area/index.d.ts +16 -0
  10. package/components/LeftTree/Area/index.js +15 -0
  11. package/components/LeftTree/Basic/index.d.ts +2 -2
  12. package/components/LeftTree/Basic/index.js +1 -1
  13. package/components/LeftTree/Department/Gwj/index.d.ts +1 -1
  14. package/components/LeftTree/Department/Gwj/index.js +1 -1
  15. package/components/LeftTree/Dictionary/index.d.ts +23 -0
  16. package/components/LeftTree/Dictionary/index.js +40 -0
  17. package/components/Map/MapSelector.d.ts +17 -1
  18. package/components/Map/MapSelector.js +23 -9
  19. package/components/Map/index.d.ts +9 -2
  20. package/components/Map/index.js +7 -3
  21. package/components/Select/Dictionary/index.d.ts +23 -0
  22. package/components/Select/Dictionary/index.js +40 -0
  23. package/components/Select/Personnel/Gwj/index.d.ts +1 -1
  24. package/components/SelectTree/Area/index.d.ts +1 -1
  25. package/components/SelectTree/Area/index.js +0 -1
  26. package/components/SelectTree/Basic/index.d.ts +2 -2
  27. package/components/SelectTree/Basic/index.js +6 -6
  28. package/components/SelectTree/Department/Gwj/index.d.ts +1 -1
  29. package/components/SelectTree/Department/Gwj/index.js +1 -1
  30. package/components/SelectTree/Dictionary/index.d.ts +23 -0
  31. package/components/SelectTree/Dictionary/index.js +40 -0
  32. package/enum/dictionary/index.js +7 -0
  33. package/enum/uploadFile/gwj/index.js +2 -0
  34. package/hooks/useDictionary/index.d.ts +24 -0
  35. package/hooks/useDictionary/index.js +50 -0
  36. package/package.json +1 -1
@@ -4,7 +4,7 @@ import type { BasicCascaderProps } from "../Basic";
4
4
  /**
5
5
  * 组件属性
6
6
  */
7
- export interface AreaCascaderProps extends Omit<BasicCascaderProps, "options"> {
7
+ export interface AreaCascaderProps extends Omit<BasicCascaderProps, "options" | "placeholder" | "nameKey" | "idKey" | "childrenKey"> {
8
8
  /** 占位符,默认为"属地" */
9
9
  placeholder?: string;
10
10
  }
@@ -11,14 +11,7 @@ function AreaCascader(props) {
11
11
  } = props;
12
12
 
13
13
  return (
14
- <BasicCascader
15
- data={Area}
16
- placeholder={placeholder}
17
- nameKey="label"
18
- idKey="value"
19
- childrenKey="children"
20
- {...restProps}
21
- />
14
+ <BasicCascader data={Area} placeholder={placeholder} nameKey="label" idKey="value" {...restProps} />
22
15
  );
23
16
  }
24
17
 
@@ -4,12 +4,12 @@ import type { FC } from "react";
4
4
  /**
5
5
  * 组件属性
6
6
  */
7
- export interface BasicCascaderProps extends CascaderProps {
7
+ export interface BasicCascaderProps extends Omit<CascaderProps, "fieldNames"> {
8
8
  /** 树形数据 label 字段,默认 name */
9
9
  nameKey?: string;
10
10
  /** 树形数据 value 字段,默认 id */
11
11
  idKey?: string;
12
- /** 树形数据 children 字段,默认 childrenList */
12
+ /** 树形数据 children 字段,默认 children */
13
13
  childrenKey?: string;
14
14
  /** 决定 onGetNodePaths 是否包含自身节点,默认 true */
15
15
  onGetNodePathsIsIncludeOneself?: boolean;
@@ -15,7 +15,7 @@ function BasicCascader(props) {
15
15
  data = [],
16
16
  nameKey = "name",
17
17
  idKey = "id",
18
- childrenKey = "childrenList",
18
+ childrenKey = "children",
19
19
  level,
20
20
  ...restProps
21
21
  } = props;
@@ -0,0 +1,23 @@
1
+ import type { FC } from "react";
2
+ import type { BasicCascaderProps } from "../Basic";
3
+
4
+ /**
5
+ * 组件属性
6
+ */
7
+ export interface DictionarySelectTreeProps extends Omit<BasicCascaderProps, "options" | "nameKey" | "idKey" | "childrenKey"> {
8
+ /** appKey,默认 DICTIONARY_APP_KEY_ENUM.DEFAULT(0bb989ecada5470c87635018ece9f327) */
9
+ appKey?: string;
10
+ /** 要获取的字典 */
11
+ dictValue: string;
12
+ /** 树形数据 label 字段,默认 dictLabel */
13
+ nameKey?: string;
14
+ /** 树形数据 value 字段,默认 dictValue */
15
+ idKey?: string;
16
+ }
17
+
18
+ /**
19
+ * 数据字典级联组件
20
+ */
21
+ declare const DictionarySelectTree: FC<DictionarySelectTreeProps>;
22
+
23
+ export default DictionarySelectTree;
@@ -0,0 +1,40 @@
1
+ import { request } from "@cqsjjb/jjb-common-lib/http";
2
+ import { useEffect, useState } from "react";
3
+ import { DICTIONARY_APP_KEY_ENUM } from "../../../enum/dictionary";
4
+ import BasicCascader from "../Basic";
5
+
6
+ /**
7
+ * 数据字典级联组件
8
+ */
9
+ function DictionarySelectTree(props) {
10
+ const {
11
+ appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT,
12
+ dictValue = "",
13
+ nameKey = "dictLabel",
14
+ idKey = "dictValue",
15
+ ...restProps
16
+ } = props;
17
+
18
+ const [treeData, setTreeData] = useState([]);
19
+
20
+ const getData = async () => {
21
+ if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
22
+ throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
23
+
24
+ setTreeData([]);
25
+ const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
26
+ setTreeData(data);
27
+ };
28
+
29
+ useEffect(() => {
30
+ dictValue && getData();
31
+ }, [dictValue]);
32
+
33
+ return (
34
+ <BasicCascader data={treeData} nameKey={nameKey} idKey={idKey} {...restProps} />
35
+ );
36
+ }
37
+
38
+ DictionarySelectTree.displayName = "DictionarySelectTree";
39
+
40
+ export default DictionarySelectTree;
@@ -31,6 +31,8 @@ export interface FormBuilderProps extends FormProps {
31
31
  customActionButtons?: ReactNode;
32
32
  /** 额外操作按钮组 */
33
33
  extraActionButtons?: ReactNode;
34
+ /** 是否处于加载状态,默认 false */
35
+ loading?: boolean;
34
36
  }
35
37
 
36
38
  /**
@@ -1,4 +1,4 @@
1
- import { Button, Col, Form, Row, Space } from "antd";
1
+ import { Button, Col, Form, Row, Space, Spin } from "antd";
2
2
  import FormItemsRenderer from "./FormItemsRenderer";
3
3
 
4
4
  /**
@@ -19,6 +19,7 @@ const FormBuilder = (props) => {
19
19
  showCancelButton = true,
20
20
  customActionButtons,
21
21
  extraActionButtons,
22
+ loading = false,
22
23
  ...restProps
23
24
  } = props;
24
25
 
@@ -27,45 +28,47 @@ const FormBuilder = (props) => {
27
28
  };
28
29
 
29
30
  return (
30
- <Form
31
- labelCol={labelCol}
32
- scrollToFirstError
33
- wrapperCol={{ span: 24 - labelCol.span }}
34
- initialValues={values}
35
- style={{ width: `calc(100% - ${gutter * 2}px)`, margin: `0 auto` }}
36
- {...restProps}
37
- >
38
- <Row gutter={gutter}>
39
- <FormItemsRenderer
40
- options={options}
41
- labelCol={labelCol}
42
- span={span}
43
- useAutoGenerateRequired={useAutoGenerateRequired}
44
- initialValues={values}
45
- />
46
- </Row>
47
- {showActionButtons && (
48
- <Row gutter={gutter} style={{ marginTop: 24 }}>
49
- <Col span={24} style={{ textAlign: "center" }}>
50
- {customActionButtons || (
51
- <Space>
52
- {showSubmitButton && (
53
- <Button type="primary" htmlType="submit">
54
- {submitButtonText}
55
- </Button>
56
- )}
57
- {showCancelButton && (
58
- <Button onClick={handleCancel} style={{ marginRight: 8 }}>
59
- {cancelButtonText}
60
- </Button>
61
- )}
62
- {extraActionButtons}
63
- </Space>
64
- )}
65
- </Col>
31
+ <Spin spinning={loading}>
32
+ <Form
33
+ labelCol={labelCol}
34
+ scrollToFirstError
35
+ wrapperCol={{ span: 24 - labelCol.span }}
36
+ initialValues={values}
37
+ style={{ width: `calc(100% - ${gutter * 2}px)`, margin: `0 auto` }}
38
+ {...restProps}
39
+ >
40
+ <Row gutter={gutter}>
41
+ <FormItemsRenderer
42
+ options={options}
43
+ labelCol={labelCol}
44
+ span={span}
45
+ useAutoGenerateRequired={useAutoGenerateRequired}
46
+ initialValues={values}
47
+ />
66
48
  </Row>
67
- )}
68
- </Form>
49
+ {showActionButtons && (
50
+ <Row gutter={gutter} style={{ marginTop: 24 }}>
51
+ <Col span={24} style={{ textAlign: "center" }}>
52
+ {customActionButtons || (
53
+ <Space>
54
+ {showSubmitButton && (
55
+ <Button type="primary" htmlType="submit">
56
+ {submitButtonText}
57
+ </Button>
58
+ )}
59
+ {showCancelButton && (
60
+ <Button onClick={handleCancel} style={{ marginRight: 8 }}>
61
+ {cancelButtonText}
62
+ </Button>
63
+ )}
64
+ {extraActionButtons}
65
+ </Space>
66
+ )}
67
+ </Col>
68
+ </Row>
69
+ )}
70
+ </Form>
71
+ </Spin>
69
72
  );
70
73
  };
71
74
 
@@ -0,0 +1,16 @@
1
+ import type { FC } from "react";
2
+ import type { BasicLeftTreeProps } from "../Basic";
3
+
4
+ /**
5
+ * 组件属性
6
+ */
7
+ export interface AreaLeftTreeProps extends Omit<BasicLeftTreeProps, "treeData" | "nameKey" | "idKey" | "childrenKey"> {
8
+
9
+ }
10
+
11
+ /**
12
+ * 属地左侧树组件
13
+ */
14
+ declare const AreaLeftTree: FC<AreaLeftTreeProps>;
15
+
16
+ export default AreaLeftTree;
@@ -0,0 +1,15 @@
1
+ import Area from "../../../json/area.json";
2
+ import BasicLeftTree from "../Basic";
3
+
4
+ /**
5
+ * 属地左侧树组件
6
+ */
7
+ function AreaLeftTree(props) {
8
+ return (
9
+ <BasicLeftTree treeData={Area} nameKey="label" idKey="value" {...props} />
10
+ );
11
+ }
12
+
13
+ AreaLeftTree.displayName = "AreaLeftTree";
14
+
15
+ export default AreaLeftTree;
@@ -4,12 +4,12 @@ import type { FC } from "react";
4
4
  /**
5
5
  * 组件属性
6
6
  */
7
- export interface BasicLeftTreeProps extends TreeProps {
7
+ export interface BasicLeftTreeProps extends Omit<TreeProps, "fieldNames"> {
8
8
  /** 树形数据 title 字段,默认 name */
9
9
  nameKey?: string;
10
10
  /** 树形数据 key 字段,默认 id */
11
11
  idKey?: string;
12
- /** 树形数据 children 字段,默认 childrenList */
12
+ /** 树形数据 children 字段,默认 children */
13
13
  childrenKey?: string;
14
14
  /** 决定 onGetNodePaths 是否包含自身节点,默认 true */
15
15
  onGetNodePathsIsIncludeOneself?: boolean;
@@ -17,7 +17,7 @@ const BasicLeftTree = (props) => {
17
17
  treeData = [],
18
18
  nameKey = "name",
19
19
  idKey = "id",
20
- childrenKey = "childrenList",
20
+ childrenKey = "children",
21
21
  ...restProps
22
22
  } = props;
23
23
 
@@ -14,7 +14,7 @@ export interface Params {
14
14
  /**
15
15
  * 组件属性
16
16
  */
17
- export interface DepartmentLeftTreeProps extends Omit<BasicLeftTreeProps, "treeData"> {
17
+ export interface DepartmentLeftTreeProps extends Omit<BasicLeftTreeProps, "treeData" | "nameKey" | "idKey" | "childrenKey"> {
18
18
  /** 请求参数 */
19
19
  params?: Params;
20
20
  }
@@ -23,7 +23,7 @@ function DepartmentLeftTree(props) {
23
23
  }, []);
24
24
 
25
25
  return (
26
- <BasicLeftTree treeData={treeData} {...restProps} />
26
+ <BasicLeftTree treeData={treeData} childrenKey="childrenList" {...restProps} />
27
27
  );
28
28
  }
29
29
 
@@ -0,0 +1,23 @@
1
+ import type { FC } from "react";
2
+ import type { BasicLeftTreeProps } from "../Basic";
3
+
4
+ /**
5
+ * 组件属性
6
+ */
7
+ export interface DictionaryLeftTreeProps extends Omit<BasicLeftTreeProps, "treeData" | "nameKey" | "idKey" | "childrenKey"> {
8
+ /** appKey,默认 DICTIONARY_APP_KEY_ENUM.DEFAULT(0bb989ecada5470c87635018ece9f327) */
9
+ appKey?: string;
10
+ /** 要获取的字典 */
11
+ dictValue: string;
12
+ /** 树形数据 label 字段,默认 dictLabel */
13
+ nameKey?: string;
14
+ /** 树形数据 value 字段,默认 dictValue */
15
+ idKey?: string;
16
+ }
17
+
18
+ /**
19
+ * 数据字典左侧树组件
20
+ */
21
+ declare const DictionaryLeftTree: FC<DictionaryLeftTreeProps>;
22
+
23
+ export default DictionaryLeftTree;
@@ -0,0 +1,40 @@
1
+ import { request } from "@cqsjjb/jjb-common-lib/http";
2
+ import { useEffect, useState } from "react";
3
+ import { DICTIONARY_APP_KEY_ENUM } from "../../../enum/dictionary";
4
+ import BasicLeftTree from "../Basic";
5
+
6
+ /**
7
+ * 数据字典左侧树组件
8
+ */
9
+ function DictionaryLeftTree(props) {
10
+ const {
11
+ appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT,
12
+ dictValue = "",
13
+ nameKey = "dictLabel",
14
+ idKey = "dictValue",
15
+ ...restProps
16
+ } = props;
17
+
18
+ const [treeData, setTreeData] = useState([]);
19
+
20
+ const getData = async () => {
21
+ if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
22
+ throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
23
+
24
+ setTreeData([]);
25
+ const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
26
+ setTreeData(data);
27
+ };
28
+
29
+ useEffect(() => {
30
+ dictValue && getData();
31
+ }, [dictValue]);
32
+
33
+ return (
34
+ <BasicLeftTree treeData={treeData} nameKey={nameKey} idKey={idKey} {...restProps} />
35
+ );
36
+ }
37
+
38
+ DictionaryLeftTree.displayName = "DictionaryLeftTree";
39
+
40
+ export default DictionaryLeftTree;
@@ -1,5 +1,14 @@
1
1
  import type { FC } from "react";
2
2
 
3
+ export interface OnConfirmParams {
4
+ /** 经度值 */
5
+ longitude: number | string;
6
+ /** 纬度值 */
7
+ latitude: number | string;
8
+ /** 额外参数 */
9
+ extra?: { area: string };
10
+ }
11
+
3
12
  export interface MapSelectorProps {
4
13
  /** 是否显示弹窗 */
5
14
  visible: boolean;
@@ -9,10 +18,17 @@ export interface MapSelectorProps {
9
18
  longitude?: number | string;
10
19
  /** 纬度值 */
11
20
  latitude?: number | string;
21
+ /** 所属区域 */
22
+ area?: string;
23
+ /** 是否显示所属区域 */
24
+ showArea?: boolean;
12
25
  /** 确认选择回调 */
13
- onConfirm?: (longitude: number | string, latitude: number | string) => void;
26
+ onConfirm?: (longitude: number | string, latitude: number | string, extra: { area: string }) => void;
14
27
  }
15
28
 
29
+ /**
30
+ * 定位组件弹窗
31
+ */
16
32
  declare const MapSelector: FC<MapSelectorProps>;
17
33
 
18
34
  export default MapSelector;
@@ -1,4 +1,4 @@
1
- import { Button, Col, Form, Input, Modal, Row, Spin } from "antd";
1
+ import { Button, Col, Form, Input, Modal, Row, Select, Spin } from "antd";
2
2
  import { useEffect, useRef, useState } from "react";
3
3
 
4
4
  /**
@@ -11,6 +11,8 @@ const MapSelector = (props) => {
11
11
  longitude,
12
12
  latitude,
13
13
  onConfirm,
14
+ area = "",
15
+ showArea = false,
14
16
  } = props;
15
17
 
16
18
  const mapContainerRef = useRef(null);
@@ -19,12 +21,14 @@ const MapSelector = (props) => {
19
21
  const [currentLongitude, setCurrentLongitude] = useState(longitude || "");
20
22
  const [currentLatitude, setCurrentLatitude] = useState(latitude || "");
21
23
  const [localSearch, setLocalSearch] = useState("");
24
+ const [currentArea, setCurrentArea] = useState("");
22
25
 
23
26
  // 当外部经纬度变化时,更新内部状态
24
27
  useEffect(() => {
25
28
  setCurrentLongitude(longitude || "");
26
29
  setCurrentLatitude(latitude || "");
27
- }, [longitude, latitude]);
30
+ setCurrentArea(area || "");
31
+ }, [longitude, latitude, area]);
28
32
 
29
33
  // 初始化地图
30
34
  const initMap = async () => {
@@ -96,7 +100,7 @@ const MapSelector = (props) => {
96
100
  // 确认选择
97
101
  const handleConfirm = () => {
98
102
  if (onConfirm) {
99
- onConfirm(currentLongitude, currentLatitude);
103
+ onConfirm(currentLongitude, currentLatitude, { area: currentArea });
100
104
  }
101
105
  handleClose();
102
106
  };
@@ -146,19 +150,29 @@ const MapSelector = (props) => {
146
150
  title="坐标"
147
151
  onCancel={handleClose}
148
152
  onOk={handleConfirm}
149
- width={800}
153
+ width={1000}
150
154
  destroyOnHidden={false}
151
155
  afterClose={handleAfterClose}
152
156
  >
153
157
  <Form labelAlign="right" labelCol={{ span: 6 }} wrapperCol={{ span: 18 }}>
158
+ {
159
+ showArea && (
160
+ <Row gutter={24}>
161
+ <Col span={12}>
162
+ <Form.Item label="所属区域">
163
+ <Select value={currentArea} onChange={e => setCurrentArea(e)} allowClear>
164
+ <Select.Option value="1">东港区</Select.Option>
165
+ <Select.Option value="2">西港区</Select.Option>
166
+ </Select>
167
+ </Form.Item>
168
+ </Col>
169
+ </Row>
170
+ )
171
+ }
154
172
  <Row gutter={24}>
155
173
  <Col span={12}>
156
174
  <Form.Item label="关键字搜索">
157
- <Input
158
- value={localSearch}
159
- onChange={e => setLocalSearch(e.target.value)}
160
- allowClear
161
- />
175
+ <Input value={localSearch} onChange={e => setLocalSearch(e.target.value)} allowClear />
162
176
  </Form.Item>
163
177
  </Col>
164
178
  <Col span={12}>
@@ -5,12 +5,19 @@ export interface MapProps {
5
5
  longitudeProps?: string;
6
6
  /** 纬度属性名,默认 latitude */
7
7
  latitudeProps?: string;
8
- /** 经纬度变化回调 */
9
- onConfirm?: (longitude: number | string, latitude: number | string) => void;
10
8
  /** 经纬度是否必填,默认 true */
11
9
  required?: boolean;
10
+ /** 所属区域 */
11
+ area?: string;
12
+ /** 是否显示所属区域 */
13
+ showArea?: boolean;
14
+ /** 确认选择回调 */
15
+ onConfirm?: (longitude: number | string, latitude: number | string, extra: { area: string }) => void;
12
16
  }
13
17
 
18
+ /**
19
+ * 定位组件
20
+ */
14
21
  declare const Map: FC<MapProps>;
15
22
 
16
23
  export default Map;
@@ -11,6 +11,8 @@ const Map = (props) => {
11
11
  latitudeProps = "latitude",
12
12
  onConfirm,
13
13
  required = true,
14
+ area = "",
15
+ showArea = false,
14
16
  } = props;
15
17
 
16
18
  const form = Form.useFormInstance();
@@ -18,14 +20,14 @@ const Map = (props) => {
18
20
  const [currentLongitude, setCurrentLongitude] = useState(form.getFieldValue(longitudeProps) || "");
19
21
  const [currentLatitude, setCurrentLatitude] = useState(form.getFieldValue(latitudeProps) || "");
20
22
 
21
- const handleMapConfirm = (longitudeValue, latitudeValue) => {
23
+ const handleMapConfirm = (longitudeValue, latitudeValue, extra) => {
22
24
  setCurrentLongitude(longitudeValue);
23
25
  setCurrentLatitude(latitudeValue);
24
26
  form.setFieldsValue({
25
27
  [longitudeProps]: longitudeValue,
26
28
  [latitudeProps]: latitudeValue,
27
29
  });
28
- onConfirm?.(longitudeValue, latitudeValue);
30
+ onConfirm?.(longitudeValue, latitudeValue, extra);
29
31
  setMapVisible(false);
30
32
  };
31
33
 
@@ -44,7 +46,7 @@ const Map = (props) => {
44
46
  <Input disabled />
45
47
  </Form.Item>
46
48
  <Button type="primary" onClick={() => setMapVisible(true)}>
47
- 点击定位
49
+ 地图定位
48
50
  </Button>
49
51
  </div>
50
52
  </Form.Item>
@@ -55,6 +57,8 @@ const Map = (props) => {
55
57
  onClose={() => setMapVisible(false)}
56
58
  longitude={currentLongitude}
57
59
  latitude={currentLatitude}
60
+ area={area}
61
+ showArea={showArea}
58
62
  onConfirm={handleMapConfirm}
59
63
  />
60
64
  </>
@@ -0,0 +1,23 @@
1
+ import type { FC } from "react";
2
+ import type { BasicSelectProps } from "../Basic";
3
+
4
+ /**
5
+ * 组件属性
6
+ */
7
+ export interface DictionarySelectProps extends Omit<BasicSelectProps, "data" | "nameKey" | "idKey"> {
8
+ /** appKey,默认 DICTIONARY_APP_KEY_ENUM.DEFAULT(0bb989ecada5470c87635018ece9f327) */
9
+ appKey?: string;
10
+ /** 要获取的字典 */
11
+ dictValue: string;
12
+ /** 树形数据 label 字段,默认 dictLabel */
13
+ nameKey?: string;
14
+ /** 树形数据 value 字段,默认 dictValue */
15
+ idKey?: string;
16
+ }
17
+
18
+ /**
19
+ * 数据字典下拉组件
20
+ */
21
+ declare const DictionarySelect: FC<DictionarySelectProps>;
22
+
23
+ export default DictionarySelect;
@@ -0,0 +1,40 @@
1
+ import { request } from "@cqsjjb/jjb-common-lib/http";
2
+ import { useEffect, useState } from "react";
3
+ import { DICTIONARY_APP_KEY_ENUM } from "../../../enum/dictionary";
4
+ import BasicSelect from "../Basic";
5
+
6
+ /**
7
+ * 数据字典下拉组件
8
+ */
9
+ function DictionarySelect(props) {
10
+ const {
11
+ appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT,
12
+ dictValue = "",
13
+ nameKey = "dictLabel",
14
+ idKey = "dictValue",
15
+ ...restProps
16
+ } = props;
17
+
18
+ const [data, setData] = useState([]);
19
+
20
+ const getData = async () => {
21
+ if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
22
+ throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
23
+
24
+ setData([]);
25
+ const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
26
+ setData(data);
27
+ };
28
+
29
+ useEffect(() => {
30
+ dictValue && getData();
31
+ }, [dictValue]);
32
+
33
+ return (
34
+ <BasicSelect treeData={data} nameKey={nameKey} idKey={idKey} {...restProps} />
35
+ );
36
+ }
37
+
38
+ DictionarySelect.displayName = "DictionarySelect";
39
+
40
+ export default DictionarySelect;
@@ -16,7 +16,7 @@ export interface Params {
16
16
  /**
17
17
  * 组件属性
18
18
  */
19
- export interface PersonnelSelectProps extends Omit<BasicSelectProps, "data"> {
19
+ export interface PersonnelSelectProps extends Omit<BasicSelectProps, "data" | "placeholder" | "nameKey" | "idKey"> {
20
20
  /** 请求参数 */
21
21
  params?: Params;
22
22
  /** 占位符,默认"人员" */
@@ -4,7 +4,7 @@ import type { BasicSelectTreeProps } from "../Basic";
4
4
  /**
5
5
  * 组件属性
6
6
  */
7
- export interface AreaSelectTreeProps extends Omit<BasicSelectTreeProps, "treeData"> {
7
+ export interface AreaSelectTreeProps extends Omit<BasicSelectTreeProps, "treeData" | "placeholder" | "nameKey" | "idKey" | "childrenKey"> {
8
8
  /** 占位符,默认"属地" */
9
9
  placeholder?: string;
10
10
  }
@@ -16,7 +16,6 @@ function AreaSelectTree(props) {
16
16
  placeholder={placeholder}
17
17
  nameKey="label"
18
18
  idKey="value"
19
- childrenKey="children"
20
19
  {...restProps}
21
20
  />
22
21
  );
@@ -4,12 +4,12 @@ import type { FC } from "react";
4
4
  /**
5
5
  * 组件属性
6
6
  */
7
- export interface BasicSelectTreeProps extends TreeSelectProps {
7
+ export interface BasicSelectTreeProps extends Omit<TreeSelectProps, "fieldNames"> {
8
8
  /** 树形数据 label 字段,默认 name */
9
9
  nameKey?: string;
10
10
  /** 树形数据 value 字段,默认 id */
11
11
  idKey?: string;
12
- /** 树形数据 children 字段,默认 childrenList */
12
+ /** 树形数据 children 字段,默认 children */
13
13
  childrenKey?: string;
14
14
  /** 决定 onGetNodePaths 是否包含自身节点,默认 true */
15
15
  onGetNodePathsIsIncludeOneself?: boolean;
@@ -16,7 +16,7 @@ function BasicSelectTree(props) {
16
16
  treeData = [],
17
17
  nameKey = "name",
18
18
  idKey = "id",
19
- childrenKey = "childrenList",
19
+ childrenKey = "children",
20
20
  level,
21
21
  ...restProps
22
22
  } = props;
@@ -24,11 +24,11 @@ function BasicSelectTree(props) {
24
24
  // 根据 level 处理树数据
25
25
  const processedTreeData = level
26
26
  ? processTreeDataByLevel({
27
- data: treeData,
28
- level,
29
- childrenKey,
30
- currentLevel: 1,
31
- })
27
+ data: treeData,
28
+ level,
29
+ childrenKey,
30
+ currentLevel: 1,
31
+ })
32
32
  : treeData;
33
33
 
34
34
  const handleChange = (value, label, extra) => {
@@ -5,7 +5,7 @@ import type { BasicSelectTreeProps } from "../../Basic";
5
5
  /**
6
6
  * 组件属性
7
7
  */
8
- export interface DepartmentSelectTreeProps extends Omit<BasicSelectTreeProps, "treeData"> {
8
+ export interface DepartmentSelectTreeProps extends Omit<BasicSelectTreeProps, "treeData" | "placeholder" | "nameKey" | "idKey" | "childrenKey"> {
9
9
  /** 请求参数 */
10
10
  params?: Params;
11
11
  /** 占位符,默认"部门" */
@@ -34,7 +34,7 @@ function DepartmentSelectTree(props) {
34
34
  }, [JSON.stringify(params), isNeedCorpInfoId, isNeedParentId]);
35
35
 
36
36
  return (
37
- <BasicSelectTree treeData={treeData} placeholder={placeholder} {...restProps} />
37
+ <BasicSelectTree treeData={treeData} placeholder={placeholder} childrenKey="childrenList" {...restProps} />
38
38
  );
39
39
  }
40
40
 
@@ -0,0 +1,23 @@
1
+ import type { FC } from "react";
2
+ import type { BasicSelectTreeProps } from "../Basic";
3
+
4
+ /**
5
+ * 组件属性
6
+ */
7
+ export interface DictionarySelectTreeProps extends Omit<BasicSelectTreeProps, "treeData" | "nameKey" | "idKey" | "childrenKey"> {
8
+ /** appKey,默认 DICTIONARY_APP_KEY_ENUM.DEFAULT(0bb989ecada5470c87635018ece9f327) */
9
+ appKey?: string;
10
+ /** 要获取的字典 */
11
+ dictValue: string;
12
+ /** 树形数据 label 字段,默认 dictLabel */
13
+ nameKey?: string;
14
+ /** 树形数据 value 字段,默认 dictValue */
15
+ idKey?: string;
16
+ }
17
+
18
+ /**
19
+ * 数据字典下拉树组件
20
+ */
21
+ declare const DictionarySelectTree: FC<DictionarySelectTreeProps>;
22
+
23
+ export default DictionarySelectTree;
@@ -0,0 +1,40 @@
1
+ import { request } from "@cqsjjb/jjb-common-lib/http";
2
+ import { useEffect, useState } from "react";
3
+ import { DICTIONARY_APP_KEY_ENUM } from "../../../enum/dictionary";
4
+ import BasicSelectTree from "../Basic";
5
+
6
+ /**
7
+ * 数据字典下拉树组件
8
+ */
9
+ function DictionarySelectTree(props) {
10
+ const {
11
+ appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT,
12
+ dictValue = "",
13
+ nameKey = "dictLabel",
14
+ idKey = "dictValue",
15
+ ...restProps
16
+ } = props;
17
+
18
+ const [treeData, setTreeData] = useState([]);
19
+
20
+ const getData = async () => {
21
+ if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
22
+ throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
23
+
24
+ setTreeData([]);
25
+ const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
26
+ setTreeData(data);
27
+ };
28
+
29
+ useEffect(() => {
30
+ dictValue && getData();
31
+ }, [dictValue]);
32
+
33
+ return (
34
+ <BasicSelectTree treeData={treeData} nameKey={nameKey} idKey={idKey} {...restProps} />
35
+ );
36
+ }
37
+
38
+ DictionarySelectTree.displayName = "DictionarySelectTree";
39
+
40
+ export default DictionarySelectTree;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 数据字典 appKey 枚举
3
+ */
4
+ export const DICTIONARY_APP_KEY_ENUM = {
5
+ DEFAULT: "0bb989ecada5470c87635018ece9f327",
6
+ GWJ: "0bb989ecada5470c87635018ece9f327",
7
+ }
@@ -62,6 +62,7 @@ export const UPLOAD_FILE_TYPE_ENUM = {
62
62
  133: 133,
63
63
  134: 134,
64
64
  135: 135,
65
+ 136: 136,
65
66
  };
66
67
 
67
68
  /**
@@ -128,4 +129,5 @@ export const UPLOAD_FILE_PATH_ENUM = {
128
129
  133: "branch_safety_director_approval",
129
130
  134: "project_authority_review_signature",
130
131
  135: "branch_manager_approval_signature",
132
+ 136: "accident_incident",
131
133
  };
@@ -0,0 +1,24 @@
1
+ export interface getDictionaryOptions {
2
+ /** appKey,默认 DICTIONARY_APP_KEY_ENUM.DEFAULT(0bb989ecada5470c87635018ece9f327) */
3
+ appKey?: string;
4
+ /** 要获取的字典 */
5
+ dictValue: string;
6
+ }
7
+
8
+ export interface DictionaryItem {
9
+ /** label */
10
+ dictLabel: string;
11
+ /** value */
12
+ dictValue: string;
13
+ /** 子级 */
14
+ children: DictionaryItem[];
15
+ [key: string]: any;
16
+ }
17
+
18
+ export type getDictionaryFunction = (options: getDictionaryOptions) => Promise<DictionaryItem[]>;
19
+
20
+ /**
21
+ * 获取数据字典
22
+ */
23
+ export default function useDictionary(returnType: "array"): [boolean, getDictionaryFunction];
24
+ export default function useDictionary(returnType?: "object"): { loading: boolean; getDictionary: getDictionaryFunction };
@@ -0,0 +1,50 @@
1
+ import { request } from "@cqsjjb/jjb-common-lib/http";
2
+ import { useState } from "react";
3
+ import { DICTIONARY_APP_KEY_ENUM } from "../../enum/dictionary";
4
+
5
+ /**
6
+ * 获取数据字典
7
+ */
8
+ function useDictionary(returnType = "object") {
9
+ // loading状态
10
+ const [loading, setLoading] = useState(false);
11
+
12
+ // 获取数据字典
13
+ const getDictionary = (options) => {
14
+ if (!options)
15
+ throw new Error("请传入 options");
16
+
17
+ setLoading(true);
18
+
19
+ return new Promise((resolve, reject) => {
20
+ const { appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT, dictValue } = options;
21
+
22
+ if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
23
+ throw new Error("传入的 options.appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
24
+ if (!dictValue)
25
+ throw new Error("请传入 options.dictValue");
26
+
27
+ // 发送请求
28
+ request(
29
+ "/config/dict-trees/list/by/dictValues",
30
+ "get",
31
+ { appKey, dictValue },
32
+ )
33
+ .then((res) => {
34
+ resolve(res.data);
35
+ })
36
+ .catch((err) => {
37
+ reject(err);
38
+ })
39
+ .finally(() => {
40
+ setLoading(false);
41
+ });
42
+ });
43
+ };
44
+
45
+ if (returnType === "array")
46
+ return [loading, getDictionary];
47
+ return { loading, getDictionary };
48
+ }
49
+
50
+ export default useDictionary;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "1.0.68",
4
+ "version": "1.0.70",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",