From 42adf7605b0d7f272e1f26b22e5b92c00b293d80 Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期五, 22 三月 2024 15:35:52 +0800
Subject: [PATCH] 登录页面接口、订单管理列表页面接口先跟进aps项目接口联调及部分代码删减

---
 src/common/untils/request.js |   73 ++++++++++++++++++------------------
 1 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/src/common/untils/request.js b/src/common/untils/request.js
index 1c10074..4541c17 100644
--- a/src/common/untils/request.js
+++ b/src/common/untils/request.js
@@ -3,21 +3,21 @@
 
 // import router from '@/router'
 // 寮�鍙戠幆澧冧笅灏嗚嚜宸辩殑token澶嶅埗鍒拌繖閲�, 涔熷彲浠ュ湪娴忚鍣ㄤ腑鎵嬪姩娣诲姞token鍒癱ookie涓�,cookie涓殑token浼樺厛
-const DEV_TOKEN =  ''
-function environmentType(){
+const DEV_TOKEN = ""
+function environmentType() {
   let type
-  if (location.href.includes('192.168.20.119')) {
-      type = 'test'
-  } else if (location.href.includes('192.168') || location.href.includes('localhost')) {
-      type = 'dev'
+  if (location.href.includes("192.168.20.119")) {
+    type = "test"
+  } else if (location.href.includes("192.168") || location.href.includes("localhost")) {
+    type = "dev"
   } else {
-      type = 'prod'
+    type = "prod"
   }
 
   return type
 }
 
-const isDev = environmentType() === 'dev'
+const isDev = environmentType() === "dev"
 
 const Axios = axios.create({
   responseType: "json",
@@ -26,9 +26,9 @@
 const getApsPage = () => {
   // 棣栭〉閮ㄧ讲鍦ㄥ悇涓幆澧冪殑绔彛
   const loginPathMap = {
-      prod:`//${window.location.hostname}:9080`,
-      test:`//192.168.20.119:9080`,
-      dev: `//192.168.8.107:8080`
+    prod: `//${window.location.hostname}:9080`,
+    test: `//192.168.20.119:9080`,
+    dev: `//192.168.8.107:8080`
   }
   return loginPathMap[environmentType()]
 }
@@ -41,15 +41,13 @@
     // // if (token != undefined) {
     // //   config.headers.Authorization = "Bearer " + token;
     // // }
-    let token = document.cookie.replace(
-      /(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/,
-      "$1",
-    );
-    if (isDev){
+    // let token = localStorage.getItem("token")
+    let token = document.cookie.replace(/(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/, "$1")
+    if (isDev) {
       token = token || DEV_TOKEN
     }
     if (token) {
-      config.headers.Authorization = "Bearer " + token;
+      config.headers.Authorization = "Bearer " + token
     }
     return config
   },
@@ -61,16 +59,17 @@
 /* //杩斿洖鐘舵�佸垽鏂�(娣诲姞鍝嶅簲鎷︽埅鍣�) */
 Axios.interceptors.response.use(
   (res) => {
+    console.log("99999", res)
     /* //瀵瑰搷搴旀暟鎹仛浜涗簨 */
     if (res.data.code === 200) {
       return res.data ? res.data : {}
-    } else if([2012,2013,2014,2015].includes(res.data.code)){
-      if (isDev){
+    } else if ([2012, 2013, 2014, 2015].includes(res.data.code)) {
+      if (isDev) {
         alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
-        window.location = getApsPage()+'/login'
-      }else {
+        window.location = getApsPage() + "/login"
+      } else {
         //   JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
-        window.location = getApsPage()+'/login'
+        window.location = getApsPage() + "/login"
       }
       // Message({
       //   message: res.data.msg,
@@ -78,30 +77,32 @@
       //   duration: 5 * 1000
       // })
       return Promise.reject(res.data)
-    }else if([2036].includes(res.data.code)){
-      if (isDev){
-        window.location = getApsPage()+'/commonWeb?resetPwd=true'
-      }else {
+    } else if ([2036].includes(res.data.code)) {
+      if (isDev) {
+        window.location = getApsPage() + "/commonWeb?resetPwd=true"
+      } else {
         //   JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
-        window.location = getApsPage()+'/commonWeb?resetPwd=true'
+        window.location = getApsPage() + "/commonWeb?resetPwd=true"
       }
       return Promise.reject(res.data)
 
       // if(window.location.pathname && window.location.pathname !== '/login'){
       //   window.location = window.location.origin+'/login'
       // }
+    } else {
+      return res.data ? res.data : {}
     }
   },
   (error) => {
-    if(error.response.status === 401){
-      if (isDev){
-        alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
-        window.location = getApsPage()+'/login'
-      }else {
-        //   JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
-        window.location = getApsPage()+'/login'
-      }
-    }
+    // if (error.response.status === 401) {
+    //   if (isDev) {
+    //     alert("JWT澶辨晥,鍗冲皢璺宠浆鑷崇櫥褰曢〉..")
+    //     window.location = getApsPage() + "/login"
+    //   } else {
+    //     //   JWT閴存潈澶辨晥 璺宠浆鍒扮櫥褰曢〉
+    //     window.location = getApsPage() + "/login"
+    //   }
+    // }
     let { message } = error
     if (message === "Network Error") {
       message = "鍚庣鎺ュ彛杩炴帴寮傚父"

--
Gitblit v1.8.0