diff --git a/src/api/config.js b/src/api/config.js index 0130bcf3..dc624903 100644 --- a/src/api/config.js +++ b/src/api/config.js @@ -51,9 +51,8 @@ http.interceptors.response.use( (response) => { // console.log('response', response) const { - data: {code, msg, show}, + data: {code, msg ,show}, } = response; - console.log('code', code) if (code === 0 || code === 200) { return response; } @@ -65,7 +64,7 @@ http.interceptors.response.use( localStorage.removeItem('refreshPage') return Promise.reject(response); } - show && message.error(msg); + show ? message.error(msg):message.error('系统接口数据异常,请联系管理员'); console.log("api %o", msg); return Promise.reject(response); }, diff --git a/src/api/request.js b/src/api/request.js index cbdc783b..4efc7830 100644 --- a/src/api/request.js +++ b/src/api/request.js @@ -1,6 +1,8 @@ import {isRef, reactive, ref, toRefs, unref, watch, watchEffect} from "vue"; import {getCookieForName, throttle} from "@/api/method"; import JSONBigInt from "json-bigint"; +import router from "@/router"; +import {message} from "ant-design-vue"; const JSONBigIntStr = JSONBigInt({ storeAsString: true }); @@ -346,5 +348,18 @@ export async function request(_url, params) { return res.text(); }).then(res => { return JSONBigIntStr.parse(res); + }).then(res => { + if (res.code === 0 || res.code === 200) { + return res; + } + if (res.code === 1000) { + (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'alpine') ? + router.push({path: 'login', query: { returnUrl: router.currentRoute.value.fullPath }}) : + (window.location.href = process.env.VUE_APP_LOGIN_URL + encodeURIComponent(window.location.protocol + process.env.VUE_APP_BOE_API_URL + process.env.VUE_APP_BASE + router.currentRoute.value.fullPath)) + localStorage.removeItem('refreshPage') + return Promise.reject(res); + } + res.show ? message.error(res.msg):message.error('系统接口数据异常,请联系管理员'); + return Promise.reject(res); }); } \ No newline at end of file