修改组件和接口返回信息
This commit is contained in:
@ -6,6 +6,8 @@ import { createServerTokenAuthentication } from 'alova/client'
|
||||
import VueHook from 'alova/vue'
|
||||
import { toast } from '@/utils/toast'
|
||||
import { ContentTypeEnum, ResultEnum, ShowMessage } from './tools/enum'
|
||||
import { useUserStore } from '@/store'
|
||||
import { router } from '@/utils/tools'
|
||||
|
||||
// 配置动态Tag
|
||||
export const API_DOMAINS = {
|
||||
@ -59,11 +61,22 @@ const alovaInstance = createAlova({
|
||||
console.log('ignoreAuth===>', ignoreAuth)
|
||||
// 处理认证信息 自行处理认证问题
|
||||
if (ignoreAuth) {
|
||||
const token = 'getToken()'
|
||||
// const token = 'getToken()'
|
||||
// if (!token) {
|
||||
// throw new Error('[请求错误]:未登录')
|
||||
// }
|
||||
// method.config.headers.token = token;
|
||||
|
||||
const userStore = useUserStore()
|
||||
const { token } = userStore.userInfo as unknown as IUserInfo
|
||||
|
||||
if (!token) {
|
||||
toast.info('请先登录')
|
||||
router.switchTab('/pages/my/my', 500)
|
||||
throw new Error('[请求错误]:未登录')
|
||||
}
|
||||
// method.config.headers.token = token;
|
||||
|
||||
method.config.headers.token = token;
|
||||
}
|
||||
|
||||
// 处理动态域名
|
||||
@ -96,13 +109,29 @@ const alovaInstance = createAlova({
|
||||
// }
|
||||
|
||||
// 处理业务逻辑错误
|
||||
const { code, message, data } = rawData as IResponse
|
||||
// if (code !== ResultEnum.Success) {
|
||||
// if (config.meta?.toast !== false) {
|
||||
// toast.warning(message)
|
||||
// }
|
||||
// throw new Error(`请求错误[${code}]:${message}`)
|
||||
// }
|
||||
const { code, msg, data } = rawData as IResponse
|
||||
if (code === ResultEnum.Unauthorized) {
|
||||
useUserStore().removeUserInfo()
|
||||
|
||||
if (config.meta?.toast !== false) {
|
||||
toast.info(msg)
|
||||
router.switchTab('/pages/my/my', 1000)
|
||||
}
|
||||
throw new Error(`登录超时[${code}]:${msg}`)
|
||||
}
|
||||
|
||||
if (code === ResultEnum.Success) {
|
||||
if (config.meta?.toast !== false && msg) {
|
||||
if (msg !== '查询成功') toast.info(msg)
|
||||
}
|
||||
}
|
||||
|
||||
if (code !== ResultEnum.Success) {
|
||||
if (config.meta?.toast !== false) {
|
||||
toast.warning(msg)
|
||||
}
|
||||
throw new Error(`请求错误[${code}]:${msg}`)
|
||||
}
|
||||
// 处理成功响应,返回业务数据
|
||||
return data
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user