微信小程序工具函数封装(2)

function requestLoading(url, params, message) { let promise = new Promise((resolve, reject) => { wx.showNavigationBarLoading() if (message != "") { wx.showLoading({ title: message }) } var timestamp = Date.parse(new Date()); timestamp = timestamp / 1000; params['openid'] = wx.getStorageSync('openid'); var newParams = this.objKeySort(params); newParams['unionid'] = wx.getStorageSync('unionid'); newParams['antime'] = timestamp; newParams['key'] = this.jiamiParams(newParams); wx.request({ url: url, data: newParams, header: { 'content-type': 'application/x-www-form-urlencoded' }, method: 'post', success: function (res) { wx.hideNavigationBarLoading() if (message != "") { wx.hideLoading() } if (res.statusCode == 200) { resolve(res.data) } else { reject(res) } }, fail: function (res) { wx.hideNavigationBarLoading() if (message != "") { wx.hideLoading() } reject('网络出错!') } }) }) return promise }

使用方法:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/e286e4073f281cfdb12b424f1a88be18.html