module.exports = {
  toLogin() {
    return new Promise((resolve, reject) => {
      // 登录
      wx.login({
        success: res => {
          const app = getApp()
          const { code: js_code } = res
          // 发送 res.code 到后台换取 openId, sessionKey, unionId
          wx.request({
            url: `${app.globalData.publicUrl}/api/st/system/weixin/appAuth?js_code=` + js_code,
            method: "get",
            header: {
              'x-tenant': app.globalData.tenant
            },
            success: res => {
              const { errcode, data } = res.data
              if (errcode === 0) {
                app.globalData.wxInfo = data;
                wx.setStorage({ key: "userInfo", data: null })
                resolve(data);
              }
            },
            error: err => {
              wx.showToast({
                title: err.msg,
                icon: 'error'
              })
              reject('error');
            }
          })
        }
      })


    })
  }
}