Prechádzať zdrojové kódy

Merge branch 'master' of http://192.168.2.21:11666/chenlong/xx_sw_dp

chenlong 1 rok pred
rodič
commit
05b800abcc

+ 3 - 0
.env.development

@@ -50,6 +50,9 @@ VITE_GLOB_DROP_CONSOLE = true
 VITE_GLOB_API_URL="/api"
 #理工api
 VITE_GLOB_LIGONG_API="/ligongApi"
+#理工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"
+
 #调试
 VITE_GLOB_DEBUGGER_API="/debuggerApi"
 

+ 2 - 1
index.html

@@ -16,7 +16,8 @@
     <script src="./static/MicroFrontend.js"></script>
     <script src="./static/mapConfig.js"></script>
     <!-- <script src="./static/grant.js"></script> -->
-    <script src="http://106.12.170.138:4001/build/grant.js"></script>
+    <script src="/build/grant.js"></script>
+    <!-- <script src="http://106.12.170.138:4001/build/grant.js"></script> -->
     <link rel="stylesheet" href="./public/static/jessibuca/iconfont/iconfont.css" />
     <style>
       .leaflet-popup-tip-container {

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

@@ -2,6 +2,7 @@ import { defHttp } from '/@/utils/http/axios';
 import { LoginParams, LoginResultModel, GetUserInfoModel, UserInfoModel, RefreshTokenParams, SmsLoginParams } from './model/userModel';
 
 import type { ErrorMessageMode } from '/#/axios';
+import { getAppEnvConfig } from '/@/utils/env';
 
 enum Api {
   Login = '/auth/login',
@@ -118,3 +119,23 @@ 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 logout = "https://iam.yced.com.cn/idp/profile/OAUTH2/Redirect/GLO?redirctToUrl=https://swqx.yced.com.cn:20043&redirectToLogin=true&entityId=swqx";
+      var iframe = document.createElement('iframe');
+      iframe.src = logout;
+      iframe.style.display = 'none';
+      iframe.style.position = 'fixed';
+      iframe.style.zIndex = '-9';
+      document.body.appendChild(iframe);
+      setTimeout(() => {
+        window.location.href = VITE_GLOB_IS_IDC;
+        resolve(true)
+      }, 3000);
+    }
+  })
+}

+ 2 - 0
src/hooks/setting/index.ts

@@ -27,6 +27,7 @@ export const useGlobSetting = (): Readonly<GlobConfig> => {
     VITE_GLOB_DEBUGGER_API,
     VITE_GLOB_ADMIN_LOGIN,
     VITE_GLOB_BASE_IMG,
+    VITE_GLOB_IS_IDC,
   } = getAppEnvConfig();
 
   if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) {
@@ -52,6 +53,7 @@ export const useGlobSetting = (): Readonly<GlobConfig> => {
     alarmNotifyDuration: VITE_GLOB_ALARM_NOTIFY_DURATION,
     alarmPollingInterval: VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME,
     baseImgUrl: VITE_GLOB_BASE_IMG,
+    isIdc: VITE_GLOB_IS_IDC,
   };
   return glob as Readonly<GlobConfig>;
 };

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

