|
@@ -1,13 +1,13 @@
|
|
|
import axios from 'axios'
|
|
|
+import history from './history'
|
|
|
+import { getTokenInfo, removeTokenInfo } from './storage'
|
|
|
import { MessageFu } from './message'
|
|
|
-import { Toast } from 'antd-mobile'
|
|
|
import { domShowFu } from './domShow'
|
|
|
-import { isMobileFu } from './history'
|
|
|
|
|
|
const envFlag = process.env.NODE_ENV === 'development'
|
|
|
|
|
|
-const baseUrlTemp = 'https://sit-zhongliuyiyuan.4dage.com' // 测试环境
|
|
|
-// const baseUrlTemp = 'http://192.168.20.13:8079' // 线下环境
|
|
|
+const baseUrlTemp = 'https://sit-liushaoqibwg.4dage.com' // 测试环境
|
|
|
+// const baseUrlTemp = 'http://192.168.20.61:8072' // 线下环境
|
|
|
|
|
|
const baseFlag = baseUrlTemp.includes('https://')
|
|
|
|
|
@@ -18,6 +18,7 @@ export const baseURL = envFlag ? `${baseUrlTemp}${baseFlag ? '' : '/api/'}` : ''
|
|
|
declare module 'axios' {
|
|
|
interface AxiosResponse {
|
|
|
code: number
|
|
|
+ timestamp: string
|
|
|
// 这里追加你的参数
|
|
|
}
|
|
|
}
|
|
@@ -37,6 +38,9 @@ http.interceptors.request.use(
|
|
|
domShowFu('#AsyncSpinLoding', true)
|
|
|
|
|
|
axajInd++
|
|
|
+
|
|
|
+ const { token } = getTokenInfo()
|
|
|
+ if (token) config.headers.token = token
|
|
|
return config
|
|
|
},
|
|
|
function (err) {
|
|
@@ -54,16 +58,16 @@ http.interceptors.response.use(
|
|
|
if (axajInd === 0) {
|
|
|
domShowFu('#AsyncSpinLoding', false)
|
|
|
}
|
|
|
- if (response.data.code === 0) {
|
|
|
+ if (response.data.code === 5001 || response.data.code === 5002) {
|
|
|
+ removeTokenInfo()
|
|
|
+ history.push('/login')
|
|
|
+ clearTimeout(timeId)
|
|
|
+ timeId = window.setTimeout(() => {
|
|
|
+ MessageFu.warning('登录失效!')
|
|
|
+ }, 200)
|
|
|
+ } else if (response.data.code === 0) {
|
|
|
// MessageFu.success(response.data.msg);
|
|
|
- } else {
|
|
|
- isMobileFu() && response.data.msg
|
|
|
- ? Toast.show({
|
|
|
- icon: 'fail',
|
|
|
- content: response.data.msg
|
|
|
- })
|
|
|
- : MessageFu.warning(response.data.msg)
|
|
|
- }
|
|
|
+ } else if (response.data.code !== 3014) MessageFu.warning(response.data.msg)
|
|
|
|
|
|
return response.data
|
|
|
},
|
|
@@ -73,20 +77,21 @@ http.interceptors.response.use(
|
|
|
axajInd = 0
|
|
|
domShowFu('#AsyncSpinLoding', false)
|
|
|
// 如果因为网络原因,response没有,给提示消息
|
|
|
- if (!err.response) {
|
|
|
- isMobileFu()
|
|
|
- ? Toast.show({
|
|
|
- icon: 'fail',
|
|
|
- content: '网络繁忙,请稍后重试!'
|
|
|
- })
|
|
|
- : MessageFu.error('网络繁忙,请稍后重试!')
|
|
|
- } else {
|
|
|
- isMobileFu()
|
|
|
- ? Toast.show({
|
|
|
- icon: 'fail',
|
|
|
- content: '响应错误,请联系管理员!'
|
|
|
- })
|
|
|
- : MessageFu.error('响应错误,请联系管理员!')
|
|
|
+ if (!err.response) MessageFu.error('网络繁忙,请稍后重试!')
|
|
|
+ else {
|
|
|
+ if (
|
|
|
+ err.response &&
|
|
|
+ err.response.data &&
|
|
|
+ err.response.data.msg &&
|
|
|
+ err.response.data.msg.length < 30
|
|
|
+ ) {
|
|
|
+ MessageFu.error(err.response.data.msg)
|
|
|
+ // 没有权限
|
|
|
+ if (err.response.data.code === 5003) {
|
|
|
+ removeTokenInfo()
|
|
|
+ history.push('/login')
|
|
|
+ }
|
|
|
+ } else MessageFu.error('响应错误,请联系管理员!')
|
|
|
}
|
|
|
}, 100)
|
|
|
|