From 6337b811cd5f2426a3fdc9abcdc3e5f10435cc3e Mon Sep 17 00:00:00 2001 From: yuping <82253452@qq.com> Date: Fri, 24 Mar 2023 03:50:10 +0800 Subject: [PATCH] =?UTF-8?q?--fix=20bug=20=E7=B3=BB=E7=BB=9F=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/config.js | 5 ++--- src/api/request.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) 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