diff --git a/software/web/src/pages/devices/index.tsx b/software/web/src/pages/devices/index.tsx index bcdc18f..cd930f5 100644 --- a/software/web/src/pages/devices/index.tsx +++ b/software/web/src/pages/devices/index.tsx @@ -8,7 +8,6 @@ import { useEffect, useState, useCallback } from 'react'; import { useNavigate } from 'react-router-dom'; import { - Layout, Typography, Modal, Button, @@ -17,11 +16,14 @@ import { Dropdown, Menu, Message, + Spin, + Tree, } from '@arco-design/web-react'; import { IconPlus, IconDelete, IconEdit, + IconRefresh, } from '@arco-design/web-react/icon'; import { treeApi, @@ -33,7 +35,7 @@ import { type Organization, } from '@/api/devices'; -import OrganizationTree, { +import { buildTreeData, collectCabinets, findOrgInTree, @@ -43,8 +45,6 @@ import OrganizationTree, { import CabinetGrid from './CabinetGrid'; import AddCabinetModal from './AddCabinetModal'; -const Content = Layout.Content; - export default function Devices() { const navigate = useNavigate(); const [treeData, setTreeData] = useState([]); @@ -285,18 +285,63 @@ export default function Devices() { ); - return ( - - + // -------- 树渲染 -------- + const renderNodeTitle = useCallback( + (nodeType: NodeType, nodeId: number, title: string) => ( + handleRightClick(e, nodeType, nodeId)} + > + {title} + + ), + [handleRightClick], + ); - + const injectTitleRender = useCallback( + (nodes: TreeInternalNode[]): unknown[] => + nodes.map((n) => ({ + ...n, + title: renderNodeTitle(n._type, n._id, n.title), + children: n.children ? injectTitleRender(n.children) : undefined, + })), + [renderNodeTitle], + ); + + const renderedTreeData = [ + { + key: 'all', + title: renderNodeTitle('all', 0, '全部'), + children: injectTitleRender(treeData) as TreeInternalNode[], + }, + ]; + + return ( +
+ {/* 左列:组织架构树 */} +
+
+ 组织架构 +
+ + {treeData.length > 0 ? ( + + ) : ( + !loading && 暂无数据 + )} + +
+ + {/* 右列:柜子列表 */} +
设备列表 ({cabinets.length}) @@ -306,7 +351,7 @@ export default function Devices() {
- +
{/* 右键菜单 */} setCabinetModalVisible(false)} onSuccess={async () => { setCabinetModalVisible(false); await loadTree(); }} /> - +
); }