var app=getApp(); function request(url, method,header, data, success) { let promise = new Promise(function(resolve, reject) { wx.request({ url, header, data, method, success: res => { if (typeof res.data === "object") { if(!!res.header.Authorization){ app.globalData.token=res.header.Authorization.split(" ")[1]; } if(!!res.data.token){ app.globalData.token=res.data.token; } if (res.data.code === 403) { wx.reLaunch({ url: '/pages/index/index', }) reject(res.data.msg); }else if(res.data.code === 601){ wx.reLaunch({ url: '/pages/other/other?type=32', }) reject(res.data.msg); }else if(res.data.code != 0&&!data.alertshow&&res.data.code!=undefined) { wx.showToast({ title: res.data.msg, icon: "none", duration: 2000 }); reject(res.data.msg); } } success(res) }, fail: res => { reject(res) }, complete: res => { // wx.hideLoading() } }) }) return promise } let fn = function() {} module.exports = { $get: function({ url, header, data = {}, success = fn }) { data.client_type = app.globalData.clientype; return request(url, 'GET',header, data, success) }, $post: function({ url, header, data = {}, success = fn }) { data.client_type = app.globalData.clientype; return request(url, 'POST',header, data, success) } }