
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://m.tnblog.net/"+usernames+"/article/details/"+aticleid;//链接URL
- msg.title = $("body").find(".aticleTitle").html();//分享链接的标题
- msg.content = aticleContent.substring(0,100);//这是再要内容
- //msg.thumbs是缩略图
- msg.thumbs = ["https://gss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/86d6277f9e2f0708cf4e3d7ee624b899a901f201.jpg"];
- share.send(msg, function() {
- console.log("分享到\"" + share.description + "\"成功! ");
- }, function(e) {
- console.log("分享到\"" + share.description + "\"失败: " + e.code + " - " + e.message);
- });
- }
评价
排名
104
文章
2
粉丝
9
评论
1
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术