工单布局修改
This commit is contained in:
@@ -7,13 +7,13 @@ import zhCN from 'antd/locale/zh_CN';
|
||||
import {
|
||||
DashboardOutlined, ExperimentOutlined, VideoCameraOutlined,
|
||||
BellOutlined, UserOutlined, LogoutOutlined,
|
||||
AppstoreOutlined, SettingOutlined
|
||||
AppstoreOutlined, SettingOutlined, MenuUnfoldOutlined, MenuFoldOutlined
|
||||
} from '@ant-design/icons';
|
||||
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 { setCurrentStation, clearStation } from '../store/stationSlice';
|
||||
import { getMenuList } from '../api/mune';
|
||||
import { getStationList } from '../api/stationManage';
|
||||
import envConfig from '../../env';
|
||||
@@ -30,12 +30,9 @@ export default function AppLayout() {
|
||||
const location = useLocation();
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
// 全局用户信息
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
// 全局场站信息
|
||||
const { currentStation, stationId } = useSelector((state: RootState) => state.station);
|
||||
|
||||
// 获取场站列表
|
||||
const getStationData = () => {
|
||||
const params = {
|
||||
pageNum: 1,
|
||||
@@ -46,8 +43,6 @@ export default function AppLayout() {
|
||||
if (res.code === 200) {
|
||||
const list = res.rows || [];
|
||||
setStationList(list);
|
||||
|
||||
// 如果没有选中任何场站,默认选第一个
|
||||
if (!currentStation && list.length > 0) {
|
||||
dispatch(setCurrentStation(list[0]));
|
||||
}
|
||||
@@ -55,15 +50,13 @@ export default function AppLayout() {
|
||||
});
|
||||
};
|
||||
|
||||
// 切换场站
|
||||
const handleStationChange = (id: number) => {
|
||||
const station = stationList.find(s => s.id === id);
|
||||
if (station) {
|
||||
dispatch(setCurrentStation(station)); // 👈 存全局
|
||||
dispatch(setCurrentStation(station));
|
||||
}
|
||||
};
|
||||
|
||||
// 获取菜单
|
||||
const getMenu = () => {
|
||||
const data = { pageNum: 1, pageSize: 10000 };
|
||||
getMenuList(data).then(res => {
|
||||
@@ -75,7 +68,6 @@ export default function AppLayout() {
|
||||
});
|
||||
};
|
||||
|
||||
// 图标映射
|
||||
const getIcon = (path) => {
|
||||
if (path.includes('overview')) return <DashboardOutlined />;
|
||||
if (path.includes('device')) return <ExperimentOutlined />;
|
||||
@@ -87,17 +79,15 @@ export default function AppLayout() {
|
||||
return <AppstoreOutlined />;
|
||||
};
|
||||
|
||||
// 菜单
|
||||
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()); // 👈 清空
|
||||
dispatch(clearStation());
|
||||
navigate('/login', { replace: true });
|
||||
};
|
||||
|
||||
@@ -131,6 +121,20 @@ export default function AppLayout() {
|
||||
padding: '0 16px'
|
||||
}}>
|
||||
<Space size="large" style={{ display: 'flex', alignItems: 'center' }}>
|
||||
|
||||
{/* ====================== 收起/展开按钮 ====================== */}
|
||||
<Button
|
||||
type="text"
|
||||
icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
|
||||
onClick={() => setCollapsed(!collapsed)}
|
||||
style={{
|
||||
fontSize: '16px',
|
||||
color: '#fff',
|
||||
width: 40,
|
||||
height: 40,
|
||||
}}
|
||||
/>
|
||||
|
||||
<Space size="small">
|
||||
<img src={logo} alt="Logo" style={{ width: 24, height: 24 }} />
|
||||
{!collapsed && (
|
||||
@@ -140,7 +144,6 @@ export default function AppLayout() {
|
||||
)}
|
||||
</Space>
|
||||
|
||||
{/* 全局场站选择器 */}
|
||||
<Select
|
||||
value={stationId}
|
||||
placeholder="请选择电站"
|
||||
@@ -181,7 +184,7 @@ export default function AppLayout() {
|
||||
collapsible
|
||||
collapsed={collapsed}
|
||||
trigger={null}
|
||||
width={220}
|
||||
width={150}
|
||||
theme="light"
|
||||
style={{ borderRight: '1px solid #e5e7eb' }}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user