feat: 1. 添加axios全局路由拦截进行自动添加请求jwt。 2.重新整理路由表。 3. 文档列表新增版本差异对比。 4.菜单路由可访问列表通过对接接口返回,添加全局路由检测。

5. 修改统一认证登录和管理员登录是通过接口形式进行,存储返回的accessToken。    6. 修改交叉评查的部分样式
This commit is contained in:
2025-11-18 11:06:24 +08:00
parent 8a50671c39
commit bfe39e45a9
53 changed files with 9503 additions and 2796 deletions
+57
View File
@@ -0,0 +1,57 @@
/**
* 客户端认证守卫组件
*
* 在客户端检查 localStorage 中的 token
* 如果未认证且访问的是需要认证的路径,则跳转到登录页
*/
import { useEffect } from 'react';
import { useNavigate, useLocation } from '@remix-run/react';
import { isAuthenticated } from '~/utils/auth-storage';
interface ClientAuthGuardProps {
isPublicPath: boolean;
}
export function ClientAuthGuard({ isPublicPath }: ClientAuthGuardProps) {
const navigate = useNavigate();
const location = useLocation();
useEffect(() => {
console.log('🔍 [Auth Guard] useEffect 触发', {
isPublicPath,
pathname: location.pathname
});
// 如果是公共路径,不需要检查认证
if (isPublicPath) {
console.log('✅ [Auth Guard] 公共路径,跳过认证检查');
return;
}
// 检查客户端是否已认证(localStorage 中有 token
const token = localStorage.getItem('access_token');
const authenticated = isAuthenticated();
console.log('🔍 [Auth Guard] 认证检查', {
token: token ? `${token.substring(0, 20)}...` : null,
authenticated,
pathname: location.pathname
});
if (!authenticated) {
console.log('🔒 [Auth Guard] 未认证,重定向到登录页');
// 保存当前路径,登录后可以跳转回来
const redirectTo = location.pathname !== '/login' ? location.pathname : '/';
// 跳转到登录页,并传递重定向目标
navigate(`/login?redirect=${encodeURIComponent(redirectTo)}`, { replace: true });
} else {
console.log('✅ [Auth Guard] 已认证,允许访问');
}
}, [isPublicPath, navigate, location.pathname]);
// 这个组件不渲染任何内容
return null;
}