weixin_52219567 hai 3 semanas
pai
achega
fe99a0b8c4
Modificáronse 2 ficheiros con 11 adicións e 56 borrados
  1. 4 4
      src/permission.ts
  2. 7 52
      src/utils/request.ts

+ 4 - 4
src/permission.ts

@@ -119,14 +119,14 @@ router.beforeEach(async (to, from, next) => {
   const userStore = useUserStore();
 
   // 需求一:判断是否需要调用 getInfo(有 token 或 不在白名单)
-  const needGetInfo = token || !isWhiteList(to.path);
-
-  if (needGetInfo) {
+  // const needGetInfo = token || !isWhiteList(to.path);
+  // console.log(!isWhiteList(to.path), '8888888888888888')
+  if (token) {
     const [err] = await tos(userStore.getInfo());
 
     // 需求五:getInfo 失败跳转/login
     if (err) {
-      await userStore.logout();
+      await useUserStore().logout();
       ElMessage.error(err);
       doRedirect('/login', next, isMultiDomain);
       NProgress.done();

+ 7 - 52
src/utils/request.ts

@@ -9,20 +9,6 @@ import { LoadingInstance } from 'element-plus/es/components/loading/src/loading'
 import FileSaver from 'file-saver';
 import { encryptBase64, encryptWithAes, generateAesKey, decryptWithAes, decryptBase64 } from '@/utils/crypto';
 import { encrypt, decrypt } from '@/utils/jsencrypt';
-import { onPath, DOMAIN_MAP } from '@/utils/siteConfig';
-import router from '@/router';
-
-// 获取主站完整 URL(用于跨域跳转)
-function getMainSiteUrl(path: string) {
-  const mainDomain = DOMAIN_MAP.www;
-  if (import.meta.env.PROD) {
-    return `https://${mainDomain}${path}`;
-  } else {
-    // 本地开发:指向主站域名加上当前运行的端口
-    const devPort = window.location.port || import.meta.env.VITE_APP_PORT;
-    return `https://${mainDomain}:${devPort}${path}`;
-  }
-}
 
 const encryptHeader = 'encrypt-key';
 let downloadLoadingInstance: LoadingInstance;
@@ -150,11 +136,15 @@ service.interceptors.response.use(
             useUserStore()
               .logout()
               .then(() => {
-                if (import.meta.env.VITE_DOMAIN_NAME == 'true') {
-                  window.location.href = getMainSiteUrl('/login');
+                let url = `https://${import.meta.env.VITE_DOMAIN_PASSPORT}`;
+
+                if (import.meta.env.PROD) {
+                  url = `${url}/login`;
                 } else {
-                  router.push('/login');
+                  const devPort = window.location.port || import.meta.env.VITE_APP_PORT;
+                  url = `${url}:${devPort}/login`;
                 }
+                window.location.href = url;
               });
           })
           .catch(() => {
@@ -162,41 +152,6 @@ service.interceptors.response.use(
           });
       }
       return Promise.reject('无效的会话,或者会话已过期,请重新登录。');
-
-      // prettier-ignore
-      // if (!isRelogin.show) {
-      //   isRelogin.show = true;
-      //   useUserStore().logout().then(() => {
-      //     window.location.href = getMainSiteUrl('/index');
-      //   });
-
-      // ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
-      //   confirmButtonText: '重新登录',
-      //   cancelButtonText: '取消',
-      //   type: 'warning'
-      // }).then(() => {
-      //   isRelogin.show = false;
-      //   useUserStore().logout().then(() => {
-      //     router.replace({
-      //       path: '/login',
-      //       query: {
-      //         redirect: encodeURIComponent(router.currentRoute.value.fullPath || '/')
-      //       }
-      //     })
-      //   });
-      // }).catch(() => {
-      //   isRelogin.show = false;
-      // });
-      // }
-
-      // useUserStore().logout().then(() => {
-      //   if (import.meta.env.VITE_DOMAIN_NAME == 'true') {
-      //     window.location.href = getMainSiteUrl('/login');
-      //   }else{
-      //     router.push('/login');
-      //   }
-      // });
-      // return Promise.reject('无效的会话,或者会话已过期,请重新登录。');
     } else if (code === HttpStatus.SERVER_ERROR) {
       ElMessage({ message: msg, type: 'error' });
       // return Promise.reject(new Error(msg));