(一)
上面是分享页面代码,用变量存储需要跳转的页面路径。
分享路径直接跳转到登录页,将需要跳转的路径以参数形式带到登录页,注意需要用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,
})
}
}
},
页面分享测试,要记得及时清除手机本地的开发版本,因为分享的页面,代码不会自动更新,需要新扫码更新手机开发版本。