按钮分享(传参,确定取消分享按钮监听)
直接上代码:
wxml页面
<button id='btn' open-type='share' plain='true'>分享按钮</button>
js页面代码
onShareAppMessage: function(res) {
var time = Date.parse(new Date());
console.log(time)
console.log(this.data.openid)
console.log(this.data.name)
var openidd = this.data.openid;
var username = this.data.name;
if (res.from === 'button') {
// 来自页面内转发按钮
console.log(res.target.id)
console.log(res.from)
//区分按钮分享
if (res.target.id === "btn") {
return {
title: '按钮分享',
path: `zh_vip/pages/my/glrk/helpQRcode?user_id=` + this.data.userid,//分享页面传参数
success: function(res) {
// 转发成功
// 助力时间开始 (openid,当前时间,真实姓名)
app.util.request({
url: "entry/wxapp/GetstartTime",
cachetime: "0",
data: {
openid: openidd,
name: username,
time: time
},
success(res) { }
})
},
fail: function(res) {
// 转发失败
}
}
}
}
//系统右上角胶囊...分享
return {
title: '标题',
path: `zh_vip/pages/my/glrk/helpQRcode?user_id=` + this.data.userid,,//分享页面传参数
imageUrl: ``,
success: function(res) {
// 转发成功
console.log("转发成功:" + JSON.stringify(res));
// 助力时间开始 (openid,当前时间,真实姓名)
app.util.request({//自己封装的接口请求方法
url: "",
cachetime: "0",
data: {
openid:this.data.openid,
name: this.data.name,
time:time
},
success(res) {
// 助力时间开始 (openid,当前时间,真实姓名)
app.util.request({//自己封装的接口请求方法
url: "",
cachetime: "0",
data: {
openid: this.data.openidd,
name: this.data.username,
time: time
},
success(res) { }
})
}
})
},
fail: function(res) {
// 转发失败
console.log("转发失败:" + JSON.stringify(res));
}
}
},