From 7ff222761cb23c4a73806f1b37d0725eda1535f6 Mon Sep 17 00:00:00 2001 From: zhangzhuliang <577851561@qq.com> Date: Thu, 1 Sep 2022 09:05:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E8=AE=AE=E5=AE=A4=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E7=8A=B6=E6=80=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/utils/request.js | 39 +++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/front/src/utils/request.js b/front/src/utils/request.js index 24446dc5..d96f4f78 100644 --- a/front/src/utils/request.js +++ b/front/src/utils/request.js @@ -11,8 +11,13 @@ import store from '@/store' import qs from 'qs' import router from '@/router' // import { isArray } from '@/utils/validate' -import { message } from 'ant-design-vue' -import { getAccessToken, setAccessToken } from '@/utils/accessToken' +import { + message +} from 'ant-design-vue' +import { + getAccessToken, + setAccessToken +} from '@/utils/accessToken' let loadingInstance @@ -29,11 +34,16 @@ const handleCode = (code, msg, res) => { store.dispatch('user/resetAll').catch(() => {}) break case 403: - router.push({ path: '/401' }).catch(() => {}) + router.push({ + path: '/401' + }).catch(() => {}) break case 500: message.error(msg || '接口异常') break + case 505: + message.error(msg || '该时段已被预约') + break case 302: // window.location.href = redirect break @@ -64,7 +74,7 @@ instance.interceptors.request.use( if ( config.data && config.headers['Content-Type'] === - 'application/x-www-form-urlencoded;charset=UTF-8' + 'application/x-www-form-urlencoded;charset=UTF-8' ) config.data = qs.stringify(config.data) if (debounce.some((item) => config.url.includes(item))) { @@ -91,7 +101,10 @@ instance.interceptors.response.use( console.log('接口返回headers', response.headers) console.log('接口返回REDIRECT', response.headers.redirect) response['Access-Control-Expose-Headers'] = 'redirect' - const { code, message } = response.data + const { + code, + message + } = response.data if (response.headers.token) { setAccessToken(response.headers.token) @@ -106,7 +119,7 @@ instance.interceptors.response.use( if (response.headers.redirect === '/#/login') { var keys = document.cookie.match(/[^ =;]+(?=\=)/g) if (keys) { - for (var i = keys.length; i--; ) { + for (var i = keys.length; i--;) { document.cookie = keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString() //清除当前域名下的,例如:m.kevis.com document.cookie = @@ -150,7 +163,10 @@ instance.interceptors.response.use( console.log('接口error', error) if (loadingInstance) loadingInstance.close() - const { response, message } = error + const { + response, + message + } = error if (error.response) { console.log('接口返回', response) console.log('接口返回headers', response.headers) @@ -162,12 +178,17 @@ instance.interceptors.response.use( window.location.replace(response.headers.redirect) return Promise.resolve() } - const { status, data } = response + const { + status, + data + } = response handleCode(status, data.msg || message, response.headers.redirect) return Promise.reject(error) } else { - let { message } = error + let { + message + } = error if (message === 'Network Error') { message = '后端接口连接异常' }