startRecord.js 2.4 KB
// pages/startRecord/startRecord.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // hasToken: false
  },
  startrecord(){
    let url = '/user/getGravidaInfo';
    app.post(url,{}).then((res)=>{
      if(res.id){
        wx.switchTab({
          url: '/pages/weight/weight',
        })
      }else{
        wx.navigateTo({
          url: '/pages/baseInfo/baseInfo',
        })   
      }
    }).catch((errMsg)=>{
       
    })
  }, 
  getUserInfo(e) {
    let detail = e.detail ;
    let that = this ;
    wx.login({
      success: (res) => {
        // 获取code 
        let code = res.code;
        let codeurl = '/public/login';
        let params = {
          code: code,
          encrypted_data: detail.encryptedData,
          doctor_id:'',
          iv: detail.iv,
          raw_data: detail.rawData,
          signature: detail.signature,
          doctor_id: wx.getStorageSync('doctor_id')
        }
        console.log(params)
        wx.showLoading({
          title: '加载中', 
        })
        app.post(codeurl, params).then((res) => {
          //正确返回结果
          console.log(res) 
          wx.setStorageSync('token', res.token)
          this.setData({
            hasToken: true
          }) 
          wx.hideLoading()
          // 登陆后跳转
          that.startrecord()
        }).catch((errMsg) => {
          console.log(errMsg);//错误提示信息
        });
      }
    })
  }, 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let token = wx.getStorageSync('token')
    if (token != '' && token != null && typeof token != undefined) {
      this.setData({
        hasToken: true
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})