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 }
使用方法: