一、request封装
request(url, data, successCallBack = function(data) {}, completeCallBack = function(data) {}, method = "GET", header = { 'content-type': 'application/json' }, dataType = 'json', responseType = 'text') { wx.request({ url: url, data: data, header: header, method: method, dataType: dataType, responseType: responseType, success: function(res) { successCallBack(res.data); }, fail: function(res) {}, complete: function(res) { completeCallBack(res) }, }) }
二、showModal封装
tipsModal(content, successCallback = function() {}, title = '提示', showCancel = false, comfirmText = '知道了', confirmColor = '#03a9f4', hasCancel = false, cancelText = '取消', cancelColor = '#000') { var params = { title: title, content: content, showCancel: showCancel, confirmText: comfirmText, confirmColor: confirmColor, success: function(res) { if (res.confirm) { successCallback(); } } } if (hasCancel == true) { params.cancelText = cancelText; params.cancelColor = cancelColor; } wx.showModal(params); }