小程序 header

 工作日志 随手笔记 仅供参考


/**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
    var that = this;
    if (wx.getStorageSync('auth_token')){
      that.gitauthtoken()
    }else{
      this.userInfoReadyCallback(this.gitauthtoken);
    }
  
    
  
  },
 封装好的函数 用来判断用户是否登录 获取auth_token 

userInfoReadyCallback: function (calback) {
    var that = this;
    //console.log(app.globalData.userInfo);
    util.login().then((res) => {
      //console.log("----------");
      return util.getUserAuthRequest('https://pmcore.mbcore.com/weapp/login', { code: res.code })
    }).then(function (res) {
      //如果needBind 是true 则需要本地缓存paramBind验证手机号时用
      console.log(res.data.result.needBind);
      if (res.data.result.needBind) {
        //为新用户,提示去绑定手机号页面
        var paramBind = wx.getStorageSync('paramBind') || '';
        paramBind = res.data.result.paramBind;
        wx.setStorageSync('paramBind', paramBind);
        wx.showModal({
          title: '提示',
          content: '您尚未登录,点击确定去往手机登录页面,点击取消将无法购买',
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '/pages/bindphone/bindphone'
              })
            } else if (res.cancel) {
              console.log("我点击了取消按钮");
              wx.switchTab({
                url: '/pages/index/index'
              })
            }
          }
        });
        // wx.navigateTo({
        //   url: '/pages/bindphone/bindphone'
        // })
      } else {
        //为老用户,可以正常登录,并本地存储auth_token
        var auth_token = wx.getStorageSync('auth_token') || '';
        auth_token = res.data.result.auth_token;
        wx.setStorageSync('auth_token', auth_token);
        //console.log(wx.getStorageSync('auth_token'));
        if (calback) {
          calback();
        }
      }
    })
  }
onShow: function () {
    var that = this;
    //用户拒绝微信位置请求
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userLocation']) {
          //用户没有授权位置信息
          that.setData({
            isAuthorizedLocation:false
          })
          wx.showModal({
            title: '提示',
            content: '查看附近的店需要您的地理位置',
            confirmText: '去开启',
            success: function (res) {
              if (res.confirm) {
                console.log('用户点击去开启')
                wx.openSetting()
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        }else{
          //用户授权了位置信息
          that.setData({
            isAuthorizedLocation: true
          })
        }
      }
    })
    // if (wx.getStorageSync('auth_token')) {
    

    // } else {
    
   
    //   this.userInfoReadyCallback(this.getLikeStatus);
    // }
    //this.changeClassify()
    
  },


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值