会议室增加自定义状态码
This commit is contained in:
parent
c1643e3cb0
commit
7ff222761c
|
@ -11,8 +11,13 @@ import store from '@/store'
|
||||||
import qs from 'qs'
|
import qs from 'qs'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
// import { isArray } from '@/utils/validate'
|
// import { isArray } from '@/utils/validate'
|
||||||
import { message } from 'ant-design-vue'
|
import {
|
||||||
import { getAccessToken, setAccessToken } from '@/utils/accessToken'
|
message
|
||||||
|
} from 'ant-design-vue'
|
||||||
|
import {
|
||||||
|
getAccessToken,
|
||||||
|
setAccessToken
|
||||||
|
} from '@/utils/accessToken'
|
||||||
|
|
||||||
let loadingInstance
|
let loadingInstance
|
||||||
|
|
||||||
|
@ -29,11 +34,16 @@ const handleCode = (code, msg, res) => {
|
||||||
store.dispatch('user/resetAll').catch(() => {})
|
store.dispatch('user/resetAll').catch(() => {})
|
||||||
break
|
break
|
||||||
case 403:
|
case 403:
|
||||||
router.push({ path: '/401' }).catch(() => {})
|
router.push({
|
||||||
|
path: '/401'
|
||||||
|
}).catch(() => {})
|
||||||
break
|
break
|
||||||
case 500:
|
case 500:
|
||||||
message.error(msg || '接口异常')
|
message.error(msg || '接口异常')
|
||||||
break
|
break
|
||||||
|
case 505:
|
||||||
|
message.error(msg || '该时段已被预约')
|
||||||
|
break
|
||||||
case 302:
|
case 302:
|
||||||
// window.location.href = redirect
|
// window.location.href = redirect
|
||||||
break
|
break
|
||||||
|
@ -64,7 +74,7 @@ instance.interceptors.request.use(
|
||||||
if (
|
if (
|
||||||
config.data &&
|
config.data &&
|
||||||
config.headers['Content-Type'] ===
|
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)
|
config.data = qs.stringify(config.data)
|
||||||
if (debounce.some((item) => config.url.includes(item))) {
|
if (debounce.some((item) => config.url.includes(item))) {
|
||||||
|
@ -91,7 +101,10 @@ instance.interceptors.response.use(
|
||||||
console.log('接口返回headers', response.headers)
|
console.log('接口返回headers', response.headers)
|
||||||
console.log('接口返回REDIRECT', response.headers.redirect)
|
console.log('接口返回REDIRECT', response.headers.redirect)
|
||||||
response['Access-Control-Expose-Headers'] = 'redirect'
|
response['Access-Control-Expose-Headers'] = 'redirect'
|
||||||
const { code, message } = response.data
|
const {
|
||||||
|
code,
|
||||||
|
message
|
||||||
|
} = response.data
|
||||||
|
|
||||||
if (response.headers.token) {
|
if (response.headers.token) {
|
||||||
setAccessToken(response.headers.token)
|
setAccessToken(response.headers.token)
|
||||||
|
@ -106,7 +119,7 @@ instance.interceptors.response.use(
|
||||||
if (response.headers.redirect === '/#/login') {
|
if (response.headers.redirect === '/#/login') {
|
||||||
var keys = document.cookie.match(/[^ =;]+(?=\=)/g)
|
var keys = document.cookie.match(/[^ =;]+(?=\=)/g)
|
||||||
if (keys) {
|
if (keys) {
|
||||||
for (var i = keys.length; i--; ) {
|
for (var i = keys.length; i--;) {
|
||||||
document.cookie =
|
document.cookie =
|
||||||
keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString() //清除当前域名下的,例如:m.kevis.com
|
keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString() //清除当前域名下的,例如:m.kevis.com
|
||||||
document.cookie =
|
document.cookie =
|
||||||
|
@ -150,7 +163,10 @@ instance.interceptors.response.use(
|
||||||
console.log('接口error', error)
|
console.log('接口error', error)
|
||||||
if (loadingInstance) loadingInstance.close()
|
if (loadingInstance) loadingInstance.close()
|
||||||
|
|
||||||
const { response, message } = error
|
const {
|
||||||
|
response,
|
||||||
|
message
|
||||||
|
} = error
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
console.log('接口返回', response)
|
console.log('接口返回', response)
|
||||||
console.log('接口返回headers', response.headers)
|
console.log('接口返回headers', response.headers)
|
||||||
|
@ -162,12 +178,17 @@ instance.interceptors.response.use(
|
||||||
window.location.replace(response.headers.redirect)
|
window.location.replace(response.headers.redirect)
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
const { status, data } = response
|
const {
|
||||||
|
status,
|
||||||
|
data
|
||||||
|
} = response
|
||||||
|
|
||||||
handleCode(status, data.msg || message, response.headers.redirect)
|
handleCode(status, data.msg || message, response.headers.redirect)
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
} else {
|
} else {
|
||||||
let { message } = error
|
let {
|
||||||
|
message
|
||||||
|
} = error
|
||||||
if (message === 'Network Error') {
|
if (message === 'Network Error') {
|
||||||
message = '后端接口连接异常'
|
message = '后端接口连接异常'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue