统一提示信息
/** * 统一提示信息 * @author langjf */ paiAlert: function (title, confirmToUrl, cancelToUrl){ wx.showModal({ title: '温馨提示', content: title, success(res) { if (res.confirm) { console.log('用户点击确定') wx.navigateTo({ url: confirmToUrl }) } else if (res.cancel) { // console.log('用户点击取消'); wx.navigateTo({ url: cancelToUrl }) } } }) },
请求逻辑处理
/** * 请求逻辑处理 * @author langjf */ myfund:function(){ var that = this; //检查登陆 var data={}; that.paiRequest('/aa/aa/aa.do', data).then(function (res) { console.log("ajax"+res); if (res.success == true) { data["buyerId"] = res.obj.userid; that.paiRequest('/aa/aa/aa.do', data).then(function (res) { if (res.status == "1") { that.paiRequest('/aa/aa/aa.do', data).then(function (res) { if (res.success = true) { that.setData({ webankurl: res.content }) } else { that.paiAlert(res.message, "/pages/my/my", "/pages/my/my"); } }); } else { that.paiAlert("您还未开通微众,去pc端开通微众", "/pages/my/my", "/pages/my/my"); } }); }else{ that.paiAlert("未登录,是否马上去登录?", "/pages/login/login", "/pages/my/my"); } }); },
统一封装wx.request 调用微信已集成 Promise 方法
/** * 统一封装wx.request 调用微信已集成 Promise 方法 * @author langjf */ paiRequest:function(requrl,data){ return new Promise(function (resolve, reject) { var resstr=""; wx.showLoading({ "mask": true }); data["token"] = wx.getStorageSync('token'); wx.request({ url: app.globalData.baseurl + requrl, data: data, async: false, method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT header: { 'content-type': 'application/x-www-form-urlencoded' // 默认值 }, success: function (res) { resolve(res.data); wx.hideLoading(); }, }) }) },
原文地址:https://developer.aliyun.com/article/786634
标签:aa,function,微信,request,data,Promise,res,my,wx From: https://www.cnblogs.com/nsw2018/p/16862991.html