training_data/apps/web/src/app/main/layout/NavigationMenu.tsx

40 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-02-25 22:04:17 +08:00
import { Menu } from "antd";
2025-03-12 09:48:35 +08:00
import { useNavigate, useLocation } from "react-router-dom";
2025-02-06 16:32:31 +08:00
2025-03-12 08:23:33 +08:00
export default function NavigationMenu() {
const navigate = useNavigate();
2025-03-12 09:48:35 +08:00
const location = useLocation();
console.log(location.pathname);
2025-03-12 08:23:33 +08:00
// 导航菜单项配置
const menuItems = [
2025-03-12 19:38:39 +08:00
{ key: 'staff', label: '人员总览', path: '/' }, // 将path改为根路径
2025-03-12 16:34:43 +08:00
{ key: 'plan', label: '培训计划', path: '/plan' },
{ key: 'day', label: '每日填报', path: '/daily' },
{ key: 'exam', label: '考核成绩', path: '/exam' },
2025-03-12 08:23:33 +08:00
];
2025-03-12 19:38:39 +08:00
2025-03-12 08:23:33 +08:00
return (
<>
<Menu
theme="dark"
mode="inline"
className="!bg-transparent !border-0 pt-4 [&_.ant-menu-item]:!mt-2"
2025-03-12 19:38:39 +08:00
selectedKeys={[ // 改用selectedKeys替代defaultSelectedKeys
menuItems.find((item) => location.pathname.startsWith(item.path))?.key,
2025-03-12 09:48:35 +08:00
]}
2025-03-12 08:23:33 +08:00
>
{menuItems.map((item) => (
<Menu.Item
key={item.key}
className="!h-14 !flex !items-center !text-gray-300 hover:!text-white group !rounded-lg mx-4"
onClick={() => navigate(item.path)}
>
<div className="flex items-center justify-center w-full px-4 transition-all duration-300 h-full rounded-lg">
<span className="text-xl font-medium">{item.label}</span>
</div>
</Menu.Item>
))}
</Menu>
</>
);
}