From 62c45e2187a481a47a60232876c52e6fb8062d3e Mon Sep 17 00:00:00 2001
From: liudong <liudong>
Date: 星期三, 31 七月 2024 14:44:10 +0800
Subject: [PATCH] 登录接口调试
---
src/api/interceptor.ts | 23 ++++++++++++++++-------
1 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/api/interceptor.ts b/src/api/interceptor.ts
index 09e9392..1dc650c 100644
--- a/src/api/interceptor.ts
+++ b/src/api/interceptor.ts
@@ -2,7 +2,12 @@
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 +17,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
@@ -28,7 +33,6 @@
// }
// config.headers.Authorization = `Bearer ${token}`;
// }
-
const authorization = getAuthorization();
if (authorization) {
@@ -50,7 +54,10 @@
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 !== 0) ||
+ (res.code && res.code !== 20000)
+ ) {
Message.error({
content: res.msg || 'Error',
duration: 5 * 1000,
@@ -67,7 +74,6 @@
okText: 'Re-Login',
async onOk() {
const userStore = useUserStore();
-
await userStore.logout();
window.location.reload();
},
@@ -76,7 +82,10 @@
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;
--
Gitblit v1.8.0