//app.js
App({
 post(url, data) {
  /** 
   * 自定义post函数,返回Promise
   * +-------------------
   * @param {String}      url 接口网址
   * @param {arrayObject} data 要传的数组对象 like: {name: 'name', age: 32}
   * +-------------------
   * @return {Promise}    promise 返回promise供后续操作
   */
  wx.showNavigationBarLoading()
  wx.showLoading({
   title: '加载中',
  })
  var promise = new Promise((resolve, reject) => {
   let that = this;
   let postData = data;
   // let baseurl = 'http://ewords.w.bronet.cn/portal/';//仅为测试地址
   let baseurl = 'https://smallpro.igmat.cn/portal/'
   //发起网络请求
   wx.request({
    url: baseurl + url,
    data: postData,
    method: 'POST',
    header: {
     'content-type': 'application/x-www-form-urlencoded'
    },
    success: function(res) { 
     //返回取得的数据
     if (res.data.code == 1) {
      resolve(res);
      setTimeout(function() {
       wx.hideLoading()
      }, 600)
      wx.hideNavigationBarLoading()
     } else if (res.data.code == '40000') {
      wx.showModal({
       title: '提示',
       content: '登陆超时,请重新登陆',
       showCancel: false,
       success: function(res) {
        if (res.confirm) {
         wx.navigateTo({
          url: '/pages/star/star',
         })
        }
       }
      })
     }
    },
    error: function(e) {
     reject("网络错误");
     wx.hideLoading();
     wx.hideNavigationBarLoading();
     wx.showModal({
      title: '提示',
      content: res.data.msg,
      showCancel: false
     })
    }
   })
  })
  wx.hideLoading();
  return promise;
 },

 globalData: {
  userInfo: null,
 }
})