完成单位位置管理模块

master
鲁誉程 10 months ago
parent 2f521b4b1b
commit 6ed6bbc8dc

@ -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}`)
} }

@ -21,5 +21,6 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
border-radius: 50%; border-radius: 50%;
cursor: pointer;
} }
} }

@ -1,10 +1,11 @@
import { useState } from 'react'; import { useEffect, useState } from 'react';
import styles from './index.less'; import styles from './index.less';
import { Input, Modal, message } from 'antd'; import { Input, Modal, message } from 'antd';
import ButtonComp from '@/components/ButtonComp'; import ButtonComp from '@/components/ButtonComp';
import { unitAddressEditOrAdd } from '@/services/register'; import { unitAddressEditOrAdd, unitAddressList } from '@/services/register';
import { useLocation, useParams } from 'umi'; import { useLocation, useParams } from 'umi';
import { sysTypeStr } from '@/utils/sysType'; import { sysTypeStr } from '@/utils/sysType';
import eventBus from '@/utils/eventBus';
export default function Page() { export default function Page() {
const location = useLocation(); const location = useLocation();
@ -12,23 +13,63 @@ export default function Page() {
const [unitName, setUnitName] = useState<any>(''); const [unitName, setUnitName] = useState<any>('');
const [visibility, setVisibility] = useState<boolean>(false); const [visibility, setVisibility] = useState<boolean>(false);
const [showFlag, setShowFlag] = useState<boolean>(false); const [showFlag, setShowFlag] = useState<boolean>(false);
const [unitId, setunitId] = useState<any>(null);
const [isDelFlag, setIsDelFlag] = useState<any>(false);
const [delVisibility, setDelVisibility] = useState<boolean>(false);
useEffect(() => {
eventBus.on('updateUnitInfo', updateUnitInfo);
eventBus.on('hideFlag', hideFlag);
return () => {
eventBus.off('updateUnitInfo', updateUnitInfo);
eventBus.off('hideFlag', hideFlag);
};
}, [])
const updateUnitInfo = (info: any) => {
setUnitName(info[1]?.unitName);
setunitId(info[1]?.id);
if (info[0] == '删除') {
setIsDelFlag(true);
setDelVisibility(true)
} else {
setIsDelFlag(false);
setVisibility(true);
}
}
const hideFlag = (val: boolean) => { setShowFlag(val) }
const submit = () => { const submit = () => {
const searchParams = new URLSearchParams(location.search); const searchParams = new URLSearchParams(location.search);
const sysType = searchParams.get('sysType'); const sysType = searchParams.get('sysType');
let params = {
unitAddressEditOrAdd({
parentId: 1, parentId: 1,
sysType: sysTypeStr[sysType], sysType: sysTypeStr[sysType],
unitName: unitName, unitName: unitName,
}).then((res) => { id: unitId,
delFlag: isDelFlag ? 1 : 0
}
unitAddressEditOrAdd(params).then((res) => {
if (res.result == 'success') { if (res.result == 'success') {
setShowFlag(true); setShowFlag(true);
setUnitName('') setUnitName('');
setunitId(null);
setVisibility(false); setVisibility(false);
message.success('添加成功!') if (isDelFlag) {
}else { setDelVisibility(false);
setShowFlag(false)
message.success('删除成功!');
eventBus.emit('getUnitList', '删除成功');
}else if (unitId) {
message.success('修改成功!');
eventBus.emit('getUnitList', '修改成功');
} else {
message.success('添加成功!');
eventBus.emit('getUnitList', '添加成功');
}
} else {
message.error(res?.errorMsg) message.error(res?.errorMsg)
} }
}) })
@ -37,13 +78,15 @@ export default function Page() {
return ( return (
<div className={styles.wzgl_warp}> <div className={styles.wzgl_warp}>
<div className={styles.earthWarp}> <div className={styles.earthWarp}>
<div className={styles.earthCon} onClick={() => setVisibility(true)}> <div className={styles.earthCon} onClick={() => {
if (showFlag) return
setVisibility(true)
}}>
{/* 小红旗 */} {/* 小红旗 */}
{ showFlag && <img src={require('../../../../assets/images/googleEarth/flag.png')} width={30} height={30}/> } {showFlag && <img src={require('../../../../assets/images/googleEarth/flag.png')} width={30} height={30} />}
</div> </div>
</div> </div>
{/* 开机认证 */}
<Modal <Modal
title="位置信息" title="位置信息"
open={visibility} open={visibility}
@ -67,10 +110,27 @@ export default function Page() {
<div className='flex_jE mt20'> <div className='flex_jE mt20'>
<ButtonComp style={{ marginRight: 20 }} text={'定位'} onClick={() => setVisibility(false)} /> <ButtonComp style={{ marginRight: 20 }} text={'定位'} onClick={() => setVisibility(false)} />
<ButtonComp style={{ marginRight: 20 }} text={'确定'} onClick={() => {submit()}} /> <ButtonComp style={{ marginRight: 20 }} text={'确定'} onClick={() => { submit() }} />
<ButtonComp type='cancel' text={'取消'} onClick={() => setVisibility(false)} /> <ButtonComp type='cancel' text={'取消'} onClick={() => setVisibility(false)} />
</div> </div>
</Modal> </Modal>
<Modal
title="提示"
open={delVisibility}
centered
width={300}
onCancel={() => setDelVisibility(false)}
footer={null}
maskClosable={false}
>
<div></div>
<div className='flex_jE mt20'>
<ButtonComp style={{ marginRight: 20 }} text={'确定'} onClick={() => { submit() }} />
<ButtonComp type='cancel' text={'取消'} onClick={() => setDelVisibility(false)} />
</div>
</Modal>
</div> </div>
); );
} }

@ -0,0 +1,5 @@
import { EventEmitter } from 'events';
const eventBus = new EventEmitter();
export default eventBus;
Loading…
Cancel
Save