Browse Source

去除isToken 判断

yangbq 1 month ago
parent
commit
e9854889b6
2 changed files with 19 additions and 19 deletions
  1. 10 10
      src/utils/request.js
  2. 9 9
      src/utils/request2.js

+ 10 - 10
src/utils/request.js

@@ -28,14 +28,14 @@ service.interceptors.request.use(config => {
   const isToken = (config.headers || {}).isToken === false
   // 是否需要防止数据重复提交
   const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
-  if (getToken() && !isToken) {
+  if (getToken()) {
      const loginPath = isPadDevice() ? 2 : 1;
- // next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
- if(loginPath==1){
-    config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
-   }else{
-    config.headers['Authorization'] =getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
-   }
+    console.log('loginPath:',loginPath)
+    if(loginPath==1){
+      config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
+    }else{
+      config.headers['Authorization'] =getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
+    }
   }
   // 请求参数加密
   if (process.env.VUE_APP_AES_ENCRYPT_ENABLED == 'true') {
@@ -131,11 +131,11 @@ service.interceptors.response.use(
              const loginPath = isPadDevice() ? 2 : 1;
             // next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
             if(loginPath==1){
-              location.href = '#/login'; 
+              location.href = '#/login';
               }else{
                 location.href = '#/loginPad';
               }
-          
+
           });
         }).catch(() => {
           isRelogin.show = false;
@@ -204,4 +204,4 @@ export function download(url, params, filename) {
   })
 }
 
-export default service
+export default service

+ 9 - 9
src/utils/request2.js

@@ -28,14 +28,14 @@ service.interceptors.request.use(config => {
   const isToken = (config.headers || {}).isToken === false
   // 是否需要防止数据重复提交
   const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
-  if (getToken() && !isToken) {
+  if (getToken()) {
      const loginPath = isPadDevice() ? 2 : 1;
  // next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
- if(loginPath==1){
-    config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
-   }else{
-    config.headers['Authorization'] =getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
-   }
+      if(loginPath==1){
+        config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
+      }else{
+        config.headers['Authorization'] =getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
+      }
   }
   // 请求参数加密
   if (process.env.VUE_APP_AES_ENCRYPT_ENABLED == 'true') {
@@ -131,11 +131,11 @@ service.interceptors.response.use(
              const loginPath = isPadDevice() ? 2 : 1;
             // next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
             if(loginPath==1){
-              location.href = '#/login'; 
+              location.href = '#/login';
               }else{
                 location.href = '#/loginPad';
               }
-          
+
           });
         }).catch(() => {
           isRelogin.show = false;
@@ -204,4 +204,4 @@ export function download(url, params, filename) {
   })
 }
 
-export default service
+export default service