xiugai
This commit is contained in:
@@ -23,12 +23,14 @@ import {
|
||||
MenuUnfoldOutlined,
|
||||
MenuFoldOutlined,
|
||||
GlobalOutlined,
|
||||
TeamOutlined
|
||||
TeamOutlined,
|
||||
MenuOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { MOCK_USER } from '../constants';
|
||||
import logo from '../assets/logo.png';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { RootState } from '../store';
|
||||
import { RootState, useAppDispatch } from '../store';
|
||||
import { logout } from '../store/userSlice';
|
||||
import { getMenuList } from '../api/mune';
|
||||
const { Header, Sider, Content } = Layout;
|
||||
|
||||
export default function AppLayout() {
|
||||
@@ -37,17 +39,33 @@ export default function AppLayout() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
const dispatch = useAppDispatch();
|
||||
const getMenu = () => {
|
||||
getMenuList().then(res => {
|
||||
if (res.code == 200) {
|
||||
message.success("获取菜单成功")
|
||||
} else {
|
||||
message.error("获取菜单失败:" + res.msg)
|
||||
}
|
||||
console.log("菜单列表:", res);
|
||||
//if (res.code == 200) {
|
||||
// setMenuList(res.data)
|
||||
//} else {
|
||||
// //message.error("获取菜单失败:"+res.msg)
|
||||
//}
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000);
|
||||
getMenu();
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem('isAuthenticated');
|
||||
localStorage.removeItem('user');
|
||||
localStorage.removeItem('token');
|
||||
navigate('/login');
|
||||
const handleLogout = async () => {
|
||||
await dispatch(logout());
|
||||
navigate('/login', { replace: true });
|
||||
|
||||
};
|
||||
|
||||
const menuItems = [
|
||||
@@ -59,9 +77,16 @@ export default function AppLayout() {
|
||||
{ key: '/users', icon: <TeamOutlined />, label: '用户管理', roles: ['admin'] },
|
||||
{ key: '/roles', icon: <UserOutlined />, label: '角色权限', roles: ['admin'] },
|
||||
{ key: '/serialNumGenerate', icon: <UserOutlined />, label: '序列号生成', roles: ['admin'] },
|
||||
{
|
||||
key: '/menuList',
|
||||
icon: <MenuOutlined />,
|
||||
label: '菜单管理',
|
||||
roles: ['admin']
|
||||
}
|
||||
];
|
||||
|
||||
const filteredMenu = menuItems.filter(item => item.roles.includes(userInfo.role));
|
||||
const filteredMenu = menuItems
|
||||
//.filter(item => item.roles.includes(userInfo?.role));
|
||||
|
||||
const currentPathLabel = menuItems.find(i => i.key === location.pathname)?.label || '概览控制台';
|
||||
|
||||
@@ -124,7 +149,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">{userInfo.username}</span>
|
||||
<span className="text-gray-800 font-medium">{userInfo?.username}</span>
|
||||
</div>
|
||||
<Button
|
||||
type="text"
|
||||
|
||||
Reference in New Issue
Block a user