小程序分享功能开发

wxml:

<view class="col-class zan-col zan-col-8"><button open-type='share' data-title="{{articleinfo.title}}" data-id="{{articleinfo.article_id}}" data-share="{{articleinfo.share}}"><image src="../../resource/images/share.png" style="width:25px;height:20px;"></image> {{articleinfo.share}}</button></view>

onShareAppMessage: function (res) {

var that = this,title='',id='',flag=0,share=0;

console.log(res);

//button按钮分享

if (res.from === 'button') {

title = res.target.dataset.title;

id = res.target.dataset.id;

share = parseInt(res.target.dataset.share)+1 ;

flag = 1;

} else {

//右上角分享

title = "优睿科技";

}

// 分享到群聊

wx.showShareMenu({

withShareTicket: true

})

return {

title:title,

complete:function(res){

if (res.errMsg == 'shareAppMessage:ok') {

// 分享成功

wx.showToast({

title: '分享成功',

})

if(flag==1){

app.util.request({

url: "entry/wxapp/share",

data: { article_id: id },

success: function (res) {

that.setData({

'articleinfo.share': share

})

}

})

}

}else{

wx.showToast({

title: '分享失败',

})

}

}

}

},

猜你喜欢

转载自blog.csdn.net/qq_36926807/article/details/82840689