From de1998a9a8990c6ee2ebb296c5c1768999e4ab51 Mon Sep 17 00:00:00 2001
From: mmc <1556375442@qq.com>
Date: Wed, 6 May 2026 16:49:07 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/Layout.tsx | 113 ++++++++++++++++++++++++------------
src/pages/Organization.tsx | 18 +++---
src/pages/StationManage.tsx | 10 ++--
src/pages/UserPage.tsx | 2 +-
src/store/index.ts | 2 +
src/store/stationSlice.ts | 42 ++++++++++++++
6 files changed, 135 insertions(+), 52 deletions(-)
create mode 100644 src/store/stationSlice.ts
diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx
index 9b66dbb..31b8e1b 100644
--- a/src/components/Layout.tsx
+++ b/src/components/Layout.tsx
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';
import { Outlet, useNavigate, useLocation } from 'react-router-dom';
import {
- Layout, Menu, Button, Space, ConfigProvider, theme
+ Layout, Menu, Button, Space, ConfigProvider, theme, Select
} from 'antd';
import zhCN from 'antd/locale/zh_CN';
import {
@@ -13,37 +13,68 @@ import logo from '../assets/logo.png';
import { useSelector } from 'react-redux';
import { RootState, useAppDispatch } from '../store';
import { logout } from '../store/userSlice';
+import { setCurrentStation, clearStation } from '../store/stationSlice'; // 👈 引入
import { getMenuList } from '../api/mune';
+import { getStationList } from '../api/stationManage';
const { Header, Sider, Content } = Layout;
export default function AppLayout() {
const [collapsed, setCollapsed] = useState(false);
const [time, setTime] = useState(new Date().toLocaleString());
- const [menuList, setMenuList] = useState([]); // 一级菜单列表
+ const [menuList, setMenuList] = useState([]);
+ const [stationList, setStationList] = useState([]);
+
const navigate = useNavigate();
const location = useLocation();
- const { userInfo } = useSelector((state: RootState) => state.user);
const dispatch = useAppDispatch();
- // ======================
- // 只取一级菜单(parentId=0)
- // ======================
+ // 全局用户信息
+ const { userInfo } = useSelector((state: RootState) => state.user);
+ // 全局场站信息
+ const { currentStation, stationId } = useSelector((state: RootState) => state.station);
+
+ // 获取场站列表
+ const getStationData = () => {
+ const params = {
+ pageNum: 1,
+ pageSize: 9999,
+ orgId: userInfo?.orgId,
+ };
+ getStationList(params).then(res => {
+ if (res.code === 200) {
+ const list = res.rows || [];
+ setStationList(list);
+
+ // 如果没有选中任何场站,默认选第一个
+ if (!currentStation && list.length > 0) {
+ dispatch(setCurrentStation(list[0]));
+ }
+ }
+ });
+ };
+
+ // 切换场站
+ const handleStationChange = (id: number) => {
+ const station = stationList.find(s => s.id === id);
+ if (station) {
+ dispatch(setCurrentStation(station)); // 👈 存全局
+ }
+ };
+
+ // 获取菜单
const getMenu = () => {
const data = { pageNum: 1, pageSize: 10000 };
getMenuList(data).then(res => {
if (res.code == 200) {
const rawList = res.rows || [];
- // 只保留 parentId=0 的一级菜单
const topMenus = rawList.filter(item => item.parentId === 0);
setMenuList(topMenus);
}
});
};
- // ======================
- // 菜单图标映射
- // ======================
+ // 图标映射
const getIcon = (path) => {
if (path.includes('overview')) return ;
if (path.includes('device')) return ;
@@ -55,25 +86,26 @@ export default function AppLayout() {
return ;
};
- // ======================
- // 构造 antd menu items(纯平铺,无children)
- // ======================
+ // 菜单
const menuItems = menuList.map(item => ({
key: item.path || `/menu/${item.menuId}`,
icon: getIcon(item.path),
label: item.menuName,
}));
+ // 退出登录时清空场站
+ const handleLogout = async () => {
+ await dispatch(logout());
+ dispatch(clearStation()); // 👈 清空
+ navigate('/login', { replace: true });
+ };
+
useEffect(() => {
const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000);
getMenu();
+ getStationData();
return () => clearInterval(timer);
- }, []);
-
- const handleLogout = async () => {
- await dispatch(logout());
- navigate('/login', { replace: true });
- };
+ }, [userInfo]);
return (
-
-
- {!collapsed && (
-
- 光伏电站智能监控与运维系统
-
- )}
+
+
+
+ {!collapsed && (
+
+ 光伏电站智能监控与运维系统
+
+ )}
+
+
+ {/* 全局场站选择器 */}
+
@@ -115,11 +163,7 @@ export default function AppLayout() {
-
+
- {/* 纯平铺一级菜单 */}
-
+
diff --git a/src/pages/Organization.tsx b/src/pages/Organization.tsx
index 225e3fb..fe842e7 100644
--- a/src/pages/Organization.tsx
+++ b/src/pages/Organization.tsx
@@ -125,15 +125,15 @@ export default function Organization() {
{ title: '负责人', dataIndex: 'manager' },
{ title: '联系电话', dataIndex: 'phone' },
{ title: '邮箱', dataIndex: 'email' },
- {
- title: '状态',
- dataIndex: 'status',
- render: (s) => (
-
- {s == 1 ? '正常' : '禁用'}
-
- )
- },
+ //{
+ // title: '状态',
+ // dataIndex: 'status',
+ // render: (s) => (
+ //
+ // {s == 1 ? '正常' : '禁用'}
+ //
+ // )
+ //},
{
title: '操作',
render: (_, r) => (
diff --git a/src/pages/StationManage.tsx b/src/pages/StationManage.tsx
index ace4ac3..7aa7f05 100644
--- a/src/pages/StationManage.tsx
+++ b/src/pages/StationManage.tsx
@@ -206,11 +206,11 @@ export default function StationManage() {
}
},
{ title: '地址', dataIndex: 'address' },
- {
- title: '状态',
- dataIndex: 'status',
- render: s => s === 1 ? 启用 : 停用
- },
+ //{
+ // title: '状态',
+ // dataIndex: 'status',
+ // render: s => s === 1 ? 启用 : 停用
+ //},
{
title: '操作',
width: 400,
diff --git a/src/pages/UserPage.tsx b/src/pages/UserPage.tsx
index 6baa256..e5d63b9 100644
--- a/src/pages/UserPage.tsx
+++ b/src/pages/UserPage.tsx
@@ -513,7 +513,7 @@ export default function UserRolePage() {
权限:{r.roleKey}
等级:{r.roleLevel || '-'}
- {r.roleKey == "admin1" && 超级管理员}
+ {/*{r.roleKey == "admin1" && 超级管理员}*/}
}
/>
diff --git a/src/store/index.ts b/src/store/index.ts
index aa826ca..42f6d22 100644
--- a/src/store/index.ts
+++ b/src/store/index.ts
@@ -3,10 +3,12 @@ import { useDispatch } from 'react-redux';
// 👇 保留 import,但是把类型定义放到 store 后面
import userReducer from './userSlice';
+import stationReducer from './stationSlice'; // 👈 加这个
export const store = configureStore({
reducer: {
user: userReducer,
+ station: stationReducer, // 👈 加这个
},
});
diff --git a/src/store/stationSlice.ts b/src/store/stationSlice.ts
new file mode 100644
index 0000000..2c931ef
--- /dev/null
+++ b/src/store/stationSlice.ts
@@ -0,0 +1,42 @@
+import { createSlice } from '@reduxjs/toolkit';
+
+// 从 localStorage 加载上次选中的场站
+const loadStationFromStorage = () => {
+ try {
+ const station = localStorage.getItem('currentStation');
+ return station ? JSON.parse(station) : null;
+ } catch {
+ return null;
+ }
+};
+
+const initialState = {
+ currentStation: loadStationFromStorage(), // 当前选中场站(完整对象)
+ stationId: loadStationFromStorage()?.id || null, // 方便直接用 id
+};
+
+const stationSlice = createSlice({
+ name: 'station',
+ initialState,
+ reducers: {
+ // 设置当前场站
+ setCurrentStation: (state, action) => {
+ state.currentStation = action.payload;
+ state.stationId = action.payload?.id || null;
+ localStorage.setItem('currentStation', JSON.stringify(action.payload));
+ },
+ // 清空场站(退出登录时用)
+ clearStation: (state) => {
+ state.currentStation = null;
+ state.stationId = null;
+ localStorage.removeItem('currentStation');
+ },
+ },
+});
+
+export const { setCurrentStation, clearStation } = stationSlice.actions;
+export default stationSlice.reducer;
+
+
+//使用const { currentStation, stationId } = useSelector((state: RootState) => state.station);
+