From 5ecb7958c96d3f0b6d47b79aff7eb306c2cf690f Mon Sep 17 00:00:00 2001
From: charles <981744753@qq.com>
Date: 星期二, 06 八月 2024 11:16:58 +0800
Subject: [PATCH] gitlab上面的wms转移到公司git

---
 src/common/untils/request.js |   56 ++++++++++++++++++++++----------------------------------
 1 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/src/common/untils/request.js b/src/common/untils/request.js
index 0843eae..5ddc7a2 100644
--- a/src/common/untils/request.js
+++ b/src/common/untils/request.js
@@ -1,12 +1,10 @@
 import axios from "axios"
 import { Message } from "element-ui"
-
-// import router from '@/router'
-
+import {getApsPage} from './index.js';
 // 寮�鍙戠幆澧冧笅灏嗚嚜宸辩殑token澶嶅埗鍒拌繖閲�, 涔熷彲浠ュ湪娴忚鍣ㄤ腑鎵嬪姩娣诲姞token鍒癱ookie涓�,cookie涓殑token浼樺厛
-const DEV_TOKEN =  ''
+const DEV_TOKEN =  '';
 function environmentType(){
-  let type
+  let type;
   if (location.href.includes('192.168.20.119')) {
     type = 'test'
   } else if (location.href.includes('192.168') || location.href.includes('localhost')) {
@@ -14,28 +12,14 @@
   } else {
     type = 'prod'
   }
-
   return type
 }
-const isDev = environmentType() === 'dev'
-
-const getApsPage = () => {
-  // 棣栭〉閮ㄧ讲鍦ㄥ悇涓幆澧冪殑绔彛
-  const loginPathMap = {
-    prod:`//${window.location.hostname}:9080`,
-    test:`//192.168.20.119:9080`,
-    // 鎯宠烦鍒版湰鍦板惎鍔ㄧ殑鐧诲綍椤电殑璇濋渶瑕佹妸dev鏀规垚浣犳湰鍦伴」鐩矾寰�
-    dev: `//192.168.8.112:8080`
-  }
-
-  return loginPathMap[environmentType()]
-}
-
+const isDev = environmentType() === 'dev';
 
 const Axios = axios.create({
   responseType: "json",
   withCredentials: true // 鏄惁鍏佽甯ookie杩欎簺
-})
+});
 
 /* //POST浼犲弬搴忓垪鍖�(娣诲姞璇锋眰鎷︽埅鍣�) */
 Axios.interceptors.request.use(
@@ -44,6 +28,9 @@
         /(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/,
         "$1",
     );
+    if (config.methodType == "down") {
+      config.responseType = "blob";
+    }
     if (isDev){
       token = token || DEV_TOKEN
     }
@@ -61,25 +48,28 @@
 /* //杩斿洖鐘舵�佸垽鏂�(娣诲姞鍝嶅簲鎷︽埅鍣�) */
 Axios.interceptors.response.use(
   (res) => {
-    /* //瀵瑰搷搴旀暟鎹仛浜涗簨 */
-    if (res.data.code === 200) {
+    if (res.config.responseType === 'blob') {
+      return res.data
+    }else if (res.data.code === 200) {
+      /* //瀵瑰搷搴旀暟鎹仛浜涗簨 */
       return res.data ? res.data : {}
     }else if([2012,2013,2014,2015].includes(res.data.code)){
       if (isDev){
-        alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
-        window.location = getApsPage()+'/login'
+        //alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
+        window.location = 'http://'+getApsPage()+'/login'
       }else {
         //   JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
-        window.location = getApsPage()+'/login'
+        window.location ='http://'+ getApsPage()+'/login'
       }
       return Promise.reject(res.data)
     }else if([2036].includes(res.data.code)){
       if (isDev){
-        window.location = getApsPage()+'/commonWeb?resetPwd=true'
+        window.location ='http://'+ getApsPage()+'/commonWeb?resetPwd=true'
       }else {
         //   JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
-        window.location = getApsPage()+'/commonWeb?resetPwd=true'
+        window.location ='http://'+ getApsPage()+'/commonWeb?resetPwd=true'
       }
+
       return Promise.reject(res.data)
       // if(window.location.pathname && window.location.pathname !== '/login'){
       //   window.location = window.location.origin+'/login'
@@ -97,14 +87,13 @@
     if (error.response.status === 401){
       if (isDev){
         alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
-        window.location = getApsPage()+'/login'
+        window.location ='http://'+ getApsPage()+'/login'
         
       }else {
         //   JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
-        window.location = getApsPage()+'/login'
+        window.location ='http://'+ getApsPage()+'/login'
       }
     }
-
     let { message } = error
     if (message === "Network Error") {
       message = "鍚庣鎺ュ彛杩炴帴寮傚父"
@@ -117,9 +106,8 @@
       message: message,
       type: "error",
       duration: 5 * 1000
-    })
+    });
     return Promise.reject(error)
   }
-)
-
+);
 export default Axios

--
Gitblit v1.8.0