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