From e2f129ee192ae3469848beeceac262b13ba8eacb Mon Sep 17 00:00:00 2001
From: 马宇豪 <978517621@qq.com>
Date: 星期三, 14 六月 2023 15:52:11 +0800
Subject: [PATCH] 新增页面和配置,对接口

---
 src/util/request.js |   32 +++++++++++++++++++-------------
 1 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/src/util/request.js b/src/util/request.js
index 8f3b97a..2fb29a4 100644
--- a/src/util/request.js
+++ b/src/util/request.js
@@ -1,6 +1,8 @@
 import axios from "axios";//原生的axios
 import Cookies from 'js-cookie';
 import { Session } from '@/util/storage';
+import {message} from "ant-design-vue";
+import { loginOut } from "@/api/login";
 //用来拦截用的
 axios.defaults.headers.post["Content-Type"] = "application/json;charset=utf-8";
 //创建一个单例
@@ -33,8 +35,13 @@
 http.interceptors.response.use(
     (response) => {
         // 对响应数据做点什么
-        if (response.data.code && response.data.code === 'A0213') {
-            this.$message.error('用户uid不存在');
+        if (response.data.code && response.data.code === 401) {
+            message.error('用户不存在');
+            loginOut()
+                .then(() => {
+                    Session.clear();
+                    window.location.href = '/';
+                });
             // useLoginApi()
             //     .signOut()
             //     .then(() => {
@@ -42,33 +49,32 @@
             //         window.location.href = '/';
             //     });
         } else if (response.data.code && response.data.code === 405) {
-            this.$message.error('token失效');
-            // useLoginApi()
-            //     .signOut()
-            //     .then(() => {
-            //         Session.clear();
-            //         window.location.href = '/';
-            //     });
+            message.error('token失效');
+            loginOut()
+                .then(() => {
+                    Session.clear();
+                    window.location.href = '/';
+                });
         }
         return Promise.resolve(response);
     },
     (error) => {
         // 对响应错误做点什么
         if (error.message.indexOf('timeout') != -1) {
-            this.$message.error('网络超时');
+            message.error('网络超时');
             setTimeout(() => {
                 Session.clear();
                 window.location.href = '/';
             }, 1000);
         } else if (error.message == 'Network Error') {
-            this.$message.error('网络连接错误');
+            message.error('网络连接错误');
             setTimeout(() => {
                 Session.clear();
                 window.location.href = '/';
             }, 1000);
         } else {
-            if (error.response.data) this.$message.error(error.response.data.error);
-            else this.$message.error('接口路径找不到');
+            if (error.response.data) message.error(error.response.data.error);
+            else message.error('接口路径找不到');
         }
         return Promise.reject(error);
     }

--
Gitblit v1.9.2