|
|
@ -2,6 +2,8 @@ import { FC, useEffect, useRef, useState } from 'react';
|
|
|
|
import styles from './index.less';
|
|
|
|
import styles from './index.less';
|
|
|
|
import { history, useLocation, useParams } from 'umi';
|
|
|
|
import { history, useLocation, useParams } from 'umi';
|
|
|
|
import { Menu, Tree } from 'antd';
|
|
|
|
import { Menu, Tree } from 'antd';
|
|
|
|
|
|
|
|
import { unitAddressList } from '@/services/register';
|
|
|
|
|
|
|
|
import eventBus from '@/utils/eventBus';
|
|
|
|
|
|
|
|
|
|
|
|
interface PageProps {
|
|
|
|
interface PageProps {
|
|
|
|
data: Array<{
|
|
|
|
data: Array<{
|
|
|
@ -27,6 +29,27 @@ const LeftMenuCom: FC<PageProps> = ({ data }) => {
|
|
|
|
const treeRef = useRef(null);
|
|
|
|
const treeRef = useRef(null);
|
|
|
|
|
|
|
|
|
|
|
|
const [menuItems, setMenuItems] = useState<any>([]);
|
|
|
|
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}`;
|
|
|
|
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 = () => {
|
|
|
|
const menuItemsConfig = () => {
|
|
|
|
if (`/registerManage/deviceRegister/${urlStr}` == `${location.pathname}${location.search}`) {
|
|
|
|
if (`/registerManage/deviceRegister/${urlStr}` == `${location.pathname}${location.search}`) {
|
|
|
|
setMenuItems([
|
|
|
|
setMenuItems([
|
|
|
@ -65,17 +96,34 @@ const LeftMenuCom: FC<PageProps> = ({ data }) => {
|
|
|
|
])
|
|
|
|
])
|
|
|
|
} else if (`/registerManage/unitLocation/${urlStr}` == `${location.pathname}${location.search}`) {
|
|
|
|
} else if (`/registerManage/unitLocation/${urlStr}` == `${location.pathname}${location.search}`) {
|
|
|
|
setMenuItems([
|
|
|
|
setMenuItems([
|
|
|
|
{ key: '1', label: '修改' },
|
|
|
|
{ key: '3', label: '修改' },
|
|
|
|
{ key: '2', label: '刷新' },
|
|
|
|
{ key: '4', label: '刷新' },
|
|
|
|
{ key: '3', label: '新建' },
|
|
|
|
{ key: '5', label: '新建' },
|
|
|
|
{ key: '4', 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) => {
|
|
|
|
const handleRightClick = (e: any, node: any) => {
|
|
|
|
if (node?.isFolder) return
|
|
|
|
if (node?.isFolder) return
|
|
|
|
|
|
|
|
e[0] == 'root' ? eventBus.emit('hideFlag', false) : eventBus.emit('hideFlag', true);
|
|
|
|
e.preventDefault();
|
|
|
|
e.preventDefault();
|
|
|
|
setContextMenuPosition({ x: e.clientX, y: e.clientY }); // 记录右键菜单位置
|
|
|
|
setContextMenuPosition({ x: e.clientX, y: e.clientY }); // 记录右键菜单位置
|
|
|
|
setSelectedKeys([node.key]); // 根据节点设置选中的 keys
|
|
|
|
setSelectedKeys([node.key]); // 根据节点设置选中的 keys
|
|
|
@ -83,42 +131,20 @@ const LeftMenuCom: FC<PageProps> = ({ data }) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
setSelectedKeys(selectedKeys);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleContextMenuClick = (e: any) => {
|
|
|
|
const handleContextMenuClick = (e: any) => {
|
|
|
|
setShowContextMenu(false); // 隐藏右键菜单
|
|
|
|
let index = selectedKeys[0] - 1;
|
|
|
|
};
|
|
|
|
if(e.key == '3') {
|
|
|
|
|
|
|
|
eventBus.emit('updateUnitInfo', ['修改', treeData1[0].children[index]]);
|
|
|
|
const treeData = [
|
|
|
|
} else if(e.key == '6') {
|
|
|
|
{
|
|
|
|
eventBus.emit('updateUnitInfo', ['删除', treeData1[0].children[index]]);
|
|
|
|
title: 'xxx管理系统',
|
|
|
|
|
|
|
|
key: 'root',
|
|
|
|
|
|
|
|
selectable: true,
|
|
|
|
|
|
|
|
isFolder: true,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
title: '用户管理',
|
|
|
|
|
|
|
|
key: 'user',
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const treeData1 = [
|
|
|
|
setShowContextMenu(false); // 隐藏右键菜单
|
|
|
|
{
|
|
|
|
};
|
|
|
|
title: '所有单位位置',
|
|
|
|
|
|
|
|
key: 'root',
|
|
|
|
|
|
|
|
selectable: true,
|
|
|
|
|
|
|
|
isFolder: true,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
title: 'aadw',
|
|
|
|
|
|
|
|
key: 'user',
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const nameType = {
|
|
|
|
const nameType = {
|
|
|
|
"设备注册": treeData,
|
|
|
|
"设备注册": treeData,
|
|
|
@ -151,10 +177,11 @@ const LeftMenuCom: FC<PageProps> = ({ data }) => {
|
|
|
|
// 树结构
|
|
|
|
// 树结构
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<Tree
|
|
|
|
<Tree
|
|
|
|
|
|
|
|
key={treeKey}
|
|
|
|
style={{ padding: 20 }}
|
|
|
|
style={{ padding: 20 }}
|
|
|
|
onContextMenu={(e) => e.preventDefault()}
|
|
|
|
onContextMenu={(e) => e.preventDefault()}
|
|
|
|
onRightClick={({ event, node }) => handleRightClick(event, node)}
|
|
|
|
onRightClick={({ event, node }) => handleRightClick(event, node)}
|
|
|
|
onSelect={(e, {node}) => {
|
|
|
|
onSelect={(e, { node }) => {
|
|
|
|
if (node.key === 'root') {
|
|
|
|
if (node.key === 'root') {
|
|
|
|
history.push(`${urlType[item.name]}/${urlStr}`)
|
|
|
|
history.push(`${urlType[item.name]}/${urlStr}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|