You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.5 KiB
68 lines
1.5 KiB
![]()
3 years ago
|
import axios from 'axios'
|
||
|
import { MessageBox, Message } from 'element-ui'
|
||
|
import store from '@/store'
|
||
|
import { getToken, getStorage } from '@/utils/auth'
|
||
|
|
||
|
// create an axios instance
|
||
|
console.log(process.env.VUE_APP_URL)
|
||
|
const service = axios.create({
|
||
|
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
|
||
|
// timeout: 5000 // request timeout
|
||
|
headers:{'Content-Type':'application/x-www-form-urlencoded;'}
|
||
|
})
|
||
|
|
||
|
// request interceptor
|
||
|
service.interceptors.request.use(
|
||
|
config => {
|
||
|
config.params = {
|
||
|
...config.params,
|
||
|
_t: Date.parse(new Date()) / 1000
|
||
|
}
|
||
|
if (getStorage()) {
|
||
|
|
||
|
config.headers['token'] = getStorage()
|
||
|
}
|
||
|
return config
|
||
|
},
|
||
|
error => {
|
||
|
console.log(error) // for debug
|
||
|
return Promise.reject(error)
|
||
|
}
|
||
|
)
|
||
|
|
||
|
// response interceptor
|
||
|
service.interceptors.response.use(
|
||
|
|
||
|
response => {
|
||
|
const res = response.data
|
||
|
if(res.type !=undefined){
|
||
|
return res
|
||
|
}
|
||
|
|
||
|
if(res.contractNo !=undefined){
|
||
|
return res
|
||
|
}
|
||
|
// if the custom code is not 20000, it is judged as an error.
|
||
|
if (res.code != 200) {
|
||
|
if (res.msg == "请重新登录") {
|
||
|
// window.location.href = 'http://39.104.100.138:8082/'
|
||
|
} else {
|
||
|
alert(res.msg);
|
||
|
}
|
||
|
}
|
||
|
return res
|
||
|
},
|
||
|
error => {
|
||
|
console.log('err' + error) // for debug
|
||
|
Message({
|
||
|
message: error.message,
|
||
|
type: 'error',
|
||
|
duration: 5 * 1000
|
||
|
})
|
||
|
|
||
|
return Promise.reject(error)
|
||
|
}
|
||
|
)
|
||
|
|
||
|
export default service
|