登录框架搭建完成
This commit is contained in:
@@ -9,7 +9,8 @@ import {
|
||||
ConfigProvider,
|
||||
theme,
|
||||
Breadcrumb,
|
||||
Badge
|
||||
Badge,
|
||||
message
|
||||
} from 'antd';
|
||||
import {
|
||||
DashboardOutlined,
|
||||
@@ -26,6 +27,8 @@ import {
|
||||
} from '@ant-design/icons';
|
||||
import { MOCK_USER } from '../constants';
|
||||
import logo from '../assets/logo.png';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { RootState } from '../store';
|
||||
const { Header, Sider, Content } = Layout;
|
||||
|
||||
export default function AppLayout() {
|
||||
@@ -33,10 +36,7 @@ export default function AppLayout() {
|
||||
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;
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000);
|
||||
@@ -61,7 +61,7 @@ export default function AppLayout() {
|
||||
{ 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(userInfo.role));
|
||||
|
||||
const currentPathLabel = menuItems.find(i => i.key === location.pathname)?.label || '概览控制台';
|
||||
|
||||
@@ -85,6 +85,7 @@ export default function AppLayout() {
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
<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">
|
||||
@@ -100,11 +101,7 @@ export default function AppLayout() {
|
||||
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">
|
||||
@@ -127,8 +124,7 @@ export default function AppLayout() {
|
||||
<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 />} />
|
||||
<span className="text-gray-800 font-medium">{userInfo.username}</span>
|
||||
</div>
|
||||
<Button
|
||||
type="text"
|
||||
|
||||
Reference in New Issue
Block a user