let ajaxTimes = 0
export const http = params => {
ajaxTimes++;
uni.showLoading({
title: "加载中",
mask: true,
});
return new Promise((resolve, reject) => {
const baseUrl = 'url'
const token = uni.getStorageSync('j_token')
const username = uni.getStorageSync('j_username')
uni.request({
data: {
token,
username,
...params.data
},
header: {'Content-type': 'application/x-www-form-urlencoded'},
method: 'POST',
url: baseUrl + params.url,
success: res => {
resolve(res.data)
},
fail: err => {
reject(err)
},
complete: (response) => {
console.log("response",response)
ajaxTimes--
if (ajaxTimes === 0) {
uni.hideLoading();
}
// 登录过期
if (response.data.code == -9) {//后台返回的
uni.clearStorageSync()
uni.showModal({
title: '未登录',
content: '您未登录,需要登录后才能继续',
success: res => {
console.log(res);
if (res.confirm) {
uni.navigateTo({
url: '../login/login'
})
}
}
})
}
}
})
})
}