浏览代码

优化退出

sujunling 1 年之前
父节点
当前提交
b2a739f49c
共有 7 个文件被更改,包括 39 次插入7 次删除
  1. 3 0
      .env.development
  2. 17 0
      src/api/sys/user.ts
  3. 3 1
      src/hooks/setting/index.ts
  4. 4 4
      src/router/guard/permissionGuard.ts
  5. 9 2
      src/store/modules/user.ts
  6. 2 0
      src/utils/env.ts
  7. 1 0
      types/config.d.ts

+ 3 - 0
.env.development

@@ -44,6 +44,9 @@ VITE_GLOB_WEB_SOCKET = ws://192.168.2.225/api/ws/plugins/telemetry?token=
 
 # Delete console
 VITE_GLOB_DROP_CONSOLE = true
+#理工api
+VITE_GLOB_IS_IDC="https://iam.yced.com.cn/idp/profile/OAUTH2/Redirect/GLO?redirctToUrl=https://swqx.yced.com.cn:20043&redirectToLogin=true&entityId=swqx"
+
 
 # Basic interface address SPA
 # VITE_GLOB_API_URL= /api

+ 17 - 0
src/api/sys/user.ts

@@ -9,6 +9,7 @@ import {
 } from './model/userModel';
 
 import type { ErrorMessageMode } from '/#/axios';
+import { getAppEnvConfig } from '/@/utils/env';
 
 enum Api {
   Login = '/auth/login',
@@ -124,3 +125,19 @@ export const getUserToken = (id: string) => {
     url: `/third/login/id/${id}`,
   });
 };
+
+export async function LoginOut() {
+  return new Promise(function (resolve, reject) {
+    const { VITE_GLOB_IS_IDC } = getAppEnvConfig();
+    if (VITE_GLOB_IS_IDC && VITE_GLOB_IS_IDC.length) {
+      var iframe = document.createElement('iframe');
+      iframe.src = VITE_GLOB_IS_IDC;
+      iframe.style.display = 'none';
+      iframe.style.position = 'fixed';
+      iframe.style.zIndex = '-9';
+      document.body.appendChild(iframe);
+      setTimeout(() => window.location.href = VITE_GLOB_IS_IDC, 3000);
+      resolve(true)
+    }
+  })
+}

+ 3 - 1
src/hooks/setting/index.ts

@@ -27,6 +27,7 @@ export const useGlobSetting = (): Readonly<GlobConfig> => {
     VITE_GLOB_DEBUGGER_API,
     VITE_GLOB_LIGONG_PAGE,
     VITE_GLOB_BASE_IMG,
+    VITE_GLOB_IS_IDC,
     VITE_GLOB_BASE_IMITATE
   } = getAppEnvConfig();
 
@@ -55,7 +56,8 @@ export const useGlobSetting = (): Readonly<GlobConfig> => {
     alarmNotifyDuration: VITE_GLOB_ALARM_NOTIFY_DURATION,
     alarmPollingInterval: VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME,
     baseImgUrl: VITE_GLOB_BASE_IMG,
-    baseImitate:VITE_GLOB_BASE_IMITATE
+    baseImitate:VITE_GLOB_BASE_IMITATE,
+    isIdc: VITE_GLOB_IS_IDC,
   };
   return glob as Readonly<GlobConfig>;
 };

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

@@ -17,10 +17,10 @@ export async function createPermissionGuard(router: Router) {
   const userStore = useUserStoreWithOut();
   const userStore2 = useUserStore();
   const permissionStore = usePermissionStoreWithOut();
-  if (location.href.indexOf('response_type') > -1) {
-    let response_type = location.href.split('response_type=')
-    console.log('有response_type后', response_type[1]);
-    const userInfo = await userStore2.kidlogin({ code: response_type[1] })
+  if (location.href.indexOf('code') > -1) {
+    let code = location.href.split('code=')
+    console.log('有response_type后', code[1]);
+    const userInfo = await userStore2.kidlogin({ code: code[1] })
     console.log('传参成功', userInfo);
   }
   router.beforeEach(async (to, from, next) => {

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

@@ -14,7 +14,7 @@ import {
   RefreshTokenParams,
   SmsLoginParams,
 } from '/@/api/sys/model/userModel';
-import { doRefreshToken, getMyInfo, loginApi, smsCodeLoginApi, kidloginApi } from '/@/api/sys/user';
+import { doRefreshToken, getMyInfo, loginApi, smsCodeLoginApi, kidloginApi, LoginOut } from '/@/api/sys/user';
 import { gisLoginApi } from '/@/api/sys/gis';
 import { useI18n } from '/@/hooks/web/useI18n';
 import { useMessage } from '/@/hooks/web/useMessage';
@@ -257,7 +257,7 @@ export const useUserStore = defineStore({
           // window.localStorage.setItem('entityId', JSON.stringify(entityId));
           // window.sessionStorage.setItem('entityId', JSON.stringify(entityId));
         }
-      } catch {}
+      } catch { }
       return userInfo;
     },
     /**
@@ -275,6 +275,13 @@ export const useUserStore = defineStore({
       // this.setSessionTimeout(false);
       // // goLogin && router.push(PageEnum.BASE_LOGIN);
 
+      const { VITE_GLOB_IS_IDC } = getAppEnvConfig();
+      if (VITE_GLOB_IS_IDC && VITE_GLOB_IS_IDC.length) {
+        await LoginOut()
+      }
+
+
+
       this.setToken(undefined);
       this.setSessionTimeout(false);
       setAuthCache(REFRESH_TOKEN_KEY, undefined);

+ 2 - 0
src/utils/env.ts

@@ -44,6 +44,7 @@ export function getAppEnvConfig() {
     VITE_GLOB_DEBUGGER_API,
     VITE_GLOB_BASE_IMG,
     VITE_GLOB_BASE_IMITATE,
+    VITE_GLOB_IS_IDC,
   } = ENV;
 
   if (!/^[a-zA-Z\_]*$/.test(VITE_GLOB_APP_SHORT_NAME)) {
@@ -71,6 +72,7 @@ export function getAppEnvConfig() {
     VITE_GLOB_DEBUGGER_API,
     VITE_GLOB_BASE_IMG,
     VITE_GLOB_BASE_IMITATE,
+    VITE_GLOB_IS_IDC,
   };
 }
 

+ 1 - 0
types/config.d.ts

@@ -199,4 +199,5 @@ export interface GlobEnvConfig {
   VITE_GLOB_BASE_IMG: string;
   //模拟地址
   VITE_GLOB_BASE_IMITATE: string;
+  VITE_GLOB_IS_IDC: string;
 }