Hbuilder packaged Vue app sharing project realization

<script type="text/javascript">

  was AUTHS =  null ;

  // 监听plusready事件  

  document.addEventListener("plusready", function() {

  // extension API is loaded, you can now properly call the extension API 

  plus.oauth.getServices ( function (Services) {

  auths = services;

  }, function(e) {

  Alert ( " get-sharing service list failed: "  + e.message +  " - "  + e.code);

  });

  // sharing 
  var the Intent =  null ,
      File = null,
      Uri =  null ,
      main =  null ;
   var shares =  null ;
   var shareImageUrl =  '' ;
   // updateSerivces plus.share with the above method do not know if plus.oauth overlap, or added in case 
  updateSerivces ();
   IF (PLUS .os.name ==  " the Android " ) {
    Intent = plus.android.importClass("android.content.Intent");
    File = plus.android.importClass("java.io.File");
    Uri = plus.android.importClass("android.net.Uri");
    main = plus.android.runtimeMainActivity();
  }

  }, false);

  function updateSerivces() {
    plus.share.getServices(function(s) {
      shares = {};
      for (var i in s) {
        var t = s[i];
        shares[t.id] = t;
      }
      Alert ( " get the list of successful sharing service " );
    }, function(e) {
      Alert ( " get-sharing service list failed: "  + e.message);
    });
    }

 </script>

All interfaces have to get APi function called after plusready event

After calling the API in the index.html header, the need to share the page by clicking on the event call the share method

// micro-channel sharing
share () {
  was IDS = [{
            id: "weixin", 
            ex: "WXSceneSession" / * * micro-letter friends /
        }, {
            id: "weixin",
            ex: "WXSceneTimeline" / * * micro-channel circle of friends /
        }, {
            id: "qq" / * QQ friends * /
        }, {
            id: "tencentweibo" / * Tencent microblogging * /
        },{
            id: "sinaweibo" / * * Sina Weibo /
        }],
        bts = [{
            title: "micro-letter to a friend"
        }, {
            title: "micro-channel circle of friends to share."
        }, {
            title: "Share the QQ"
        }, {
            title: "Share to Tencent microblogging"
        }, {
            title: "Share Xinlang"
        }];
    plus.nativeUI.actionSheet({
            cancel: "Cancel"
            buttons: bts
        },function(e) {
            var i = e.index;
            alert('i:' + i)
            if (i > 0) {
                // this.shareAction(ids[i - 1].id, ids[i - 1].ex);
                var id = ids[i - 1].id;
                var ex = ids[i - 1].ex
                was p = zero;
                alert('ex:'+ex)
                if (!id || !(s = shares[id])) {
                    alert ( "Invalid sharing service!");
                    return;
                }
                if (s.authenticated) {
                    alert ( "--- --- authorized");
                    msg = {
                      content: 'Share - Details'
                      href: 'http://front.llldou.cn/home',
                      title: 'ji simple steps take you become chicken industry predators, easy monthly income 30w',
                      content: 'you are not a local tyrant, do the task to change the egg, save enough eggs, exchange benefits, in addition to the old iron you, I do not tell anyone! '
                      thumbs: ['http://img3.3lian.com/2013/v10/4/87.jpg'],
                      pictures: ['http://img3.3lian.com/2013/v10/4/87.jpg'],
                      extra: {
                        scene: ex
                      }
                    };
                    s.send(msg, function() {
                        alert ( "Share success!");
                    }, function(e) {
                        alert ( "Sharing Failed!");
                    });
                } else {
                    alert ( "--- --- Unauthorized");
                    s.authorize(function() {
                      msg = {
                          content: 'Share - Details'
                          href: 'http://front.llldou.cn/home',
                          title: 'ji simple steps take you become chicken industry predators, easy monthly income 30w',
                          content: 'you are not a local tyrant, do the task to change the egg, save enough eggs, exchange benefits, in addition to the old iron you, I do not tell anyone! '
                          thumbs: ['http://img3.3lian.com/2013/v10/4/87.jpg'],
                          pictures: ['http://img3.3lian.com/2013/v10/4/87.jpg'],
                          extra: {
                            scene: ex
                         }
                      };
                      s.send(msg, function() {
                          alert ( "Share success!");
                      }, function(e) {
                          alert ( "Sharing Failed!");
                      });
                    }, function(e) {
                        alert ( "Authentication Authorization failed");
                    });
                }
            }
        }
    );
}

After plus.share micro-channel messages and circle of friends SDK configuration Hbuilder manifest.json file in the check and fill appid and appsecret, add the Share permissions in the module configuration (share) module, can be packaged

Probably recording function, the code needs to be improved

Guess you like

Origin www.cnblogs.com/Strangers/p/11924556.html