一、request封装

 

request(url, data, successCallBack = function (data) {}, completeCallBack = function (data) {}, method = "GET", dataType = 'json', responseType = 'text') {
    var method = method.toLowerCase()
    if (method == 'get') {
      var header = {
        'content-type': 'application/json'
      }
    } else if (method == 'post') {
      var header = {
        'content-type': 'application/x-www-form-urlencoded'
      }
    }
    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);
}

 

相关文章:

  • 2022-02-17
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2022-01-10
  • 2022-12-23
  • 2022-02-16
猜你喜欢
  • 2021-12-18
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案