分类:
前端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); }); }
评价