Forráskód Böngészése

[Feat 0000] 自动登录解决登陆后重定向不正确的问题

houzekong 8 hónapja
szülő
commit
ee05d50aa5
2 módosított fájl, 16 hozzáadás és 9 törlés
  1. 7 6
      src/router/guard/permissionGuard.ts
  2. 9 3
      src/store/modules/user.ts

+ 7 - 6
src/router/guard/permissionGuard.ts

@@ -109,9 +109,13 @@ export function createPermissionGuard(router: Router) {
       // query中要求自动登录的执行登录逻辑
       if (to.query[AUTO_LOGIN_URL_QUERY.key] === AUTO_LOGIN_URL_QUERY.val) {
         const userStore = useUserStoreWithOut();
-        await userStore.autoLogin();
-        next(to.path);
-        return;
+        await userStore.autoLogin({
+          goHome: false,
+        });
+        return next({
+          path: to.path,
+          query: to.query,
+        });
       }
 
       //update-begin---author:wangshuai ---date:20220629  for:[issues/I5BG1I]vue3 Auth2未实现------------
@@ -156,9 +160,6 @@ export function createPermissionGuard(router: Router) {
 
       //update-begin---author:scott ---date:2023-04-24  for:【QQYUN-4713】登录代码调整逻辑有问题,改造待观察--
       if (to.fullPath) {
-        console.log('to.fullPath 1', to.fullPath);
-        console.log('to.path 2', to.path);
-
         const getFullPath = to.fullPath;
         if (
           getFullPath == '/' ||

+ 9 - 3
src/store/modules/user.ts

@@ -160,8 +160,8 @@ export const useUserStore = defineStore({
         // save token
         this.setToken(token);
         this.setTenant(userInfo.loginTenantId);
+        // 将用户的用户名与密码存于数据库之中,这是为了实现前端单点登录模拟
         this.setPassword(params.password);
-        // 将用户的用户名与密码存于数据库之中,这是为了
         return this.afterLoginAction(goHome, data);
       } catch (error) {
         return Promise.reject(error);
@@ -376,14 +376,20 @@ export const useUserStore = defineStore({
         },
       });
     },
-    async autoLogin() {
+    async autoLogin(
+      params: Partial<LoginParams> & {
+        goHome?: boolean;
+        mode?: ErrorMessageMode;
+      } = {}
+    ) {
       try {
         const loginParams = {
           username: 'autoAdmin',
           password: 'autoAdmin123',
           checkKey: new Date().getTime(),
+          ...params,
         };
-        this.login(loginParams);
+        return this.login(loginParams);
       } catch (error) {
         return Promise.reject(error);
       }