|
@@ -22,6 +22,7 @@ import { errorResult } from './const'
|
|
|
import { useI18n } from '/@/hooks/web/useI18n'
|
|
|
import { createNow, formatRequestDate } from './helper'
|
|
|
import { TOKEN_KEY } from '/@/enums/cacheEnum'
|
|
|
+import router from '/@/router'
|
|
|
|
|
|
const globSetting = useGlobSetting()
|
|
|
const prefix = globSetting.urlPrefix
|
|
@@ -54,19 +55,19 @@ const transform: AxiosTransform = {
|
|
|
const { code, data: result, msg: message } = data
|
|
|
|
|
|
// 这里逻辑可以根据项目进行修改
|
|
|
- const hasSuccess = data && Reflect.has(data, 'code') && code === ResultEnum.SUCCESS
|
|
|
- if (!hasSuccess) {
|
|
|
- if (message) {
|
|
|
- // errorMessageMode=‘modal’的时候会显示modal错误弹窗,而不是消息提示,用于一些比较重要的错误
|
|
|
- if (options.errorMessageMode === 'modal') {
|
|
|
- createErrorModal({ title: t('sys.api.errorTip'), content: message })
|
|
|
- } else if (options.errorMessageMode === 'message') {
|
|
|
- createMessage.error(message)
|
|
|
- }
|
|
|
- }
|
|
|
- Promise.reject(new Error(message))
|
|
|
- return errorResult
|
|
|
- }
|
|
|
+ // const hasSuccess = data && Reflect.has(data, 'code') && code === ResultEnum.SUCCESS
|
|
|
+ // if (!hasSuccess) {
|
|
|
+ // if (message) {
|
|
|
+ // // errorMessageMode=‘modal’的时候会显示modal错误弹窗,而不是消息提示,用于一些比较重要的错误
|
|
|
+ // if (options.errorMessageMode === 'modal') {
|
|
|
+ // createErrorModal({ title: t('sys.api.errorTip'), content: message })
|
|
|
+ // } else if (options.errorMessageMode === 'message') {
|
|
|
+ // createMessage.error(message)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // Promise.reject(new Error(message))
|
|
|
+ // return errorResult
|
|
|
+ // }
|
|
|
|
|
|
// 接口请求成功,直接返回结果
|
|
|
if (code === ResultEnum.SUCCESS) {
|
|
@@ -77,6 +78,21 @@ const transform: AxiosTransform = {
|
|
|
}
|
|
|
return result
|
|
|
}
|
|
|
+ // 用户信息过期了
|
|
|
+ if (code === ResultEnum.EXPIRED) {
|
|
|
+ console.log(111)
|
|
|
+
|
|
|
+ createErrorModal({
|
|
|
+ title: '用户信息过期',
|
|
|
+ content: '请重新登录',
|
|
|
+ okCancel: false,
|
|
|
+ closable: false,
|
|
|
+ okButtonProps: {
|
|
|
+ onClick: () => router.replace('/login')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
// 接口请求错误,统一提示错误信息
|
|
|
if (code === ResultEnum.ERROR) {
|
|
|
if (message) {
|
|
@@ -147,6 +163,9 @@ const transform: AxiosTransform = {
|
|
|
requestInterceptors: config => {
|
|
|
// 请求之前处理config
|
|
|
const token = getToken()
|
|
|
+ // if (config.method?.toUpperCase() === 'POST' && !token) {
|
|
|
+ // router.replace('/login')
|
|
|
+ // }
|
|
|
if (token) {
|
|
|
// jwt token
|
|
|
// config.headers.Authorization = token
|