diff --git a/src/utils/axios.js b/src/utils/axios.js index b2fe824..4b8a416 100644 --- a/src/utils/axios.js +++ b/src/utils/axios.js @@ -5,7 +5,8 @@ import { ElMessage } from "element-plus"; import router from "@/router/index"; import { localGet } from "./index"; import config from "~/config"; -import { token } from '../proto/data/pd' +import { token,response } from '../proto/data/pd'; +import { localRemove, pathMap } from "@/utils"; axios.defaults.baseURL = config[import.meta.env.MODE].baseUrl; axios.defaults.withCredentials = true; @@ -31,6 +32,15 @@ function getNeedToken() { // 请求拦截器,内部根据返回值,重新组装,统一管理。 axios.interceptors.response.use( (res) => { + // token过期 + const ret = response.decode(new Uint8Array(res.data)); + if(ret.code ===40100 || ret.code ===40101) { + localRemove("token"); + ElMessage.closeAll(); + ElMessage.error(ret.msg || "Token过期,请重新登录"); + router.push({ path: "/login" }); + return Promise.reject(ret); + } return res.data; }, (error) => { diff --git a/vite.config.js b/vite.config.js index 14c1a67..c366d35 100644 --- a/vite.config.js +++ b/vite.config.js @@ -24,7 +24,8 @@ export default ({ mode }) => defineConfig({ server: { proxy: { '/api': { - target: 'http://frp.shikicc.com:58951', + target: 'http://cdcm_test_api.shikicc.com:58909', + // target: 'http://frp.shikicc.com:58951', // target: 'http://10.10.14.123', // target: 'https://cdcmapi.shikicc.com', changeOrigin: true,