feat(auth): 添加登录功能和路由保护

- 在侧边栏添加退出登录按钮并实现登出逻辑
- 添加 ProtectedRoute 组件用于路由权限控制
- 创建 LoginPage 组件实现登录界面和逻辑
- 集成本地登录验证到 authSlice 状态管理
- 配置路由表添加登录页面和保护路由
- 实现自动跳转到登录页面的重定向逻辑
This commit is contained in:
2026-02-01 14:11:44 +08:00
parent 906bb39b83
commit 7043a26ab3
5 changed files with 380 additions and 210 deletions

View File

@@ -4,6 +4,7 @@ import {
CloseOutlined,
MenuOutlined,
SettingOutlined,
LogoutOutlined,
} from "@ant-design/icons";
import { ClipboardList, X } from "lucide-react";
import { menuItems } from "@/pages/Layout/menu";
@@ -12,6 +13,7 @@ import TaskUpload from "./TaskUpload";
import SettingsPage from "../SettingsPage/SettingsPage";
import { useAppSelector, useAppDispatch } from "@/store/hooks";
import { showSettings, hideSettings } from "@/store/slices/settingsSlice";
import { logout } from "@/store/slices/authSlice";
const isPathMatch = (currentPath: string, targetPath: string) =>
currentPath === targetPath || currentPath.startsWith(`${targetPath}/`);
@@ -67,6 +69,11 @@ const AsiderAndHeaderLayout = () => {
};
}, []);
const handleLogout = () => {
dispatch(logout());
navigate("/login");
};
return (
<div
className={`${
@@ -148,6 +155,9 @@ const AsiderAndHeaderLayout = () => {
>
</Button>
<Button block danger onClick={handleLogout}>
退
</Button>
</div>
) : (
<div className="space-y-2">
@@ -175,6 +185,7 @@ const AsiderAndHeaderLayout = () => {
>
<SettingOutlined />
</Button>
<Button block danger onClick={handleLogout} icon={<LogoutOutlined />} />
</div>
)}
</div>