tnblog
首页
视频
资源
登录

mui分享到朋友圈

2359人阅读 2019/11/25 12:55 总访问:4544 评论:3 收藏:9 手机
分类: 前端mui

mui分享操作

首先给点击事件一个id或者class标识 -->share


然后我们直接写js代码


//分享操作
var shares = {};
mui.plusReady(function() {
plus.share.getServices(function(s) {
if (s && s.length > 0) {
for (var i = 0; i < s.length; i++) {
var t = s[i];
shares[t.id] = t;
}
}
}, function() {
console.log("获取分享服务列表失败");
});
});
 //分享链接点击事件
mui("body").on("tap",".share",function(){
var ids = [{
id: "weixin",
ex: "WXSceneSession"
}, {
id: "weixin",
ex: "WXSceneTimeline"
}, {
id: "qq"
}],
bts = [{
title: "分享给微信好友"
}, {
title: "分享到朋友圈"
}, {
title: "分享到QQ好友"
}];
plus.nativeUI.actionSheet({
cancel: "取消",
buttons: bts
}, function(e) {
var i = e.index;
if (i > 0) {
var s_id = ids[i - 1].id;
var share = shares[s_id];
if (share.authenticated) {
shareMessage(share, ids[i - 1].ex);
} else {
share.authorize(function() {
shareMessage(share, ids[i - 1].ex);
}, function(e) {
console.log("认证授权失败:" + e.code + " - " + e.message);
});
}
}
});
});
function shareMessage(share, ex) {
var aticleContent=$("body").find(".aticleContent").text();
var msg = {
extra: {
scene: ex
}
};
msg.href = "http://www.xxxx/"+usernames+"/article/details/"+aticleid;//链接URL
msg.title = $("body").find(".aticleTitle").html();//分享链接的标题
msg.content = aticleContent.substring(0,100);//这是再要内容
//msg.thumbs是缩略图
msg.thumbs = ["https://gss0.baidu.co9a901f201.jpg"];
share.send(msg, function() {
console.log("分享到\"" + share.description + "\"成功! ");
}, function(e) {
console.log("分享到\"" + share.description + "\"失败: " + e.code + " - " + e.message);
});
}



评价
App修改之后的个性签名喔😲怎么样?哈哈
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术