第一步:创建request.js
const Promise = require('es6-promise').Promise
const util = require('./util.js');
const utils = util.default.util.prototype;
//签名参数 这个两个参数是后台给的
const key = 'cdbbf90ec69b7f9df6ff301e58bbff1b';
const secret = 'e2f3efdd889e1bab39c981ad46993fda';
function wxPromisify(fn) {
return function(obj = {}) {
return new Promise((resolve, reject) => {
obj.success = function(res) {
//成功 (只返回res.data)
resolve(res.data)
setTimeout(function(){
wx.hideLoading();
},200)
}
obj.fail = function(res) {
//失败
reject(res)
setTimeout(function(){
wx.hideLoading();
},200)
}
fn(obj)
})
}
}
//无论promise对象最后状态如何都会执行
Promise.prototype.finally = function(callback) {
let P = this.constructor;
return this.then(
value => P.resolve(callback()).then(() => value),
reason => P.resolve(callback()).then((