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.
 

55 lines
1.2 KiB

// 请求方法
/**
* url 请求地址
* data 请求数据
* header 带token的请求头
*/
const app = getApp();
export function request(url,data,header){
return new Promise((resolve,reject) => {
// console.log(data);
wx.request({
url: url,
data: data,
header: header,
method: 'POST',
dataType: 'json',
responseType: 'text',
success: (res) => {
// console.log(res);
if(res.statusCode == '401'){
wx.clearStorage();
const value = wx.getStorageSync('token');
console.log(value);
if (!value || value == null) {
wx.redirectTo({
url: "/pages/login"
})
} else {
app.getPower();
}
}else if(res.data.code == '500'){
wx.showToast({
title:'网络错误',
icon: 'none',
duration: 1000
})
}else if(res.data.code == '412'){
wx.showToast({
title:res.data.msg,
icon: 'none',
duration: 1000
})
}else{
resolve(res);
}
},
fail: (res) => {
},
})
})
}