zy-react-library 1.0.54 → 1.0.56

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.
@@ -33,7 +33,7 @@ function BasicCascader(props) {
33
33
  if (!onGetNodePathsIsIncludeOneself && selectedOptions) {
34
34
  nodePaths = selectedOptions.slice(0, -1);
35
35
  }
36
- return nodePaths;
36
+ return nodePaths || [];
37
37
  };
38
38
 
39
39
  const handleChange = (value, selectedOptions) => {
@@ -13,6 +13,8 @@ export interface BasicSelectProps extends SelectProps {
13
13
  idKey?: string;
14
14
  /** 占位符 */
15
15
  placeholder?: string;
16
+ /** 获取 label */
17
+ onGetLabel?: (label: string) => void;
16
18
  }
17
19
 
18
20
  /**
@@ -1,32 +1,41 @@
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;
1
+ import { Select } from "antd";
2
+ import { getLabelName } from "../../../utils";
3
+
4
+ /**
5
+ * 基础下拉组件(不建议直接使用此组件,二次继承使用)
6
+ */
7
+ function BasicSelect(props) {
8
+ const {
9
+ onGetLabel,
10
+ placeholder = "",
11
+ data = [],
12
+ nameKey = "name",
13
+ idKey = "id",
14
+ ...restProps
15
+ } = props;
16
+
17
+ const handleChange = (event) => {
18
+ if (event)
19
+ onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey }));
20
+ else
21
+ onGetLabel?.("");
22
+ };
23
+
24
+ return (
25
+ <Select placeholder={`请选择${placeholder}`} showSearch allowClear onChange={handleChange} {...restProps}>
26
+ {data.map((item) => {
27
+ const value = item[idKey];
28
+ const label = item[nameKey];
29
+ return (
30
+ <Select.Option key={value} value={value}>
31
+ {label}
32
+ </Select.Option>
33
+ );
34
+ })}
35
+ </Select>
36
+ );
37
+ }
38
+
39
+ BasicSelect.displayName = "BasicSelect";
40
+
41
+ export default BasicSelect;
@@ -19,6 +19,8 @@ export interface BasicSelectTreeProps extends TreeSelectProps {
19
19
  placeholder?: string;
20
20
  /** 控制只能选择到第几级 */
21
21
  level?: number;
22
+ /** 获取 label */
23
+ onGetLabel?: (label: string) => void;
22
24
  }
23
25
 
24
26
  /**
@@ -26,4 +28,4 @@ export interface BasicSelectTreeProps extends TreeSelectProps {
26
28
  */
27
29
  declare const BasicSelectTree: FC<BasicSelectTreeProps>;
28
30
 
29
- export default BasicSelectTree;
31
+ export default BasicSelectTree;
@@ -6,7 +6,8 @@ import { getTreeNodePaths, processTreeDataByLevel } from "../../../utils";
6
6
  */
7
7
  function BasicSelectTree(props) {
8
8
  const {
9
- onSelect,
9
+ onChange,
10
+ onGetLabel,
10
11
  onGetNodePaths,
11
12
  onGetNodePathsIsIncludeOneself = true,
12
13
  placeholder = "",
@@ -28,8 +29,8 @@ function BasicSelectTree(props) {
28
29
  })
29
30
  : treeData;
30
31
 
31
- const handleSelect = (value, node, extra) => {
32
- if (value.length > 0) {
32
+ const handleChange = (value, label, extra) => {
33
+ if (value) {
33
34
  const parentNodes = getTreeNodePaths({
34
35
  data: treeData,
35
36
  targetId: value,
@@ -38,8 +39,13 @@ function BasicSelectTree(props) {
38
39
  isIncludeOneself: onGetNodePathsIsIncludeOneself,
39
40
  });
40
41
  onGetNodePaths?.(parentNodes);
42
+ onGetLabel?.(parentNodes[parentNodes.length - 1][nameKey]);
41
43
  }
42
- onSelect?.(value, node, extra);
44
+ else {
45
+ onGetNodePaths?.([]);
46
+ onGetLabel?.("");
47
+ }
48
+ onChange?.(value, label, extra);
43
49
  };
44
50
 
45
51
  return (
@@ -50,7 +56,7 @@ function BasicSelectTree(props) {
50
56
  popup: { root: { maxHeight: 400, overflow: "auto" } },
51
57
  }}
52
58
  placeholder={`请选择${placeholder}`}
53
- onSelect={handleSelect}
59
+ onChange={handleChange}
54
60
  allowClear
55
61
  treeData={processedTreeData}
56
62
  fieldNames={{ label: nameKey, value: idKey, children: childrenKey }}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "1.0.54",
4
+ "version": "1.0.56",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",