会议室增加自定义状态码

This commit is contained in:
zhangzhuliang 2022-09-01 09:05:28 +08:00
parent c1643e3cb0
commit 7ff222761c
1 changed files with 30 additions and 9 deletions

View File

@ -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 = '后端接口连接异常'
}