Jelajahi Sumber

[Fix 0000] 修复看板跳转后无法正确重定向的问题

houzekong 8 bulan lalu
induk
melakukan
3f5cc3bae9

+ 10 - 7
src/hooks/vent/useAutoLogin.ts

@@ -4,6 +4,7 @@ import QueryString from 'qs';
 import { useUserStore } from '/@/store/modules/user';
 import { RouteLocationNormalized } from 'vue-router';
 import { useMessage } from '../web/useMessage';
+import { AUTO_LOGIN_URL_QUERY } from '/@/router/constant';
 
 /** 自动登录功能的Hook,该Hook是为了部署在同一局域网内的多套系统之间能够无缝切换 */
 export function useAutoLogin() {
@@ -11,7 +12,7 @@ export function useAutoLogin() {
   function open(url: string, redirect?: string, target?: string) {
     const userStore = useUserStore();
     const qs = QueryString.stringify({
-      autoLogin: true,
+      [AUTO_LOGIN_URL_QUERY.key]: AUTO_LOGIN_URL_QUERY.val,
       username: userStore.getUserInfo.username,
       workNo: userStore.getUserInfo.workNo,
       redirect,
@@ -19,12 +20,13 @@ export function useAutoLogin() {
     window.open(`${url}?${qs}`, target);
   }
 
-  /** 用在路由守卫里,执行自动登录的逻辑,如果存在符合自动登录标准的query则执行自动登录 */
-  async function doAutoLogin(route: RouteLocationNormalized) {
+  /** 用在路由守卫里,执行自动登录的逻辑,如果存在符合自动登录标准的query则执行自动登录,返回是否需要重定向 */
+  async function doAutoLogin(route: RouteLocationNormalized): Promise<boolean> {
     const userStore = useUserStore();
-    if (!route.query) return;
-    const { autoLogin, username, workNo } = route.query;
-    if (!autoLogin || !username || !workNo) return;
+    if (!route.query) return false;
+    if (route.query[AUTO_LOGIN_URL_QUERY.key] !== AUTO_LOGIN_URL_QUERY.val) return false;
+    const { username, workNo } = route.query;
+    if (!username || !workNo) return false;
     const params = {
       username: username as string,
       workNo: workNo as string,
@@ -32,10 +34,11 @@ export function useAutoLogin() {
     };
     try {
       await userStore.autoLogin(params);
+      return true;
     } catch (e: any) {
       const message = useMessage().createMessage;
       message.error(e.message);
-      return;
+      return false;
     }
   }
 

+ 2 - 0
src/router/constant.ts

@@ -10,6 +10,8 @@ export const QIANKUN_ROUTE_OUTER_NAME = 'MicroAppOuter';
 
 export const AUTO_LOGIN_URL_QUERY = { key: 'auto-login', val: '1' };
 
+export const MOCK_LOGIN_URL_QUERY = { key: 'mock-login', val: '1' };
+
 export const SKIP_SSO_URL_QUERY = { key: 'skipsso', val: '1' };
 
 // 暂时修改

+ 8 - 4
src/router/guard/permissionGuard.ts

@@ -15,7 +15,7 @@ import { OAUTH2_THIRD_LOGIN_TENANT_ID } from '/@/enums/cacheEnum';
 import { useGlobSetting } from '/@/hooks/setting';
 
 import _ from 'lodash';
-import { AUTO_LOGIN_URL_QUERY, SKIP_SSO_URL_QUERY } from '../constant';
+import { AUTO_LOGIN_URL_QUERY, MOCK_LOGIN_URL_QUERY, SKIP_SSO_URL_QUERY } from '../constant';
 import { useSso } from '/@/hooks/web/useSso';
 import { useAutoLogin } from '/@/hooks/vent/useAutoLogin';
 
@@ -41,7 +41,6 @@ const glob = useGlobSetting();
 export function createPermissionGuard(router: Router) {
   const userStore = useUserStoreWithOut();
   const permissionStore = usePermissionStoreWithOut();
-  const { doAutoLogin } = useAutoLogin();
 
   router.beforeEach(async (to, from, next) => {
     RootRoute.redirect = glob.homePath || PageEnum.BASE_HOME;
@@ -60,8 +59,13 @@ export function createPermissionGuard(router: Router) {
       document.title = '首页';
       return;
     }
+
     // 如果符合自动登录的相关条件则直接执行自动登录,覆盖原有的登录信息
-    await doAutoLogin(to);
+    const { doAutoLogin } = useAutoLogin();
+    const redirect = await doAutoLogin(to);
+    if (redirect && to.query.redirect) {
+      next(to.query.redirect as string);
+    }
 
     const token = userStore.getToken;
 
@@ -119,7 +123,7 @@ export function createPermissionGuard(router: Router) {
         if (redirectSso) return;
       }
       // query中要求自动登录的执行自动登录
-      if (to.query[AUTO_LOGIN_URL_QUERY.key] === AUTO_LOGIN_URL_QUERY.val) {
+      if (to.query[MOCK_LOGIN_URL_QUERY.key] === MOCK_LOGIN_URL_QUERY.val) {
         const userStore = useUserStoreWithOut();
         await userStore.mockLogin({
           goHome: false,

+ 2 - 2
src/views/vent/performance/comment/CADModal.vue

@@ -35,7 +35,7 @@
   import { onMounted } from 'vue';
   import CADViewer from '/@/views/vent/performance/fileDetail/commen/CADViewer.vue';
   import { useGlobSetting } from '/@/hooks/setting';
-  import { AUTO_LOGIN_URL_QUERY, SKIP_SSO_URL_QUERY } from '/@/router/constant';
+  import { MOCK_LOGIN_URL_QUERY, SKIP_SSO_URL_QUERY } from '/@/router/constant';
 
   const { sysOrgCode } = useGlobSetting();
   // 不是布尔台的使用 mxcad 模式,是布尔台的使用 iframe 模式以避免“法律风险”
@@ -60,7 +60,7 @@
       // 当以 iframe 模式运行时,origin 在生产模式下需要指向本项目公司端所部署的地址
       const origin = import.meta.env.PROD ? 'http://10.248.235.101:8092' : window.location.origin;
       // const origin = import.meta.env.DEV ? 'http://182.92.126.35:8092' : window.location.origin;
-      iframesrc.value = `${origin}/fileManager/cad-viewer?${SKIP_SSO_URL_QUERY.key}=${SKIP_SSO_URL_QUERY.val}&${AUTO_LOGIN_URL_QUERY.key}=${AUTO_LOGIN_URL_QUERY.val}&id=${record.id}&filename=${record.fileName}`;
+      iframesrc.value = `${origin}/fileManager/cad-viewer?${SKIP_SSO_URL_QUERY.key}=${SKIP_SSO_URL_QUERY.val}&${MOCK_LOGIN_URL_QUERY.key}=${MOCK_LOGIN_URL_QUERY.val}&id=${record.id}&filename=${record.fileName}`;
     }
   });