优化BasicSelectTree

master
LiuJiaNan 2025-12-08 10:49:51 +08:00
parent f97b308764
commit 9674bbe71c
2 changed files with 18 additions and 2 deletions

View File

@ -1,6 +1,6 @@
import { TreeSelect } from "antd"; import { TreeSelect } from "antd";
import { useEffect } from "react"; import { useEffect } from "react";
import { getTreeNodePaths, processTreeDataByLevel, processTreeDataForOnlyLastLevel } from "../../../utils"; import { arrayObjectDeduplication, getDataType, getTreeNodePaths, processTreeDataByLevel, processTreeDataForOnlyLastLevel } from "../../../utils";
/** /**
* 基础下拉树组件不建议直接使用此组件二次继承使用 * 基础下拉树组件不建议直接使用此组件二次继承使用
@ -37,6 +37,22 @@ function BasicSelectTree(props) {
const handleChange = (value, label, extra) => { const handleChange = (value, label, extra) => {
if (value) { if (value) {
if (getDataType(value) === "Array") {
const parentNodes = [];
for (let i = 0; i < value.length; i++) {
const currentParentNodes = getTreeNodePaths({
data: treeData,
targetId: value[i],
idKey,
childrenKey,
isIncludeOneself: onGetNodePathsIsIncludeOneself,
});
parentNodes.push(...currentParentNodes);
}
onGetNodePaths?.(arrayObjectDeduplication(parentNodes, idKey));
onGetLabel?.(label);
return;
}
const parentNodes = getTreeNodePaths({ const parentNodes = getTreeNodePaths({
data: treeData, data: treeData,
targetId: value, targetId: value,

View File

@ -27,7 +27,7 @@ function getService(service, getExtraParams = {}, transform, usePermission) {
} }
if (usePermission) if (usePermission)
params.menuPath = window.location.pathname params.menuPath = window.location.pathname;
// 发起请求 // 发起请求
const res = await service(params); const res = await service(params);