mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-15 22:46:49 +00:00
[improvement][project] supersonic 0.6.0 version update (#16)
Co-authored-by: lexluo <lexluo@tencent.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { API } from '@/services/API';
|
||||
|
||||
import { ISemantic } from './data';
|
||||
import type { DataNode } from 'antd/lib/tree';
|
||||
|
||||
export const changeTreeData = (treeData: API.ProjectList, auth?: boolean): DataNode[] => {
|
||||
@@ -77,3 +77,50 @@ export const findDepartmentTree: any = (treeData: any[], projectId: string) => {
|
||||
}
|
||||
return findDepartmentTree(newStepList, projectId);
|
||||
};
|
||||
|
||||
const isDescendant = (
|
||||
node: ISemantic.IDomainItem,
|
||||
parentId: number,
|
||||
nodes: ISemantic.IDomainItem[],
|
||||
): boolean => {
|
||||
// 如果当前节点的 parentId 与指定的 parentId 相同,则说明它是指定节点的子节点
|
||||
if (node.parentId === parentId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 递归检查当前节点的父节点是否是指定节点的子节点
|
||||
const parentNode = nodes.find((n) => n.id === node.parentId);
|
||||
if (parentNode) {
|
||||
return isDescendant(parentNode, parentId, nodes);
|
||||
}
|
||||
|
||||
// 如果找不到父节点,则说明当前节点不是指定节点的子孙节点
|
||||
return false;
|
||||
};
|
||||
|
||||
export const findLeafNodesFromDomainList = (
|
||||
nodes: ISemantic.IDomainItem[],
|
||||
id: number | null = null,
|
||||
): ISemantic.IDomainItem[] => {
|
||||
const leafNodes: ISemantic.IDomainItem[] = [];
|
||||
|
||||
// 遍历所有节点
|
||||
for (const node of nodes) {
|
||||
let isLeaf = true;
|
||||
|
||||
// 检查当前节点是否有子节点
|
||||
for (const childNode of nodes) {
|
||||
if (childNode.parentId === node.id) {
|
||||
isLeaf = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果当前节点是叶子节点,并且满足指定的 id 条件,则将其添加到结果数组中
|
||||
if (isLeaf && (id === null || isDescendant(node, id, nodes))) {
|
||||
leafNodes.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
return leafNodes;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user