feat: 组织架构树只显示到项目节点,不显示柜子

This commit is contained in:
12451 2026-07-02 19:18:47 +08:00
parent 04a3d31517
commit 1be7480472

View File

@ -13,7 +13,6 @@ import {
} from '@arco-design/web-react';
import {
IconFolder,
IconDesktop,
IconRefresh,
} from '@arco-design/web-react/icon';
import {
@ -36,19 +35,19 @@ export interface TreeInternalNode {
_id: number;
}
/** 构建 Arco Tree 数据 */
/** 构建 Arco Tree 数据(只到项目节点,不显示柜子) */
export function buildTreeData(nodes: TreeNode[], parentKey?: string): TreeInternalNode[] {
const result: TreeInternalNode[] = [];
for (const n of nodes) {
const key = parentKey ? `${parentKey}-${n.id}` : `${n.id}`;
const children = n.children ? buildTreeData(n.children, key) : undefined;
const nodeType: NodeType = n.children !== undefined
? (parentKey ? 'project' : 'organization')
: 'cabinet';
const nodeType: NodeType = parentKey ? 'project' : 'organization';
// 只显示组织和项目,不显示柜子
const hasChildren = n.children && n.children.some(c => c.children !== undefined);
const children = hasChildren ? buildTreeData(n.children!, key) : undefined;
result.push({
key,
title: n.abstract_id ? `${n.abstract_id} ${n.name || ''}` : n.name,
isLeaf: !children || children.length === 0,
title: n.name,
isLeaf: !hasChildren,
children,
_type: nodeType,
_id: n.id,
@ -124,12 +123,9 @@ export default function OrganizationTree({
const injectTitleRender = useCallback(
(nodes: TreeInternalNode[]): unknown[] =>
nodes.map((n) => {
const icon = n._type === 'cabinet'
? <IconDesktop />
: <IconFolder />;
return {
...n,
title: renderNodeTitle(n._type, n._id, n.title, icon),
title: renderNodeTitle(n._type, n._id, n.title, <IconFolder />),
children: n.children ? injectTitleRender(n.children) : undefined,
};
}),