|
|
|
@ -2,6 +2,8 @@ import { FC, useEffect, useRef, useState } from 'react';
|
|
|
|
|
import styles from './index.less';
|
|
|
|
|
import { history, useLocation, useParams } from 'umi';
|
|
|
|
|
import { Menu, Tree } from 'antd';
|
|
|
|
|
import { unitAddressList } from '@/services/register';
|
|
|
|
|
import eventBus from '@/utils/eventBus';
|
|
|
|
|
|
|
|
|
|
interface PageProps {
|
|
|
|
|
data: Array<{
|
|
|
|
@ -27,6 +29,27 @@ const LeftMenuCom: FC<PageProps> = ({ data }) => {
|
|
|
|
|
const treeRef = useRef(null);
|
|
|
|
|
|
|
|
|
|
const [menuItems, setMenuItems] = useState<any>([]);
|
|
|
|
|
const [treeKey, setTreeKey] = useState<any>(0);
|
|
|
|
|
|
|
|
|
|
const [treeData, setTreeData] = useState([
|
|
|
|
|
{
|
|
|
|
|
title: 'xxx管理系统',
|
|
|
|
|
key: 'root',
|
|
|
|
|
selectable: true,
|
|
|
|
|
isFolder: true,
|
|
|
|
|
children: [],
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const [treeData1, setTreeData1] = useState([
|
|
|
|
|
{
|
|
|
|
|
title: '所有单位位置',
|
|
|
|
|
key: 'root',
|
|
|
|
|
selectable: true,
|
|
|
|
|
isFolder: true,
|
|
|
|
|
children: [],
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
let urlStr = `${urlParams?.fileType}${location?.search}`;
|
|
|
|
|
|
|
|
|
@ -57,6 +80,14 @@ const LeftMenuCom: FC<PageProps> = ({ data }) => {
|
|
|
|
|
};
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eventBus.on('getUnitList', getUnitList);
|
|
|
|
|
return () => {
|
|
|
|
|
eventBus.off('getUnitList', getUnitList);
|
|
|
|
|
};
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
const menuItemsConfig = () => {
|
|
|
|
|
if (`/registerManage/deviceRegister/${urlStr}` == `${location.pathname}${location.search}`) {
|
|
|
|
|
setMenuItems([
|
|
|
|
@ -65,61 +96,56 @@ const LeftMenuCom: FC<PageProps> = ({ data }) => {
|
|
|
|
|
])
|
|
|
|
|
} else if (`/registerManage/unitLocation/${urlStr}` == `${location.pathname}${location.search}`) {
|
|
|
|
|
setMenuItems([
|
|
|
|
|
{ key: '1', label: '修改' },
|
|
|
|
|
{ key: '2', label: '刷新' },
|
|
|
|
|
{ key: '3', label: '新建' },
|
|
|
|
|
{ key: '4', label: '删除' }
|
|
|
|
|
{ key: '3', label: '修改' },
|
|
|
|
|
{ key: '4', label: '刷新' },
|
|
|
|
|
{ key: '5', label: '新建' },
|
|
|
|
|
{ key: '6', label: '删除' }
|
|
|
|
|
])
|
|
|
|
|
getUnitList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新单位位置管理树结构数据
|
|
|
|
|
const getUnitList = (type?: string) => {
|
|
|
|
|
unitAddressList({ pageNum: 1, pageSize: 50}).then((res: any) => {
|
|
|
|
|
if (res.result == 'success') {
|
|
|
|
|
res.data[0].list.forEach((val: any) => { val.title = val.unitName; val.key = val.id; })
|
|
|
|
|
setTreeData1((e) => { e[0].children = res.data[0].list; return e })
|
|
|
|
|
setTreeKey((e: any) => { return e + 1 })
|
|
|
|
|
if (type == '添加成功') {
|
|
|
|
|
setSelectedKeys([Number(res.data[0].list.length)])
|
|
|
|
|
}else if (type == '删除成功') {
|
|
|
|
|
setSelectedKeys(['root'])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleRightClick = (e: any, node: any) => {
|
|
|
|
|
if (node?.isFolder) return
|
|
|
|
|
|
|
|
|
|
e[0] == 'root' ? eventBus.emit('hideFlag', false) : eventBus.emit('hideFlag', true);
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
setContextMenuPosition({ x: e.clientX, y: e.clientY }); // 记录右键菜单位置
|
|
|
|
|
setSelectedKeys([node.key]); // 根据节点设置选中的 keys
|
|
|
|
|
setShowContextMenu(true); // 显示右键菜单
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSelect = (selectedKeys: any, name: any) => {
|
|
|
|
|
const handleSelect = (selectedKeys: any, name: any) => {
|
|
|
|
|
selectedKeys[0] == 'root' ? eventBus.emit('hideFlag', false) : eventBus.emit('hideFlag', true);
|
|
|
|
|
setSelectedKeys(selectedKeys);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleContextMenuClick = (e: any) => {
|
|
|
|
|
let index = selectedKeys[0] - 1;
|
|
|
|
|
if(e.key == '3') {
|
|
|
|
|
eventBus.emit('updateUnitInfo', ['修改', treeData1[0].children[index]]);
|
|
|
|
|
} else if(e.key == '6') {
|
|
|
|
|
eventBus.emit('updateUnitInfo', ['删除', treeData1[0].children[index]]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setShowContextMenu(false); // 隐藏右键菜单
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const treeData = [
|
|
|
|
|
{
|
|
|
|
|
title: 'xxx管理系统',
|
|
|
|
|
key: 'root',
|
|
|
|
|
selectable: true,
|
|
|
|
|
isFolder: true,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
title: '用户管理',
|
|
|
|
|
key: 'user',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const treeData1 = [
|
|
|
|
|
{
|
|
|
|
|
title: '所有单位位置',
|
|
|
|
|
key: 'root',
|
|
|
|
|
selectable: true,
|
|
|
|
|
isFolder: true,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
title: 'aadw',
|
|
|
|
|
key: 'user',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const nameType = {
|
|
|
|
|
"设备注册": treeData,
|
|
|
|
|
'单位位置管理': treeData1
|
|
|
|
@ -151,14 +177,15 @@ const LeftMenuCom: FC<PageProps> = ({ data }) => {
|
|
|
|
|
// 树结构
|
|
|
|
|
<div>
|
|
|
|
|
<Tree
|
|
|
|
|
key={treeKey}
|
|
|
|
|
style={{ padding: 20 }}
|
|
|
|
|
onContextMenu={(e) => e.preventDefault()}
|
|
|
|
|
onRightClick={({ event, node }) => handleRightClick(event, node)}
|
|
|
|
|
onSelect={(e, {node}) => {
|
|
|
|
|
onSelect={(e, { node }) => {
|
|
|
|
|
if (node.key === 'root') {
|
|
|
|
|
history.push(`${urlType[item.name]}/${urlStr}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleSelect(e, item.name)
|
|
|
|
|
}}
|
|
|
|
|
selectedKeys={selectedKeys}
|
|
|
|
|