zy-react-library 1.0.41 → 1.0.43
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.
|
@@ -11,9 +11,9 @@ export interface CustomRenderProps {
|
|
|
11
11
|
/** 表单当前值 */
|
|
12
12
|
formValues: FormValues;
|
|
13
13
|
/** 字段值 */
|
|
14
|
-
value
|
|
14
|
+
value: any;
|
|
15
15
|
/** 值变化回调 */
|
|
16
|
-
onChange
|
|
16
|
+
onChange: (value: any) => void;
|
|
17
17
|
/** 其他属性 */
|
|
18
18
|
[key: string]: any;
|
|
19
19
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Input, Tree } from "antd";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
|
+
import { getTreeNodePaths } from "../../../utils";
|
|
3
4
|
|
|
4
5
|
const { Search } = Input;
|
|
5
6
|
|
|
@@ -71,35 +72,16 @@ const BasicLeftTree = (props) => {
|
|
|
71
72
|
setAutoExpandParent(false);
|
|
72
73
|
};
|
|
73
74
|
|
|
74
|
-
const getNodePaths = (data, targetId, idKey, childrenKey, path = [], isIncludeOneself) => {
|
|
75
|
-
for (let i = 0; i < data.length; i++) {
|
|
76
|
-
const node = data[i];
|
|
77
|
-
const newPath = [...path, node];
|
|
78
|
-
|
|
79
|
-
// 找到目标节点,根据isIncludeOneself决定是否包含自身
|
|
80
|
-
if (node[idKey] === targetId) {
|
|
81
|
-
if (isIncludeOneself)
|
|
82
|
-
return newPath; // 包含自身
|
|
83
|
-
else
|
|
84
|
-
return path; // 不包含自身,只返回父节点路径
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 递归查找子节点
|
|
88
|
-
if (node[childrenKey] && node[childrenKey].length > 0) {
|
|
89
|
-
const result = getNodePaths(node[childrenKey], targetId, idKey, childrenKey, newPath, isIncludeOneself);
|
|
90
|
-
if (result) {
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return null;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
75
|
const handleSelect = (selectedKeys, event) => {
|
|
100
76
|
if (selectedKeys.length > 0) {
|
|
101
77
|
const selectedNodeId = selectedKeys[0];
|
|
102
|
-
const parentNodes =
|
|
78
|
+
const parentNodes = getTreeNodePaths({
|
|
79
|
+
data: treeData,
|
|
80
|
+
targetId: selectedNodeId,
|
|
81
|
+
idKey,
|
|
82
|
+
childrenKey,
|
|
83
|
+
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
|
84
|
+
});
|
|
103
85
|
onGetNodePaths?.(parentNodes);
|
|
104
86
|
}
|
|
105
87
|
onSelect?.(selectedKeys, event);
|