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;