|
@@ -9,6 +9,7 @@ import { useLoginStore, useAccountStore, useErrorInfoStore } from '@/stores'
|
|
|
import { CommonResult, ResultCode, SendMsgToMQ } from './types'
|
|
import { CommonResult, ResultCode, SendMsgToMQ } from './types'
|
|
|
import { FunCode } from '@/constants/funcode'
|
|
import { FunCode } from '@/constants/funcode'
|
|
|
import service from '@/services'
|
|
import service from '@/services'
|
|
|
|
|
+import eventBus from '@/services/bus'
|
|
|
|
|
|
|
|
export default new (class {
|
|
export default new (class {
|
|
|
private readonly axiosInstance = axios.create({
|
|
private readonly axiosInstance = axios.create({
|
|
@@ -58,6 +59,13 @@ export default new (class {
|
|
|
if (err.response) {
|
|
if (err.response) {
|
|
|
const { msg, message } = err.response.data ?? {}
|
|
const { msg, message } = err.response.data ?? {}
|
|
|
switch (err.response.status) {
|
|
switch (err.response.status) {
|
|
|
|
|
+ case 401: {
|
|
|
|
|
+ const loginStore = useLoginStore()
|
|
|
|
|
+ if (loginStore.token) {
|
|
|
|
|
+ eventBus.$emit('LogoutNotify', '登录失效,请重新登录')
|
|
|
|
|
+ }
|
|
|
|
|
+ return Promise.reject(msg || message)
|
|
|
|
|
+ }
|
|
|
case 408: {
|
|
case 408: {
|
|
|
return Promise.reject('请求超时,请稍后再试')
|
|
return Promise.reject('请求超时,请稍后再试')
|
|
|
}
|
|
}
|
|
@@ -129,12 +137,15 @@ export default new (class {
|
|
|
config.url = baseUrl + config.url
|
|
config.url = baseUrl + config.url
|
|
|
const res = await this.request<CommonResult<T>>(config, errMsg)
|
|
const res = await this.request<CommonResult<T>>(config, errMsg)
|
|
|
switch (res.code) {
|
|
switch (res.code) {
|
|
|
- case ResultCode.InvalidToken:
|
|
|
|
|
|
|
+ case ResultCode.InvalidToken: {
|
|
|
return Promise.reject('令牌无效')
|
|
return Promise.reject('令牌无效')
|
|
|
- case ResultCode.Success:
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ case ResultCode.Success: {
|
|
|
return res
|
|
return res
|
|
|
- default:
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ default: {
|
|
|
return Promise.reject(res.msg)
|
|
return Promise.reject(res.msg)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -149,12 +160,15 @@ export default new (class {
|
|
|
config.url = baseUrl + config.url
|
|
config.url = baseUrl + config.url
|
|
|
const res = await this.request<CommonResult<T>>(config, errMsg)
|
|
const res = await this.request<CommonResult<T>>(config, errMsg)
|
|
|
switch (res.code) {
|
|
switch (res.code) {
|
|
|
- case ResultCode.InvalidToken:
|
|
|
|
|
|
|
+ case ResultCode.InvalidToken: {
|
|
|
return Promise.reject('令牌无效')
|
|
return Promise.reject('令牌无效')
|
|
|
- case 0:
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ case 0: {
|
|
|
return res
|
|
return res
|
|
|
- default:
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ default: {
|
|
|
return Promise.reject(res.msg)
|
|
return Promise.reject(res.msg)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|