From 04dba6a17f836b5fbdf0eedff8a129c6785fd8a2 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期五, 28 二月 2025 18:25:00 +0800
Subject: [PATCH] 111

---
 admin/src/utils/request.js |   33 ++++++++++++++++++---------------
 1 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/admin/src/utils/request.js b/admin/src/utils/request.js
index 17a1ddd..ce83873 100644
--- a/admin/src/utils/request.js
+++ b/admin/src/utils/request.js
@@ -3,6 +3,7 @@
 import pkg from '../../package'
 import { trim } from './util'
 import cache from '../plugins/cache'
+import { Message } from 'element-ui'
 
 axios.defaults.headers.common['Content-Type'] = 'application/json;charset=UTF-8'
 const axiosInstance = axios.create({
@@ -13,7 +14,6 @@
 
 // 鏂板缓璇锋眰鎷︽埅鍣�
 axiosInstance.interceptors.request.use(config => {
-  // debugger
   // 鍙傛暟鍘荤┖鏍�
   if (config.trim === true) {
     if (config.data != null) {
@@ -31,11 +31,9 @@
   config.headers['eva-platform'] = `pc-${pkg.version}`
   // 璁剧疆璁よ瘉澶�
   const authToken = Cookies.get('eva-auth-token')
-
   if (authToken != null) {
     config.headers['eva-auth-token'] = authToken
   }
-  // debugger
   return config
 }, function (error) {
   return Promise.reject(error)
@@ -43,6 +41,8 @@
 
 // 鏂板缓鍝嶅簲鎷︽埅鍣�
 axiosInstance.interceptors.response.use((response) => {
+
+  // console.log(response.status)
   // debugger
   // 璇锋眰澶辫触
   if (response.status !== 200) {
@@ -54,20 +54,23 @@
   }
   // 鏈櫥褰�
   if (response.data.code === 401) {
-    // window.location.href = '/#/'
-    // debugger
     if (response.config.autoLogin !== false) {
-      // window.location.href = process.env.VUE_APP_ROUTER_MODE === 'history' ? '/#/login' : '/login'
-      window.location.href = process.env.VUE_APP_CONTEXT_PATH
-      // window.location.href = '/hfznzzzd_web'
+      location.reload()
+      // window.location.href = process.env.VUE_APP_ROUTER_MODE === 'history' ? '/login' : '/#/login'
     }
     return Promise.reject(response.data)
   }
   // 涓氬姟澶辫触
   if (!response.data.success) {
-    return Promise.reject(response.data)
+    Message.error(response.data.message)
+    return null
   }
-  return response.data.data
+  if (response.data.data) {
+    return response.data.data
+  } else {
+    return response.data
+  }
+
 }, function (error) {
   if (error.code == null) {
     return Promise.reject(new Error('鏈嶅姟鍣ㄧ箒蹇欙紝璇风◢鍚庡啀璇�'))
@@ -85,7 +88,7 @@
     __arguments: args,
     __result_promise: null,
     // 寮�鍚紦瀛�
-    cache () {
+    cache() {
       const data = this.__cacheImpl.getJSON(cacheKey)
       if (data != null) {
         this.__result_promise = Promise.resolve(data)
@@ -95,16 +98,16 @@
       }
       return this
     },
-    then () {
+    then() {
       return this.__access('then', arguments)
     },
-    catch () {
+    catch() {
       return this.__access('catch', arguments)
     },
-    finally () {
+    finally() {
       return this.__access('finally', arguments)
     },
-    __access (methodName, args) {
+    __access(methodName, args) {
       if (this.__result_promise != null) {
         return this.__result_promise
       }

--
Gitblit v1.9.3