zy-react-library 1.0.55 → 1.0.57

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
  /**
@@ -6,6 +6,7 @@ import { getLabelName } from "../../../utils";
6
6
  */
7
7
  function BasicSelect(props) {
8
8
  const {
9
+ onChange,
9
10
  onGetLabel,
10
11
  placeholder = "",
11
12
  data = [],
@@ -14,23 +15,15 @@ function BasicSelect(props) {
14
15
  ...restProps
15
16
  } = props;
16
17
 
17
- // const handleSelect = (event) => {
18
- // onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey }));
19
- // };
20
- //
21
- // const handleClear = () => {
22
- // onGetLabel?.(undefined);
23
- // };
24
-
25
- const handleChange = (event) => {
18
+ const handleChange = (event, option) => {
26
19
  if (event)
27
20
  onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey }));
28
21
  else
29
- onGetLabel?.(undefined);
30
- }
22
+ onGetLabel?.("");
23
+ onChange?.(event, option);
24
+ };
31
25
 
32
26
  return (
33
- // <Select placeholder={`请选择${placeholder}`} showSearch allowClear onClear={handleClear} onSelect={handleSelect} {...restProps}>
34
27
  <Select placeholder={`请选择${placeholder}`} showSearch allowClear onChange={handleChange} {...restProps}>
35
28
  {data.map((item) => {
36
29
  const value = item[idKey];
@@ -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.55",
4
+ "version": "1.0.57",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",