Browse Source

Merge remote-tracking branch 'origin/master'

yzx 2 months ago
parent
commit
504f32f40a
2 changed files with 35 additions and 30 deletions
  1. 18 18
      src/router/modules/remaining.ts
  2. 17 12
      src/views/Login/components/LoginForm.vue

+ 18 - 18
src/router/modules/remaining.ts

@@ -36,11 +36,11 @@ const { t } = useI18n()
  canTo: true               设置为true即使hidden为true,也依然可以进行路由跳转(默认 false)
  }
  **/
- async function getUserType() {
-  const userType = await LoginApi.getInfo(); // 假设你有 LoginApi.getInfo() 方法获取用户信息
-  console.log(userType,'getUserType');
-  return userType.roles; // 假设返回的角色是一个数组
-}
+//  async function getUserType() {
+//   const userType = await LoginApi.getInfo(); // 假设你有 LoginApi.getInfo() 方法获取用户信息
+//   console.log(userType,'getUserType');
+//   return userType.roles; // 假设返回的角色是一个数组
+// }
 const remainingRouter: AppRouteRecordRaw[] = [
   {
     path: '/system',
@@ -124,7 +124,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
     }
   },
   // {
-  //   path: '/Home',
+  //   path: '/system/Home',
   //   component: Layout,
   //   name: 'SystemHome',
   //   meta: {
@@ -139,7 +139,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
   //   children: [
   //     {
   //       path: 'index',
-  //       component: () => import('@/views/Home/Index.vue'),
+  //       component: () => import('@/views/system/Home/Index.vue'),
   //       name: 'Index',
   //       meta: {
   //         title: t('router.home'),
@@ -718,17 +718,17 @@ const remainingRouter: AppRouteRecordRaw[] = [
   }
 ];
 
-(async () => {
-  const userRoles = await getUserType();
+// (async () => {
+//   const userRoles = await getUserType();
   
-  // 判断用户是否具有 "student" 角色
-  if (userRoles.includes("student")) {
-    // 如果用户不属于 "student",则从路由中移除 /system/Home 路由
-    const systemHomeIndex = remainingRouter.findIndex(route => route.path === '/system/Home');
-    if (systemHomeIndex !== -1) {
-      remainingRouter.splice(systemHomeIndex, 1); // 移除该路由
-    }
-  }
-})();
+//   // 判断用户是否具有 "student" 角色
+//   if (userRoles.includes("student")) {
+//     // 如果用户不属于 "student",则从路由中移除 /system/Home 路由
+//     const systemHomeIndex = remainingRouter.findIndex(route => route.path === '/system/Home');
+//     if (systemHomeIndex !== -1) {
+//       remainingRouter.splice(systemHomeIndex, 1); // 移除该路由
+//     }
+//   }
+// })();
 
 export default remainingRouter;

+ 17 - 12
src/views/Login/components/LoginForm.vue

@@ -264,18 +264,23 @@ const handleLogin = async (params) => {
       authUtil.removeLoginForm()
     }
     authUtil.setToken(res)
-    const userType = await LoginApi.getInfo()
-    console.log(userType,"我在这里")
-    if(userType.roles.indexOf("student") !== -1){
-        console.log("我是学生")
-        window.location.href = '/system/studentSelf/index'
-    }else{
-        console.log("我不是学生")
-        if (!redirect.value) {
-          redirect.value = '/'
-        }
-       window.location.href = '/system/Home/index'
-        // push({ path: redirect.value || permissionStore.addRouters[0].path })
+    try {
+      const userType = await LoginApi.getInfo();
+      console.log(userType,"我在这里");
+      console.log(userType);  // 查看 userType 的结构  
+      if (userType && Array.isArray(userType.roles)) {
+          if (userType.roles.indexOf("student") !== -1) {
+              console.log("我是学生");
+              window.location.href = '/system/studentSelf/index';
+          } else {
+              console.log("我不是学生");
+              window.location.href = '/system/Home/index';
+          }
+      } else {
+          console.error("userType 或 roles 格式错误");
+      }
+    } catch (error) {
+      console.error("获取用户信息时发生错误:", error);
     }
   } finally {
     loginLoading.value = false