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.
|
@@ -1,32 +1,41 @@
|
|
|
1
|
-
import { Select } from "antd";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
|
32
|
-
if (value
|
|
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
|
-
|
|
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
|
-
|
|
59
|
+
onChange={handleChange}
|
|
54
60
|
allowClear
|
|
55
61
|
treeData={processedTreeData}
|
|
56
62
|
fieldNames={{ label: nameKey, value: idKey, children: childrenKey }}
|