From 1da0bc255179f25b5227bec27833cf486cb6cb90 Mon Sep 17 00:00:00 2001
From: yinbangzhong <zhongbangyin@126.com>
Date: 星期二, 10 九月 2024 19:41:40 +0800
Subject: [PATCH] agent会话

---
 src/api/interceptor.ts |   37 +++++++++++++++++++++++++++----------
 1 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/api/interceptor.ts b/src/api/interceptor.ts
index 36599d4..529dbfa 100644
--- a/src/api/interceptor.ts
+++ b/src/api/interceptor.ts
@@ -2,7 +2,15 @@
 import type { AxiosRequestConfig, AxiosResponse } from 'axios';
 import { Message, Modal } from '@arco-design/web-vue';
 import { useUserStore } from '@/store';
-import { getAuthorization, getToken, setAuthorization, setToken } from "@/utils/auth";
+import {
+  getAuthorization,
+  getToken,
+  setAuthorization,
+  setToken,
+} from '@/utils/auth';
+
+
+
 
 export interface HttpResponse<T = unknown> {
   status: number;
@@ -12,9 +20,9 @@
 }
 
 if (import.meta.env.VITE_API_BASE_URL) {
-  axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL;
+  // axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL;
 }
-axios.defaults.withCredentials = true
+axios.defaults.withCredentials = true;
 axios.interceptors.request.use(
   (config: AxiosRequestConfig) => {
     // let each request carry token
@@ -29,7 +37,6 @@
     //   config.headers.Authorization = `Bearer ${token}`;
     // }
 
-
     const authorization = getAuthorization();
     if (authorization) {
       if (!config.headers) {
@@ -37,7 +44,8 @@
       }
       config.headers.Authorization = `${authorization}`;
     }
-    config.headers.Authorization = 'IjFjOWY3OWM0NGUxYzExZWZhMDk0MDI0MmFjMTIwMDA2Ig.ZqhQ-w.JmA9ESUTd_JKK2wtZ4PVgVmCNj8';
+    // config.headers.Authorization =
+    //   'ImE4NGQ4ZWNjNGVmYjExZWZiZjRkMDI0MmFjMTIwMDA2Ig.ZqnIBw.ZX7_UxnSBKu8x_riQ5FrHLMAS78';
     return config;
   },
   (error) => {
@@ -49,9 +57,16 @@
 axios.interceptors.response.use(
   (response: AxiosResponse<HttpResponse>) => {
     const res = response.data;
-
     // if the custom code is not 20000, it is judged as an error.
-    /*if ((res.retcode && res.retcode !== 0) || (res.code && res.code !== 20000)) {
+    if ( (res.retcode && res.retcode == 401) ||  (res.code && res.code == 401) || (res.code && res.code == 4006))
+    {
+      const userStore = useUserStore();
+      userStore.logout();
+    }
+    if (
+      (res.retcode && res.retcode !== 0) ||
+      (res.code && res.code !== 20000 && res.code !== 200)
+    ) {
       Message.error({
         content: res.msg || 'Error',
         duration: 5 * 1000,
@@ -68,7 +83,6 @@
           okText: 'Re-Login',
           async onOk() {
             const userStore = useUserStore();
-
             await userStore.logout();
             window.location.reload();
           },
@@ -77,9 +91,12 @@
       return Promise.reject(new Error(res.msg || 'Error'));
     }
 
-    if(response.config.url === '/v1/user/login'|| response.config.url === '/base/login')  {
+    if (
+      response.config.url === '/v1/user/login' ||
+      response.config.url === '/base/login'
+    ) {
       setAuthorization(response.headers.authorization);
-    }*/
+    }
     return res;
   },
   (error) => {

--
Gitblit v1.8.0