From e4782d9b6bc563b43522a66ca613b0cc0d51c299 Mon Sep 17 00:00:00 2001 From: JayChou Date: Wed, 26 Mar 2025 17:51:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=A8=E5=93=8D=E5=BA=94=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E5=99=A8=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index 031139b..7887f51 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -2,9 +2,9 @@ import axios from "axios"; import pinia from "@/store"; import { ElMessage } from "element-plus"; -import {removeToken} from '@/utils/auth' +import { removeToken } from "@/utils/auth"; import userStore from "@/store/modules/user"; -import router from '@/router' +import router from "@/router"; // 创建axios实例 const server = axios.create({ baseURL: import.meta.env.VITE_APP_BASE_API, @@ -22,19 +22,23 @@ server.interceptors.request.use((config) => { // 创建相应拦截器 server.interceptors.response.use((response) => { if (response.data.code === 401) { - const useuserStore = userStore(pinia); + const useuserStore = userStore(pinia); -// useuserStore.clearStatus(); + // useuserStore.clearStatus(); // return Promise.reject(response); } - if(response.data.code=== 401){ + if (response.data.code != 200 && response.data.code != 0) { + ElMessage.error(response.data.message); + return Promise.reject(response); + } + if (response.data.code === 401) { ElMessage.error(response.data.message); return Promise.reject(response); } if (response.data.code === 412) { ElMessage.error(response.data.message); - removeToken() - router.push('/login') + removeToken(); + router.push("/login"); return Promise.reject(response); } return response.data;