修改一下
This commit is contained in:
@@ -1,150 +1,151 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Outlet, useNavigate, useLocation } from 'react-router-dom';
|
||||
import {
|
||||
Layout,
|
||||
Menu,
|
||||
Button,
|
||||
Avatar,
|
||||
Space,
|
||||
ConfigProvider,
|
||||
theme,
|
||||
Breadcrumb,
|
||||
Badge
|
||||
import {
|
||||
Layout,
|
||||
Menu,
|
||||
Button,
|
||||
Avatar,
|
||||
Space,
|
||||
ConfigProvider,
|
||||
theme,
|
||||
Breadcrumb,
|
||||
Badge
|
||||
} from 'antd';
|
||||
import {
|
||||
DashboardOutlined,
|
||||
ExperimentOutlined,
|
||||
VideoCameraOutlined,
|
||||
BellOutlined,
|
||||
DownloadOutlined,
|
||||
UserOutlined,
|
||||
LogoutOutlined,
|
||||
MenuUnfoldOutlined,
|
||||
MenuFoldOutlined,
|
||||
GlobalOutlined,
|
||||
TeamOutlined
|
||||
import {
|
||||
DashboardOutlined,
|
||||
ExperimentOutlined,
|
||||
VideoCameraOutlined,
|
||||
BellOutlined,
|
||||
DownloadOutlined,
|
||||
UserOutlined,
|
||||
LogoutOutlined,
|
||||
MenuUnfoldOutlined,
|
||||
MenuFoldOutlined,
|
||||
GlobalOutlined,
|
||||
TeamOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { MOCK_USER } from '../constants';
|
||||
|
||||
import logo from '../assets/logo.png';
|
||||
const { Header, Sider, Content } = Layout;
|
||||
|
||||
export default function AppLayout() {
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
const [time, setTime] = useState(new Date().toLocaleString());
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
const [time, setTime] = useState(new Date().toLocaleString());
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
// 从 localStorage 获取真实用户信息
|
||||
const userJson = localStorage.getItem('user');
|
||||
const user = userJson ? JSON.parse(userJson) : MOCK_USER;
|
||||
// 从 localStorage 获取真实用户信息
|
||||
const userJson = localStorage.getItem('user');
|
||||
const user = userJson ? JSON.parse(userJson) : MOCK_USER;
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem('isAuthenticated');
|
||||
localStorage.removeItem('user');
|
||||
localStorage.removeItem('token');
|
||||
navigate('/login');
|
||||
};
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem('isAuthenticated');
|
||||
localStorage.removeItem('user');
|
||||
localStorage.removeItem('token');
|
||||
navigate('/login');
|
||||
};
|
||||
|
||||
const menuItems = [
|
||||
{ key: '/', icon: <DashboardOutlined />, label: '概览控制台', roles: ['admin', 'operator', 'viewer'] },
|
||||
{ key: '/devices', icon: <ExperimentOutlined />, label: '设备管理', roles: ['admin', 'operator'] },
|
||||
{ key: '/video', icon: <VideoCameraOutlined />, label: '在线视频', roles: ['admin', 'operator', 'viewer'] },
|
||||
{ key: '/alerts', icon: <BellOutlined />, label: '警报中心', roles: ['admin', 'operator'] },
|
||||
{ key: '/downloads', icon: <DownloadOutlined />, label: '视频下载', roles: ['admin', 'operator'] },
|
||||
{ key: '/users', icon: <TeamOutlined />, label: '用户管理', roles: ['admin'] },
|
||||
{ key: '/roles', icon: <UserOutlined />, label: '角色权限', roles: ['admin'] },
|
||||
];
|
||||
const menuItems = [
|
||||
{ key: '/', icon: <DashboardOutlined />, label: '概览控制台', roles: ['admin', 'operator', 'viewer'] },
|
||||
{ key: '/devices', icon: <ExperimentOutlined />, label: '设备管理', roles: ['admin', 'operator'] },
|
||||
{ key: '/video', icon: <VideoCameraOutlined />, label: '在线视频', roles: ['admin', 'operator', 'viewer'] },
|
||||
{ key: '/alerts', icon: <BellOutlined />, label: '警报中心', roles: ['admin', 'operator'] },
|
||||
{ key: '/downloads', icon: <DownloadOutlined />, label: '视频下载', roles: ['admin', 'operator'] },
|
||||
{ key: '/users', icon: <TeamOutlined />, label: '用户管理', roles: ['admin'] },
|
||||
{ key: '/roles', icon: <UserOutlined />, label: '角色权限', roles: ['admin'] },
|
||||
{ key: '/serialNumGenerate', icon: <UserOutlined />, label: '序列号生成', roles: ['admin'] },
|
||||
];
|
||||
|
||||
const filteredMenu = menuItems.filter(item => item.roles.includes(user.role));
|
||||
const filteredMenu = menuItems.filter(item => item.roles.includes(user.role));
|
||||
|
||||
const currentPathLabel = menuItems.find(i => i.key === location.pathname)?.label || '概览控制台';
|
||||
const currentPathLabel = menuItems.find(i => i.key === location.pathname)?.label || '概览控制台';
|
||||
|
||||
return (
|
||||
<ConfigProvider
|
||||
theme={{
|
||||
algorithm: theme.defaultAlgorithm,
|
||||
token: {
|
||||
colorPrimary: '#1890ff',
|
||||
borderRadius: 2,
|
||||
},
|
||||
components: {
|
||||
Layout: {
|
||||
headerBg: '#fff',
|
||||
siderBg: '#001529',
|
||||
},
|
||||
Menu: {
|
||||
darkItemBg: '#001529',
|
||||
darkItemSelectedBg: '#1890ff',
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Layout style={{ minHeight: '100vh' }}>
|
||||
<Sider trigger={null} collapsible collapsed={collapsed} width={200} theme="dark">
|
||||
<div className="h-16 flex items-center justify-center border-b border-white/10 overflow-hidden">
|
||||
<Space size="small" className="px-2">
|
||||
<GlobalOutlined style={{ fontSize: 24, color: '#1890ff' }} />
|
||||
{!collapsed && <span className="text-white font-bold text-lg whitespace-nowrap">RobotMaster AI</span>}
|
||||
</Space>
|
||||
</div>
|
||||
<Menu
|
||||
theme="dark"
|
||||
mode="inline"
|
||||
selectedKeys={[location.pathname]}
|
||||
items={filteredMenu}
|
||||
onClick={({ key }) => navigate(key)}
|
||||
/>
|
||||
{!collapsed && (
|
||||
<div className="absolute bottom-4 left-4 right-4 p-2 bg-white/5 rounded text-[12px] text-gray-400">
|
||||
当前权限: <span className="text-white font-bold">{user.role === 'admin' ? '系统管理员' : user.role === 'operator' ? '操作员' : '观察员'}</span>
|
||||
</div>
|
||||
)}
|
||||
</Sider>
|
||||
<Layout>
|
||||
<Header className="px-6 flex items-center justify-between shadow-sm border-b border-gray-100 h-16 bg-white shrink-0 z-10">
|
||||
<div className="flex items-center gap-4">
|
||||
<Button
|
||||
type="text"
|
||||
icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
|
||||
onClick={() => setCollapsed(!collapsed)}
|
||||
style={{ fontSize: '16px', width: 40, height: 40 }}
|
||||
/>
|
||||
<Breadcrumb
|
||||
items={[
|
||||
{ title: '系统首页' },
|
||||
{ title: currentPathLabel }
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
return (
|
||||
<ConfigProvider
|
||||
theme={{
|
||||
algorithm: theme.defaultAlgorithm,
|
||||
token: {
|
||||
colorPrimary: '#1890ff',
|
||||
borderRadius: 2,
|
||||
},
|
||||
components: {
|
||||
Layout: {
|
||||
headerBg: '#fff',
|
||||
siderBg: '#001529',
|
||||
},
|
||||
Menu: {
|
||||
darkItemBg: '#001529',
|
||||
darkItemSelectedBg: '#1890ff',
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Layout style={{ minHeight: '100vh' }}>
|
||||
<Sider trigger={null} collapsible collapsed={collapsed} width={220} theme="dark">
|
||||
<div className="h-16 flex items-center justify-center border-b border-white/10 overflow-hidden">
|
||||
<Space size="small" className="px-2">
|
||||
<img src={logo} alt="Logo" style={{ width: "24px", height: "24px" }} />
|
||||
{!collapsed && <span className="text-white font-bold text-lg whitespace-nowrap">机器人智慧服务系统</span>}
|
||||
</Space>
|
||||
</div>
|
||||
<Menu
|
||||
theme="dark"
|
||||
mode="inline"
|
||||
selectedKeys={[location.pathname]}
|
||||
items={filteredMenu}
|
||||
onClick={({ key }) => navigate(key)}
|
||||
/>
|
||||
{!collapsed && (
|
||||
<div className="absolute bottom-4 left-4 right-4 p-2 bg-white/5 rounded text-[12px] text-gray-400">
|
||||
当前权限: <span className="text-white font-bold">{user.role === 'admin' ? '系统管理员' : user.role === 'operator' ? '操作员' : '观察员'}</span>
|
||||
</div>
|
||||
)}
|
||||
</Sider>
|
||||
<Layout>
|
||||
<Header className="px-6 flex items-center justify-between shadow-sm border-b border-gray-100 h-16 bg-white shrink-0 z-10">
|
||||
<div className="flex items-center gap-4">
|
||||
<Button
|
||||
type="text"
|
||||
icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
|
||||
onClick={() => setCollapsed(!collapsed)}
|
||||
style={{ fontSize: '16px', width: 40, height: 40 }}
|
||||
/>
|
||||
<Breadcrumb
|
||||
items={[
|
||||
{ title: '系统首页' },
|
||||
{ title: currentPathLabel }
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-6">
|
||||
<div className="flex items-center gap-3 pr-6 border-r border-gray-100">
|
||||
<span className="text-gray-400 font-mono text-[13px]">{time}</span>
|
||||
<Badge status="success" />
|
||||
<span className="text-gray-800 font-medium">{user.name}</span>
|
||||
<Avatar src={user.avatar} size="small" icon={<UserOutlined />} />
|
||||
</div>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
icon={<LogoutOutlined />}
|
||||
onClick={handleLogout}
|
||||
className="font-bold text-[12px] uppercase"
|
||||
>
|
||||
退出登录
|
||||
</Button>
|
||||
</div>
|
||||
</Header>
|
||||
<Content className="p-4 overflow-y-auto bg-[#f4f7f9] min-h-0">
|
||||
<Outlet />
|
||||
</Content>
|
||||
</Layout>
|
||||
</Layout>
|
||||
</ConfigProvider>
|
||||
);
|
||||
<div className="flex items-center gap-6">
|
||||
<div className="flex items-center gap-3 pr-6 border-r border-gray-100">
|
||||
<span className="text-gray-400 font-mono text-[13px]">{time}</span>
|
||||
<Badge status="success" />
|
||||
<span className="text-gray-800 font-medium">{user.name}</span>
|
||||
<Avatar src={user.avatar} size="small" icon={<UserOutlined />} />
|
||||
</div>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
icon={<LogoutOutlined />}
|
||||
onClick={handleLogout}
|
||||
className="font-bold text-[12px] uppercase"
|
||||
>
|
||||
退出登录
|
||||
</Button>
|
||||
</div>
|
||||
</Header>
|
||||
<Content className="p-4 overflow-y-auto bg-[#f4f7f9] min-h-0">
|
||||
<Outlet />
|
||||
</Content>
|
||||
</Layout>
|
||||
</Layout>
|
||||
</ConfigProvider>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user