From fee0d01707dc93426b31aa66b197fda51a8bd1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E8=AA=89=E7=A8=8B?= <2659568239@qq.com> Date: Fri, 26 Jan 2024 18:16:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=B7=AF=E7=94=B1=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=87=BA=E5=8E=BB=E5=90=8E=E9=A1=B6=E9=83=A8=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=A1=86=E5=92=8C=E5=8F=B3=E4=BE=A7=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9C=AA=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes/index.ts | 2 +- src/layouts/LeftMenuOne/index.tsx | 29 +++++++++- src/layouts/index.tsx | 56 ++++++++++++++----- src/pages/CoreSystemEntrance/index.tsx | 2 +- .../InitialSystem/DeviceInstall/index.tsx | 2 +- src/pages/InitialSystem/PowerOnAuth/index.tsx | 2 +- src/pages/InstallExe/exeDialog/CodeManage.tsx | 2 +- src/pages/InstallExe/exeDialog/CoreArea.tsx | 2 +- src/pages/InstallExe/exeDialog/DutyArea.tsx | 2 +- .../DeviceRegister/AdminsTab/index.tsx | 17 +++++- src/utils/index.ts | 46 ++++++++------- src/utils/sysType.ts | 27 +++++++++ 12 files changed, 141 insertions(+), 48 deletions(-) create mode 100644 src/utils/sysType.ts diff --git a/config/routes/index.ts b/config/routes/index.ts index ce9926d..5a6e3f2 100644 --- a/config/routes/index.ts +++ b/config/routes/index.ts @@ -137,7 +137,7 @@ const routes = [ // 建设中页面 { - path: '/construction', + path: '/construction/:fileType', component: '@/pages/construction' }, diff --git a/src/layouts/LeftMenuOne/index.tsx b/src/layouts/LeftMenuOne/index.tsx index 6cd9de6..3c06b1e 100644 --- a/src/layouts/LeftMenuOne/index.tsx +++ b/src/layouts/LeftMenuOne/index.tsx @@ -105,6 +105,31 @@ const LeftMenuCom: FC = ({ data }) => { } ]; + const treeData1 = [ + { + title: '所有单位位置', + key: 'root', + selectable: true, + isFolder: true, + children: [ + { + title: 'aadw', + key: 'user', + }, + ], + } + ]; + + const nameType = { + "设备注册": treeData, + '单位位置管理': treeData1 + } + + const urlType = { + "设备注册": '/registerManage/deviceRegister', + '单位位置管理': '/registerManage/unitLocation' + } + return (
{list.map((item: any, index: number) => { @@ -131,13 +156,13 @@ const LeftMenuCom: FC = ({ data }) => { onRightClick={({ event, node }) => handleRightClick(event, node)} onSelect={(e, {node}) => { if (node.key === 'root') { - history.push(`/registerManage/deviceRegister/${urlStr}`) + history.push(`${urlType[item.name]}/${urlStr}`) } handleSelect(e, item.name) }} selectedKeys={selectedKeys} - treeData={treeData} + treeData={nameType[item.name]} blockNode={true} defaultExpandAll={true} /> diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index ca71fa2..e69ba6c 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -1,5 +1,5 @@ -import { Outlet, history, useLocation, useParams } from 'umi'; +import { Outlet, history, useLocation, useParams, useRoutes } from 'umi'; import styles from './index.less'; import { useEffect, useState } from 'react'; import { MenuType, tabsType } from '@/utils/menu'; @@ -15,6 +15,7 @@ import theme from '@/styles/antd.theme'; dayjs.locale('zh-cn'); import moment from 'moment' +import {getMenuType, getTabKey } from '@/utils'; moment.locale('ZH-cn') @@ -77,20 +78,49 @@ export default function Layout() { setSelectVal(info?.layoutInfo.selectVal); setTabList([...tabsType[info?.layoutInfo.selectVal]]); } else { - setTabList([...tabsType[selectVal]]); - let obj: any = { - selectVal: selectVal, - active: active, - activeName: activeName, - } - localStorage.setItem(`${urlParams?.fileType}`, JSON.stringify({ ...info, layoutInfo: obj })) + upDateLayout() } }, []) useEffect(() => { + upDateLayout() setRouteName(getCurrentPageName(location.pathname)) }, [location]); + // 更新布局数据 + const upDateLayout = () => { + const index = location.pathname.lastIndexOf('/'); + let pathname = location.pathname.substring(0, index); + let menType, tabKey; + + if (!['/registerManage/deviceRegister', '/registerManage/unitLocation'].includes(pathname)) { + menType = getMenuType(pathname); + tabKey = getTabKey(menType); + + if(!menType || !tabKey) return + + if ( + info?.layoutInfo?.selectVal != tabKey || + info?.layoutInfo?.activeName != menType + ) { + setActiveName(menType); + setSelectVal(Number(tabKey)); + setTabList([...tabsType[Number(tabKey)]]); + } + }else if (pathname == '/registerManage/unitLocation') { + setActive(2) + setActiveName('位置管理'); + setSelectVal(6); + setTabList([...tabsType[6]]); + }else if ('/registerManage/deviceRegister') { + setActive(1) + setActiveName('注册管理'); + setSelectVal(6); + setTabList([...tabsType[6]]); + } + } + + // 页面销毁前记录下当前布局信息 window.addEventListener('beforeunload', function (event) { let obj: any = { @@ -106,9 +136,9 @@ export default function Layout() { if (tabList.length > 0 && !info?.layoutInfo) { setActiveName(tabList[0].name) let info = MenuType[tabList[0].name]; - + if (isTreeType(info)) return - + if (info[0].data) { history.push(`${info[0].data[0].url}/${urlStr}`) } else { @@ -124,17 +154,15 @@ export default function Layout() { if (info[0]?.name === '设备注册') { isReturn = true; history.push(`/registerManage/deviceRegister/${urlStr}`); - // return navigateToPath(info, '/registerManage/deviceRegister'); } if (info[0]?.name === '单位位置管理') { isReturn = true; history.push(`/registerManage/unitLocation/${urlStr}`); - //return navigateToPath(info, '/registerManage/unitLocation'); } } return isReturn; }; - + // 获取路由名称 const getCurrentPageName = (pathname: string) => { @@ -202,7 +230,7 @@ export default function Layout() { if (isTreeType(info)) return if (info.length == 0 || info[0].data && info[0].data.length == 0) { - history.push('/construction'); + history.push(`/construction/${urlStr}`); return } diff --git a/src/pages/CoreSystemEntrance/index.tsx b/src/pages/CoreSystemEntrance/index.tsx index 15b2990..fe357fc 100644 --- a/src/pages/CoreSystemEntrance/index.tsx +++ b/src/pages/CoreSystemEntrance/index.tsx @@ -79,7 +79,7 @@ const CoreSystemEntrance: FC = ({ }) => { } else if (key == '二' && pin == 'test') { initData() // 记录登陆成功状态 - localStorage.setItem(`${urlParams?.fileType}`, JSON.stringify({ ...info, pingLoginStatus: true })) + localStorage.setItem(`${urlParams?.fileType}`, JSON.stringify({ ...info, pingLoginStatus: true, layoutInfo: null })) // 登录成功进入系统 history.push(`/registerManage/deviceRegister/${urlParams?.fileType}${location?.search}`) diff --git a/src/pages/InitialSystem/DeviceInstall/index.tsx b/src/pages/InitialSystem/DeviceInstall/index.tsx index 391e17b..875a6b3 100644 --- a/src/pages/InitialSystem/DeviceInstall/index.tsx +++ b/src/pages/InitialSystem/DeviceInstall/index.tsx @@ -4,7 +4,7 @@ import { Input, Upload, UploadProps, message } from 'antd'; import ButtonComp from '@/components/ButtonComp'; import { college_table_query, deviceInit_init, deviceInstall_deviceInstall } from '@/services/api'; import { useParams } from 'umi'; -import { fileStr, sysType, sysTypeStr } from '@/utils'; +import { fileStr, sysType, sysTypeStr } from '@/utils/sysType'; interface PageProps { } diff --git a/src/pages/InitialSystem/PowerOnAuth/index.tsx b/src/pages/InitialSystem/PowerOnAuth/index.tsx index a9709d8..651414b 100644 --- a/src/pages/InitialSystem/PowerOnAuth/index.tsx +++ b/src/pages/InitialSystem/PowerOnAuth/index.tsx @@ -5,7 +5,7 @@ import ButtonComp from '@/components/ButtonComp'; import { college_table_query } from '@/services/api'; import { useParams } from 'umi'; import DEV from '@/utils/env/dev'; -import { countType } from '@/utils'; +import { countType } from '@/utils/sysType'; interface PageProps { } diff --git a/src/pages/InstallExe/exeDialog/CodeManage.tsx b/src/pages/InstallExe/exeDialog/CodeManage.tsx index 6c4220f..dd52e0a 100644 --- a/src/pages/InstallExe/exeDialog/CodeManage.tsx +++ b/src/pages/InstallExe/exeDialog/CodeManage.tsx @@ -1,7 +1,7 @@ import React, { FC, useEffect, useState } from 'react'; import styles from './index.less'; import { Input, Progress, message } from 'antd'; -import { countType } from '@/utils'; +import { countType } from '@/utils/sysType'; import { useParams } from 'umi'; import DEV from '@/utils/env/dev'; diff --git a/src/pages/InstallExe/exeDialog/CoreArea.tsx b/src/pages/InstallExe/exeDialog/CoreArea.tsx index dd44220..8dbbcaf 100644 --- a/src/pages/InstallExe/exeDialog/CoreArea.tsx +++ b/src/pages/InstallExe/exeDialog/CoreArea.tsx @@ -1,7 +1,7 @@ import React, { FC, useEffect, useState } from 'react'; import styles from './index.less'; import { Input, Progress, message } from 'antd'; -import { countType, sysType } from '@/utils'; +import { countType, sysType } from '@/utils/sysType'; import { useParams } from 'umi'; import DEV from '@/utils/env/dev'; diff --git a/src/pages/InstallExe/exeDialog/DutyArea.tsx b/src/pages/InstallExe/exeDialog/DutyArea.tsx index b7cd3c4..45f3c5e 100644 --- a/src/pages/InstallExe/exeDialog/DutyArea.tsx +++ b/src/pages/InstallExe/exeDialog/DutyArea.tsx @@ -1,7 +1,7 @@ import React, { FC, useEffect, useState } from 'react'; import styles from './index.less'; import { Input, Progress, message } from 'antd'; -import { countType, sysType } from '@/utils'; +import { countType, sysType } from '@/utils/sysType'; import { useParams } from 'umi'; import DEV from '@/utils/env/dev'; diff --git a/src/pages/Register/RegisterManage/DeviceRegister/AdminsTab/index.tsx b/src/pages/Register/RegisterManage/DeviceRegister/AdminsTab/index.tsx index cb7b9a9..969d7f8 100644 --- a/src/pages/Register/RegisterManage/DeviceRegister/AdminsTab/index.tsx +++ b/src/pages/Register/RegisterManage/DeviceRegister/AdminsTab/index.tsx @@ -5,10 +5,14 @@ import { rowClassName } from '@/utils'; import { Form, Input, Pagination, Radio, Select, Table, message } from 'antd'; import { useEffect, useState } from 'react'; import styles from './index.less' +import { useLocation, useParams, history } from 'umi'; const { TextArea } = Input; export default function Page() { + const urlParams = useParams(); + const location = useLocation() + const [tableData, setTableData] = useState([]); const [pageNumber, setPageNumber] = useState(1); const [pageSize, setpageSize] = useState(10); @@ -19,6 +23,9 @@ export default function Page() { const [form] = Form.useForm(); const [selectedRowKeys, setSelectedRowKeys] = useState([]); + let sysData = localStorage.getItem(`${urlParams?.fileType}`); + let info = sysData ? JSON.parse(sysData) : null; + const columns: any = [ { title: '单位名称', dataIndex: 'seatName', key: 'seatName', align: 'center' }, { title: '系统名称', dataIndex: 'sysName', key: 'sysName', align: 'center' }, @@ -144,7 +151,15 @@ export default function Page() { ]}> - { }} /> + { + let obj: any = { + selectVal: 6, + active: 2, + activeName: '位置管理', + } + localStorage.setItem(`${urlParams?.fileType}`, JSON.stringify({ ...info, layoutInfo: obj })) + history.push(`/registerManage/unitLocation/${urlParams?.fileType}${location?.search}`) + }} />
diff --git a/src/utils/index.ts b/src/utils/index.ts index e8e29f7..a3a254a 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,31 +1,29 @@ -export const countType = { - 'hx1': '核心区一', - 'hx2': '核心区二', - 'zq1': '执勤区一', - 'zq2': '执勤区二' -} - -export const fileStr = { - 'hx1': 'hx', - 'hx2': 'hx', - 'zq1': 'zq', - 'zq2': 'zq' -} +import { MenuType, tabsType } from "./menu"; -export const sysType = { - 'hx1': 'up_', - 'hx2': 'down_', - 'zq1': 'up_', - 'zq2': 'down_' +// 通过url获取菜单类型 +export const getMenuType = (url: string) => { + for (const key in MenuType) { + const menuItems = MenuType[key]; + for (const item of menuItems) { + if (item.url === url || (item.data && item.data.some(dataItem => dataItem.url === url))) { + return key; + } + } + } + return null; } -export const sysTypeStr = { - 'up_hx': '上级核心区', - 'up_zq': '上级执勤区', - 'down_hx': '下级核心区', - 'down_zq': '下级执勤区' +// 通过菜单名称获取到下拉框的key值 +export const getTabKey = (name: string) => { + for (const [key, items] of Object.entries(tabsType)) { + if (items.some((item: { name: string; }) => item.name === name)) { + return key; + } + } + return null; } -export const rowClassName = (record:any, index: any) => { +// 设置表格行样式颜色 +export const rowClassName = (record: any, index: any) => { return index % 2 === 0 ? 'even-row' : 'odd-row'; }; \ No newline at end of file diff --git a/src/utils/sysType.ts b/src/utils/sysType.ts new file mode 100644 index 0000000..49ccdd8 --- /dev/null +++ b/src/utils/sysType.ts @@ -0,0 +1,27 @@ +export const countType = { + 'hx1': '核心区一', + 'hx2': '核心区二', + 'zq1': '执勤区一', + 'zq2': '执勤区二' +} + +export const fileStr = { + 'hx1': 'hx', + 'hx2': 'hx', + 'zq1': 'zq', + 'zq2': 'zq' +} + +export const sysType = { + 'hx1': 'up_', + 'hx2': 'down_', + 'zq1': 'up_', + 'zq2': 'down_' +} + +export const sysTypeStr = { + 'up_hx': '上级核心区', + 'up_zq': '上级执勤区', + 'down_hx': '下级核心区', + 'down_zq': '下级执勤区' +} \ No newline at end of file