http请求修改

This commit is contained in:
姚亚男
2021-10-19 14:59:13 +08:00
parent b399125d3a
commit 27a0dc96b1
10 changed files with 113 additions and 74 deletions
-24
View File
@@ -12,10 +12,6 @@ const http = (method, url, data, header= headerDefault) => {
let Authorization = wx.getStorageSync(TokenKey) ? wx.getStorageSync(TokenKey) : '';
header[TokenKey] = Authorization == '' ? '' : Authorization
return new Promise((resolve, reject) => {
wx.showLoading({
title: '加载中...',
mask: true
})
wx.request({
method: method,
url: baseUrl + url,
@@ -24,34 +20,14 @@ const http = (method, url, data, header= headerDefault) => {
success: res => {
wx.hideLoading();
if (res.statusCode === 200) {
// 接口请求错误的时候提示
if((res.data.code !== 200 && res.data.code !== 0) && (res.data.message)) {
wx.showToast({
title: res.data.message,
icon: "none",
duration: 800,
mask: true
});
}
// 200: 服务端业务处理正常结束
resolve(res.data)
} else {
reject(res.data);
wx.hideLoading();
// wx.showToast({
// title: "登录失效,请重新登录",
// icon: "none",
// duration: 1500,
// mask: true
// });
// wx.navigateTo({
// url: '/pages/login/login',
// })
console.error("登录失效3");
}
},
fail: err => {
console.error(err);
reject(err);
wx.hideLoading();
},