微信小程序 分享页面做登录拦截采坑记录

(一)

上面是分享页面代码,用变量存储需要跳转的页面路径。

分享路径直接跳转到登录页,将需要跳转的路径以参数形式带到登录页,注意需要用encodeURLComponent()转义

 onShareAppMessage: function (ops) {
    let url = encodeURIComponent('../StatisticalEle/StatisticalEle? 
              id='+this.data.activeIndex);
    return {
        title: '数据分析报表', //转发的标题。当前小程序名称
        path: 'pages/login_dn/login_dn?url='+url,
        imageUrl: '',//自定义图片路径 支持PNG及JPG。显示图片长宽比是 5:4。
        success:function(res){
          wx.showToast({
            title: res+'成功',
            icon: 'none',
            duration:1000
          })
        }
    }
  },

 

(二)

在登录页面接收传过来的参数。并且通过decodeURLComponent()方法编译。并且将参数分割出来。

因为我跳转的tabbar页面 不能直接带参跳转,只能将页面参数存到app的全局变量里。

if(options.url){
      let url = decodeURIComponent(options.url)
      let theRequest ={};
      let str = url.split("?"); //以“?”分割url
        for(let i=0;i<str.length;i++){
          theRequest[str[i].split("=")[0]] = decodeURI(str[i].split("=")[1]);
        }
      app.globalData.showActionIndex = theRequest.id
      console.log(theRequest)
      this.setData({
        redirectURL:str[0]
      })
 }

(三)登录跳转

 if (res.data.success && _this.data.redirectURL) {
            wx.switchTab({
              url: _this.data.redirectURL
            })
    }
           

(四)展示页面处理,判断并设置相关数据。

onShow(){
    if(app.globalData.showActionIndex){
      console.log()
      if(app.globalData.showActionIndex == 2 ){
        // 分析报告页面
        this.setData({
          activeIndex:app.globalData.showActionIndex,
          scrollpage:false,
        })
      }else{
        this.setData({
          activeIndex:app.globalData.showActionIndex,
          scrollpage:true,
        })
      }
  }
  },

页面分享测试,要记得及时清除手机本地的开发版本,因为分享的页面,代码不会自动更新,需要新扫码更新手机开发版本。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值