张涛 пре 1 година
родитељ
комит
85166051c4
1 измењених фајлова са 12 додато и 8 уклоњено
  1. 12 8
      src/router/guard.js

+ 12 - 8
src/router/guard.js

@@ -7,32 +7,36 @@ const whiteList = ['/login', '/reg', '/noPer'];
 
 // 导入所需的模块
 router.beforeEach((to, from, next) => {
-  const isAuthorized = kuky_Authorization.get();
-  const isLoginPage = to.path === '/login';
-  const firstLogin = from.path === '/login';
-  const isInWhiteList = whiteList.includes(to.path);
+  const isAuthorized = kuky_Authorization.get(); // 获取用户授权状态
+  const isLoginPage = to.path === '/login'; // 判断目标路径是否为登录页
+  const firstLogin = from.path === '/login'; // 判断当前路径是否为登录页
+  const isInWhiteList = whiteList.includes(to.path); // 检查目标路径是否在白名单中
   const hasAccess = accessFlatRoutes.some((route) => {
+    // 检查用户是否有权访问目标路径
     return route.path == to.path;
   });
 
   // 用户已授权的情况
   if (isAuthorized) {
     if (isLoginPage || firstLogin) {
+      // 如果目标页面为登录页或当前为登录页
       if (to.path !== firstPage) {
-        next({ path: firstPage }); // 如果要进入登录页,且不是首页,则重定向到首页
+        // 如果目标路径不是首页
+        next({ path: firstPage }); // 重定向到首页
       } else {
         next(); // 如果已经是首页,则正常访问
       }
     } else if (!hasAccess && !isInWhiteList) {
-      // 无权限访问且不在白名单中,重定向到无权限页面
-      next({ path: '/noPer' });
+      // 如果用户访问权限且不在白名单中
+      next({ path: '/noPer' }); // 重定向到无权限页面
     } else {
       next(); // 其他情况,正常访问
     }
   } else {
     // 用户未授权的情况
     if (isInWhiteList) {
-      next(); // 在免登录白名单中,允许进入
+      // 如果目标路径在免登录白名单中
+      next(); // 允许进入
     } else {
       next('/login'); // 否则重定向到登录页面
     }