Преглед изворни кода

[Fix 0000] 跳过单点登录的相关问题修复

houzekong пре 8 месеци
родитељ
комит
4088f45974
2 измењених фајлова са 10 додато и 3 уклоњено
  1. 7 1
      src/hooks/web/useSso.ts
  2. 3 2
      src/router/guard/permissionGuard.ts

+ 7 - 1
src/hooks/web/useSso.ts

@@ -9,9 +9,10 @@ const openSso = globSetting.openSso;
 export function useSso() {
   const locationUrl = 'http://' + window.location.host + '/';
   /**
-   * 单点登录
+   * 单点登录,返回是否需要跳转到单点登录页
    */
   async function ssoLogin() {
+    let redirect = false;
     if (openSso == 'true') {
       const token = getToken();
       const ticket = getUrlParam('ticket');
@@ -22,21 +23,26 @@ export function useSso() {
             service: locationUrl,
           })
             .then((res) => {
+              redirect = false;
               const userStore = useUserStore();
               userStore.setToken(res.token);
               return userStore.afterLoginAction(true, {});
             })
             .catch(() => {
+              redirect = true;
               window.location.href = globSetting.casBaseUrl + '/login?service=' + encodeURIComponent(locationUrl);
             });
         } else {
           if (window.location.search == '?type=noCas') {
+            redirect = false;
           } else {
             window.location.href = globSetting.casBaseUrl + '/login?service=' + encodeURIComponent(locationUrl);
+            redirect = true;
           }
         }
       }
     }
+    return redirect;
   }
 
   /**

+ 3 - 2
src/router/guard/permissionGuard.ts

@@ -110,8 +110,9 @@ export function createPermissionGuard(router: Router) {
       }
       // query如果没有明确要求跳过sso则执行sso登录
       if (to.query[SKIP_SSO_URL_QUERY.key] !== SKIP_SSO_URL_QUERY.val) {
-        await useSso().ssoLogin();
-        return;
+        const redirectSso = await useSso().ssoLogin();
+        // 如果需要重定向到sso页面则取消路由导航
+        if (redirectSso) return;
       }
       // query中要求自动登录的执行自动登录
       if (to.query[AUTO_LOGIN_URL_QUERY.key] === AUTO_LOGIN_URL_QUERY.val) {