优化BasicSelectTree
parent
325227b0fb
commit
c189725deb
|
|
@ -25,11 +25,11 @@ function BasicSelectTree(props) {
|
||||||
// 根据 level 处理树数据
|
// 根据 level 处理树数据
|
||||||
let processedTreeData = level
|
let processedTreeData = level
|
||||||
? processTreeDataByLevel({
|
? processTreeDataByLevel({
|
||||||
data: treeData,
|
data: treeData,
|
||||||
level,
|
level,
|
||||||
childrenKey,
|
childrenKey,
|
||||||
currentLevel: 1,
|
currentLevel: 1,
|
||||||
})
|
})
|
||||||
: treeData;
|
: treeData;
|
||||||
|
|
||||||
// 根据 onlyLastLevel 处理树数据
|
// 根据 onlyLastLevel 处理树数据
|
||||||
|
|
@ -40,22 +40,25 @@ function BasicSelectTree(props) {
|
||||||
if (getDataType(value) === "Array") {
|
if (getDataType(value) === "Array") {
|
||||||
const parentNodes = [];
|
const parentNodes = [];
|
||||||
for (let i = 0; i < value.length; i++) {
|
for (let i = 0; i < value.length; i++) {
|
||||||
|
const targetId = (restProps.labelInValue || restProps.treeCheckStrictly) ? value[i].value : value[i];
|
||||||
const currentParentNodes = getTreeNodePaths({
|
const currentParentNodes = getTreeNodePaths({
|
||||||
data: treeData,
|
data: treeData,
|
||||||
targetId: value[i],
|
targetId,
|
||||||
idKey,
|
idKey,
|
||||||
childrenKey,
|
childrenKey,
|
||||||
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
||||||
});
|
});
|
||||||
parentNodes.push(...currentParentNodes);
|
parentNodes.push(...currentParentNodes);
|
||||||
}
|
}
|
||||||
onGetNodePaths?.(arrayObjectDeduplication(parentNodes, idKey));
|
const deduplicationParentNodes = arrayObjectDeduplication(parentNodes, idKey);
|
||||||
onGetLabel?.(label);
|
onGetNodePaths?.(deduplicationParentNodes);
|
||||||
|
onGetLabel?.((restProps.labelInValue || restProps.treeCheckStrictly) ? value.map(item => item.label) : label);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
const targetId = (restProps.labelInValue || restProps.treeCheckStrictly) ? value.value : value;
|
||||||
const parentNodes = getTreeNodePaths({
|
const parentNodes = getTreeNodePaths({
|
||||||
data: treeData,
|
data: treeData,
|
||||||
targetId: value,
|
targetId,
|
||||||
idKey,
|
idKey,
|
||||||
childrenKey,
|
childrenKey,
|
||||||
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
||||||
|
|
@ -68,7 +71,7 @@ function BasicSelectTree(props) {
|
||||||
onGetNodePaths?.([]);
|
onGetNodePaths?.([]);
|
||||||
onGetLabel?.("");
|
onGetLabel?.("");
|
||||||
}
|
}
|
||||||
onChange?.(value, label, extra);
|
onChange?.((restProps.labelInValue || restProps.treeCheckStrictly) ? value.map(item => item.value) : value, label, extra);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -88,6 +91,7 @@ function BasicSelectTree(props) {
|
||||||
treeData={processedTreeData}
|
treeData={processedTreeData}
|
||||||
fieldNames={{ label: nameKey, value: idKey, children: childrenKey }}
|
fieldNames={{ label: nameKey, value: idKey, children: childrenKey }}
|
||||||
treeNodeFilterProp={nameKey}
|
treeNodeFilterProp={nameKey}
|
||||||
|
showCheckedStrategy={TreeSelect.SHOW_ALL}
|
||||||
{...restProps}
|
{...restProps}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue