fix: 1. 系统设置入口进来只会跳转到拥有权限访问的页面。
2. 优化登录样式
This commit is contained in:
+28
-5
@@ -52,23 +52,36 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
// 🔑 检查用户是否有系统设置权限
|
||||
let hasSettingsAccess = false;
|
||||
let hasCrossCheckingAccess = false;
|
||||
let settingsChildren: { path: string; title: string }[] = [];
|
||||
|
||||
if (userRole && frontendJWT) {
|
||||
const { getUserRoutesByRole } = await import('~/api/auth/user-routes');
|
||||
const routesResult = await getUserRoutesByRole(userRole, frontendJWT, true); // includeHidden=true
|
||||
|
||||
if (routesResult.success && routesResult.data) {
|
||||
// 检查是否存在顶级路由 '/settings'
|
||||
hasSettingsAccess = routesResult.data.some(route => route.path === '/settings');
|
||||
// 查找 '/settings' 路由及其子路由
|
||||
const settingsRoute = routesResult.data.find(route => route.path === '/settings');
|
||||
if (settingsRoute) {
|
||||
hasSettingsAccess = true;
|
||||
// 提取子路由信息(仅 path 和 title)
|
||||
if (settingsRoute.children && settingsRoute.children.length > 0) {
|
||||
settingsChildren = settingsRoute.children.map(child => ({
|
||||
path: child.path,
|
||||
title: child.title
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否存在顶级路由 '/cross-checking'
|
||||
hasCrossCheckingAccess = routesResult.data.some(route => route.path === '/cross-checking');
|
||||
// console.log(`🔑 [Index Loader] 用户${hasSettingsAccess ? '有' : '没有'}系统设置权限`);
|
||||
// console.log(`🔑 [Index Loader] 系统设置子路由数量: ${settingsChildren.length}`);
|
||||
// console.log(`🔑 [Index Loader] 用户${hasCrossCheckingAccess ? '有' : '没有'}交叉评查权限`);
|
||||
}
|
||||
}
|
||||
|
||||
// 返回用户信息、入口模块和权限给客户端
|
||||
return Response.json({ userRole, userInfo, entryModules, hasSettingsAccess, hasCrossCheckingAccess });
|
||||
return Response.json({ userRole, userInfo, entryModules, hasSettingsAccess, hasCrossCheckingAccess, settingsChildren });
|
||||
}
|
||||
|
||||
export default function Index() {
|
||||
@@ -238,6 +251,14 @@ export default function Index() {
|
||||
|
||||
// 处理进入系统设置
|
||||
const handleEnterSettings = () => {
|
||||
// 🔑 检查是否有系统设置的子路由
|
||||
if (!loaderData.settingsChildren || loaderData.settingsChildren.length === 0) {
|
||||
// 没有子路由,显示错误提示
|
||||
toastService.error('您无权限访问或页面丢失');
|
||||
console.warn('⚠️ [Index] 系统设置没有可访问的子路由');
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
// 🔑 设置标志:表示用户通过系统设置入口进入
|
||||
sessionStorage.setItem('settingsMode', 'true');
|
||||
@@ -249,8 +270,10 @@ export default function Index() {
|
||||
sessionStorage.removeItem('crossCheckingMode');
|
||||
}
|
||||
|
||||
// 跳转到系统设置的默认页面
|
||||
navigate('/rule-groups');
|
||||
// 跳转到第一个子路由
|
||||
const firstChildPath = loaderData.settingsChildren[0].path;
|
||||
console.log(`📌 [Index] 系统设置:跳转到第一个子路由 ${firstChildPath}`);
|
||||
navigate(firstChildPath);
|
||||
};
|
||||
|
||||
// 处理进入交叉评查
|
||||
|
||||
Reference in New Issue
Block a user