@@ -61,6 +61,9 @@ export async function createPermissionGuard(router: Router) {
 
 
   router.beforeEach(async (to, from, next) => {
+    console.log('to', to);
+    console.log('from', from);
+    debugger
     // console.log('Refresh token', sessionStorage.getItem('refreshToken'));
     // console.log('token', sessionStorage.getItem('refreshToken'));
     let userInfo = await getAuthCache(USER_INFO_KEY);
@@ -118,8 +121,11 @@ export async function createPermissionGuard(router: Router) {
         };
       }
       if (redirectData.path == '/login') {
-        const { VITE_GLOB_ADMIN_LOGIN } = getAppEnvConfig();
-        if (deveProType) {
+        const { VITE_GLOB_ADMIN_LOGIN, VITE_GLOB_IS_IDC } = getAppEnvConfig();
+        if (VITE_GLOB_IS_IDC && VITE_GLOB_IS_IDC.length) {
+          window.location.href = VITE_GLOB_IS_IDC;
+          return;
+        } else if (deveProType) {
           window.location.href = VITE_GLOB_ADMIN_LOGIN;
           return;
         }

+ 17 - 10
src/store/modules/user.ts

@@ -7,7 +7,7 @@ import { PageEnum } from '/@/enums/pageEnum';
 import { JWT_TOKEN_KEY, REFRESH_TOKEN_KEY, ROLES_KEY, USER_INFO_KEY } from '/@/enums/cacheEnum';
 import { getAuthCache, setAuthCache } from '/@/utils/auth';
 import { LoginParams, LoginResultModel, 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 { ligongLoginApi } from '/@/api/sys/ligong';
 import { useI18n } from '/@/hooks/web/useI18n';
 import { useMessage } from '/@/hooks/web/useMessage';
@@ -17,6 +17,7 @@ import { RouteRecordRaw } from 'vue-router';
 import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
 import { createLocalStorage } from '/@/utils/cache/index';
 import { getEntitiesId } from '/@/api/dashboard/index';
+import { getAppEnvConfig } from '/@/utils/env';
 
 interface UserState {
   platInfo: any;
@@ -268,13 +269,20 @@ export const useUserStore = defineStore({
       // this.setSessionTimeout(false);
       // // goLogin && router.push(PageEnum.BASE_LOGIN);
 
-      this.setToken(undefined);
-      this.setSessionTimeout(false);
-      setAuthCache(REFRESH_TOKEN_KEY, undefined);
-      this.setUserInfo(null);
-      goLogin && router.push(PageEnum.BASE_LOGIN);
-      window.localStorage.clear();
-      window.localStorage.removeItem('updateUserInfo');
+      const { VITE_GLOB_IS_IDC } = getAppEnvConfig();
+      if (VITE_GLOB_IS_IDC && VITE_GLOB_IS_IDC.length) {
+        await LoginOut()
+        sessionStorage.removeItem("token")
+        sessionStorage.removeItem("refreshToken")
+      } else {
+        this.setToken(undefined);
+        this.setSessionTimeout(false);
+        setAuthCache(REFRESH_TOKEN_KEY, undefined);
+        this.setUserInfo(null);
+        goLogin && router.push(PageEnum.BASE_LOGIN);
+        window.localStorage.clear();
+        window.localStorage.removeItem('updateUserInfo');
+      }
     },
 
     async doRefresh() {
@@ -324,8 +332,7 @@ export const useUserStore = defineStore({
         // 本系统的登录
         const data = await kidloginApi(loginParams, mode);
         console.log('luozhi1', data);
-
-        return this.process(data.data, goHome);
+        return this.process(data.data || data, goHome);
       } catch (error) {
         return Promise.reject(error);
       }

+ 2 - 0
src/utils/env.ts

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

+ 9 - 9
src/utils/http/axios/Axios.ts

@@ -118,15 +118,15 @@ export class VAxios {
       // If cancel repeat request is turned on, then cancel repeat request is prohibited
       const userStore = useUserStore();
       if (userStore && userStore.jwtToken) {
-        try {
-          const res = jwt_decode(userStore.jwtToken) as JwtModel;
-          const currentTime = (new Date().getTime() + (config.timeout || 0)) / 1000;
-          if (currentTime >= res.exp && this.isNeedTokenURL(config.url)) {
-            await this.refreshTokenBeforeReq(userStore.doRefresh);
-          }
-        } catch (error) {
-          userStore.logout();
-        }
+        // try {//sjl,注释掉去掉token刷新
+        //   const res = jwt_decode(userStore.jwtToken) as JwtModel;
+        //   const currentTime = (new Date().getTime() + (config.timeout || 0)) / 1000;
+        //   if (currentTime >= res.exp && this.isNeedTokenURL(config.url)) {
+        //     await this.refreshTokenBeforeReq(userStore.doRefresh);
+        //   }
+        // } catch (error) {
+        //   userStore.logout();
+        // }
       }
       const {
         headers: { ignoreCancelToken },

+ 9 - 2
src/utils/http/axios/index.ts

@@ -20,6 +20,9 @@ import { PageEnum } from '/@/enums/pageEnum';
 import { router } from '/@/router';
 import { sm2 } from 'sm-crypto';
 import { message } from 'ant-design-vue';
+import { useUserStore } from '/@/store/modules/user';
+
+
 
 // # 国密私钥(后端加密,前端解密)
 const privateKey = 'fe16bcdc8b3e79029984a0a171d5861c58ef9979ed111c01f849f45d165075aa';
@@ -193,8 +196,12 @@ const transform: AxiosTransform = {
         window.localStorage.clear();
         window.sessionStorage.clear();
         // router.push(PageEnum.BASE_HOME);//之前路由返回的地址
-        const { VITE_GLOB_ADMIN_LOGIN } = getAppEnvConfig();
-        window.location.href = VITE_GLOB_ADMIN_LOGIN;
+        const { VITE_GLOB_ADMIN_LOGIN, VITE_GLOB_IS_IDC } = getAppEnvConfig();
+        if (VITE_GLOB_IS_IDC && VITE_GLOB_IS_IDC.length) {
+          useUserStore().logout()
+        } else {
+          window.location.href = VITE_GLOB_ADMIN_LOGIN;
+        }
       }
       if (code === 'ECONNABORTED' && message.indexOf('timeout') !== -1) {
         // errMessage = t('sys.api.apiTimeoutMessage');

+ 1 - 0
src/views/header/Weather.vue

@@ -212,6 +212,7 @@ export default defineComponent({
       window.location.href = `${window.location.origin}/admin/index.html#/lifeline/bigscreen/systemNavigation`;
     };
     const outline = () => {
+      console.log('点击了退出');
       loginOut();
     };
     return {

+ 1 - 0
types/config.d.ts

@@ -197,4 +197,5 @@ export interface GlobEnvConfig {
   VITE_GLOB_LIGONG_ADMIN: string;
   //图片地址
   VITE_GLOB_BASE_IMG: string;
+  VITE_GLOB_IS_IDC:string;
 }