var apiUrl = 'https://xxx/'
var TenantToken=yyy
/**
* 异步调用接口
*/
function request(url, method, header, param, success) {
wx.request({
url: apiUrl + url,
method: method,
header: header,
data: param,
success: function (res) {
// console.log(res,"000")
if (res.header.token) {
wx.setStorageSync('token', res.header.token)
}
if (res.data.code == 1) {
success(res.data.data);
} else {
if (res.data.code == 401) {
wx.removeStorageSync('token')
wx.showModal({
title: '提示',
showCancel: false,
content: res.data.msg,
success(res) {
if (res.confirm) {
wx.switchTab({
url: '/pages/me/me',//如果token失效了就跳到登录页
})
}
}
});
} else {
//弹出错误提示
wx.showModal({
showCancel: false,
content: res.data.msg
});
}
wx.hideLoading();
}
},
fail: function (errMsg) {
// console.log(errMsg,"1111111111111")
//隐藏-加载中
wx.hideLoading();
//隐藏-加载中
wx.hideNavigationBarLoading();
//停止当前页面下拉刷新
wx.stopPullDownRefresh();
//错误提示
// wx.showModal({
// showCancel: false,
// content: res.msg
// });
}
});
}
//导出
module.exports = {
request: request,
apiUrl: apiUrl,
}
调用的时候
//get
util.request('xxx?aaa=bbb', 'GET', {}, {},
function (res) {
console.log(res)
})
//post
let param = {}
util.request('vvv', 'POST', {}, param,
function (res) {
})