|
|
@ -1,32 +1,35 @@
|
|
|
|
import axios from 'axios'
|
|
|
|
import axios from 'axios'
|
|
|
|
import vm from "../main";
|
|
|
|
import vm from '../main'
|
|
|
|
import { getToken } from '@/utils/auth'
|
|
|
|
import { getToken } from '@/utils/auth'
|
|
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
|
|
const request = axios.create({
|
|
|
|
const request = axios.create({
|
|
|
|
baseURL: 'http://50.146.63.43:1129/hjapi',
|
|
|
|
// baseURL: 'http://50.146.63.43:1129/hjapi',
|
|
|
|
//baseURL: 'http://121.41.91.94:12002/hjapi',
|
|
|
|
baseURL: 'http://121.41.91.94:12002/hjapi',
|
|
|
|
//baseURL: `http://${window.location.host}/hjapi`,
|
|
|
|
//baseURL: `http://${window.location.host}/hjapi`,
|
|
|
|
timeout: 50000,
|
|
|
|
timeout: 50000,
|
|
|
|
headers: { 'content-type': 'application/json' },
|
|
|
|
headers: { 'content-type': 'application/json' }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// request拦截器
|
|
|
|
// request拦截器
|
|
|
|
request.interceptors.request.use(config => {
|
|
|
|
request.interceptors.request.use(
|
|
|
|
// 是否需要设置 token
|
|
|
|
(config) => {
|
|
|
|
const isToken = (config.headers || {}).isToken === false
|
|
|
|
// 是否需要设置 token
|
|
|
|
// 是否需要防止数据重复提交
|
|
|
|
const isToken = (config.headers || {}).isToken === false
|
|
|
|
if (getToken() && !isToken) {
|
|
|
|
// 是否需要防止数据重复提交
|
|
|
|
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
|
|
if (getToken() && !isToken) {
|
|
|
|
|
|
|
|
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//防止重复提交
|
|
|
|
|
|
|
|
return config
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
(error) => {
|
|
|
|
|
|
|
|
console.log(error)
|
|
|
|
|
|
|
|
Promise.reject(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//防止重复提交
|
|
|
|
)
|
|
|
|
return config
|
|
|
|
|
|
|
|
}, error => {
|
|
|
|
|
|
|
|
console.log(error)
|
|
|
|
|
|
|
|
Promise.reject(error)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
// response 拦截器
|
|
|
|
// response 拦截器
|
|
|
|
// 可以在接口响应后统一处理结果
|
|
|
|
// 可以在接口响应后统一处理结果
|
|
|
|
request.interceptors.response.use(
|
|
|
|
request.interceptors.response.use(
|
|
|
|
response => {
|
|
|
|
(response) => {
|
|
|
|
if (response.data) {
|
|
|
|
if (response.data) {
|
|
|
|
switch (response.data.code) {
|
|
|
|
switch (response.data.code) {
|
|
|
|
case 200:
|
|
|
|
case 200:
|
|
|
@ -36,7 +39,9 @@ request.interceptors.response.use(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 兼容服务端返回的字符串数据
|
|
|
|
// 兼容服务端返回的字符串数据
|
|
|
|
if (typeof response.data === 'string') {
|
|
|
|
if (typeof response.data === 'string') {
|
|
|
|
response.data = response.data ? JSON.parse(response.data) : response.data
|
|
|
|
response.data = response.data
|
|
|
|
|
|
|
|
? JSON.parse(response.data)
|
|
|
|
|
|
|
|
: response.data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return response.data
|
|
|
|
return response.data
|
|
|
|
|
|
|
|
|
|
|
@ -66,17 +71,14 @@ request.interceptors.response.use(
|
|
|
|
duration: 3
|
|
|
|
duration: 3
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return response.data
|
|
|
|
return response.data
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
(error) => {
|
|
|
|
console.log('err' + error) // for debug
|
|
|
|
console.log('err' + error) // for debug
|
|
|
|
|
|
|
|
|
|
|
|
return Promise.reject(error)
|
|
|
|
return Promise.reject(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
export default request
|
|
|
|
export default request
|
|
|
|