37 lines
991 B
JavaScript
37 lines
991 B
JavaScript
axios.defaults.baseURL = BASE_PATH;
|
|
axios.defaults.headers.post['Content-Type'] = 'application/json';
|
|
axios.defaults.timeout = 120000;
|
|
|
|
// 添加请求拦截器
|
|
axios.interceptors.request.use(function (config) {
|
|
var token = localStorage.getItem("user_token");
|
|
config.headers.Authorization = token;
|
|
return config;
|
|
}, function (error) {
|
|
return Promise.reject(error);
|
|
});
|
|
|
|
// 添加响应拦截器
|
|
axios.interceptors.response.use(function (response) {
|
|
try {
|
|
plus.nativeUI.closeWaiting();
|
|
}catch(e){
|
|
|
|
}
|
|
return response;
|
|
}, function (error) {
|
|
try {
|
|
if(error=="Error: Network Error" || error.toString().indexOf('timeout') > -1){
|
|
if(plus.webview.getWebviewById('error.html')==null){
|
|
clicked('error.html',true,false,{},{},function(){
|
|
window.location.reload();
|
|
})
|
|
}else{
|
|
$(".loadingBg").hide();
|
|
plus.nativeUI.closeWaiting();
|
|
plus.webview.getWebviewById("error.html").show();
|
|
}
|
|
}
|
|
}catch(e){}
|
|
return Promise.reject(error);
|
|
}); |