收藏
回答

wx.reLaunch或tabbar新手机首次进入小程序按钮无法跳转?

 点击按钮触发授权,然后跳转到Index

现在发现新手机就会出现无法跳转,老用户跳转正常

var app=getApp();

Page({


  /**

   * 页面的初始数据

   */

  data: {

    getnum:1,

    url:''

  },

  /**

   * 生命周期函数--监听页面加载

   */

  onLoad: function (options) {

    var that=this;

    wx.removeStorageSync('userInfo')

    // 请求图片的前缀地址

    app.util.request({

      url: 'entry/wxapp/ImgFrontSrc',

      data: {

        m: 'kuowan_wish',

      },

      cachetime: 30,

      success: function (res) {

        that.setData({

          url: res.data

        })

        let url = res.data;

      },

    })


    // 调出设备宽度

    wx.getSystemInfo({

      success: function(res) {

        //console.log(res.windowWidth);

        //rpx转换px比例

        var bili = (res.windowWidth/750).toFixed(3);

        that.setData({

          bili: bili,

          windowWidth: res.windowWidth

        })

      },

    })

    // 查看是否授权

    wx.getSetting({

      success(res) {

        var shouquan = res.authSetting['scope.userInfo'];

        wx.getStorage({

          key: 'phonenumberdata',

          success: function(res) {

            console.log(res.data);

            if (shouquan && res.data.encryptedData!=''{

              setTimeout(function(){

                wx.switchTab({

                  url: '../index/index'

                })

              }, 200)

            }

          },

        })

      }

    })

  },

  bindGetUserInfo(e) {

    var that = this;

    console.log(e.detail.userInfo);

    var userinfo = e.detail.userInfo;

    // 向服务器传递用户数据

    app.util.getUserInfo(function (userInfo) {

      console.log(userInfo)

      var userInfo=wx.getStorageSync('userInfo');

      that.setData({

        uid: userInfo.userinfo.uid

      })

      //app.globalData.uid = userInfo.userinfo.uid

      // 用户注册

      // 需要获取手机号

      if (that.data.getnum == 0{

        app.util.request({

          url: 'entry/wxapp/Register',

          data: {

            m: 'kuowan_wish',

            uid: userInfo.userinfo.uid,

            nickname: userInfo.wxInfo.nickName,

            avatar: userInfo.wxInfo.avatarUrl,

            gender: userInfo.wxInfo.gender,

            openid: userInfo.userinfo.openid,

            scene: scene?scene:0

          },

          success: function (res) {

            console.log(res.data)

            if (res.data.errno == 0{

              that.animation1.translate(500).step()

              that.setData({

                animationData: that.animation1.export(),

              })

              // 计算动画2不同设备移动距离

              var distance = parseInt(((that.data.windowWidth + that.data.bili * 300/ 2).toFixed(0));

              //console.log(typeof distance);

              that.animation2.translate(distance).step()

              that.setData({

                animationphone: that.animation2.export(),

              })

            }

          },

          fail: function (res) {

            console.log(res.data)

              wx.showToast({

                title: '注册失败请重试!',

                icon:'none'

              })

              wx.redirectTo({

                url: '../shouquan/shouquan',

              })

          }

        })

      }

      // 不需要手机号

      else if (that.data.getnum == 1{

        app.util.request({

          url: 'entry/wxapp/Register',

          data: {

            m: 'kuowan_wish',

            uid: userInfo.userinfo.uid,

            nickname: userInfo.wxInfo.nickName,

            avatar: userInfo.wxInfo.avatarUrl,

            gender: userInfo.wxInfo.gender,

            openid: userInfo.userinfo.openid

          },

          success: function (res) {

            console.log(res.data)

            if (res.data.errno == 0{

              setTimeout(function(){

                wx.reLaunch({

                  url: '../index/index'

                })

              }, 200)

            }

          },

          fail: function (res) {

            console.log(res.data)

              wx.showToast({

                title: '注册失败请重试!',

                icon: 'none'

              })

              wx.redirectTo({

                url: '../shouquan/shouquan',

              })

          }

        })

      }

      // 原动画位置

    })

  },

  


  /**

   * 生命周期函数--监听页面初次渲染完成

   */

  onReady: function () {

  },


  /**

   * 生命周期函数--监听页面显示

   */

  onShow: function () {

    const animation1 = wx.createAnimation({

      duration: 1000,

      timingFunction: 'ease-in-out',

    })


    this.animation1 = animation1

    const animation2 = wx.createAnimation({

      duration: 1000,

      timingFunction: 'ease-in-out',

      delay: 500

    })

    this.animation2 = animation2

  },


  /**

   * 生命周期函数--监听页面隐藏

   */

  onHide: function () {

  },


  /**

   * 生命周期函数--监听页面卸载

   */

  onUnload: function () {

  },


  /**

   * 页面相关事件处理函数--监听用户下拉动作

   */

  onPullDownRefresh: function () {


  },


  /**

   * 页面上拉触底事件的处理函数

   */

  onReachBottom: function () {


  },


  /**

   * 用户点击右上角分享

   */

  onShareAppMessage: function () {


  }

})


最后一次编辑于  02-22
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容
问题标签