global.http ={
timer:null,
beenLoginPage:false,
post: (url, data, loading)=>{if(loading) {
uni.showLoading({
mask:true})
}return new Promise((resolve, reject) =>{
uni.request({
url: BaseUrl+url,
method:"POST",
header: {
sessid: getSessid()
},
data,
success: res=>{if(loading) {
uni.hideLoading();
}if (res.data.code === 300) {
$Toast('登录过期,请重新登录!');
removeItem('sessid');if (http.beenLoginPage) return;if (http.timer != null) {
clearTimeout(http.timer);
};
http.timer=setTimeout(function() {
http.timer= null;
uni.reLaunch({
url:'/pages/login/login'})
http.beenLoginPage= true;
setTimeout(()=>{
http.beenLoginPage= false;
},600000)
},1500);return;
}if (res.statusCode != 200 || res.data.code != 200) {
uni.showToast({
title: res.data.msg|| '网络异常',
duration:1500,
icon:"none"})return;
}
resolve(res);
},
fail(err) {if(loading) {
uni.hideLoading();
}
$Toast('网络异常!');
reject(err);
}
})
})
},
all: (promise)=>{returnPromise.all(promise);
},
spread: function(callback) {returnfunction wrap(arr) {callback.apply(null, arr);
};
}
}