diff --git a/public/static/res/mods/index.js b/public/static/res/mods/index.js index 60e2ddc..1c30b65 100644 --- a/public/static/res/mods/index.js +++ b/public/static/res/mods/index.js @@ -859,6 +859,22 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util'], function( if(type === 'bar1'){ //slayer.msg('打开 index.js,开启发表新帖的路径'); location.href = articleAdd; + } + //分享 + if(type === 'bar2'){ + if(navigator.userAgent.indexOf("Html5Plus") > -1) { + //5+ 原生分享 + window.plusShare({ + title: "my-app-name",//应用名字 + content: "分享具体内容", + href: location.href,//分享出去后,点击跳转地址 + thumbs: ["/static/share/icon/wx.png"] //分享缩略图 + }, function(result) { + //分享回调 + }); + } else { + //原有wap分享实现 + } } } }); diff --git a/public/static/share/icon/wx.png b/public/static/share/icon/wx.png new file mode 100644 index 0000000..84abbf8 Binary files /dev/null and b/public/static/share/icon/wx.png differ diff --git a/public/static/share/plusShare.js b/public/static/share/plusShare.js new file mode 100644 index 0000000..5f94794 --- /dev/null +++ b/public/static/share/plusShare.js @@ -0,0 +1,117 @@ +(function() { + var plusReady = function(callback) { + if(window.plus) { + callback(); + } else { + document.addEventListener('plusready', callback); + } + } + var shareServices = {}; + var init = function() { + plus.share.getServices(function(services) { + for(var i = 0, len = services.length; i < len; i++) { + shareServices[services[i].id] = services[i]; + } + }); + }; + var isWechatInstalled = function() { + return plus.runtime.isApplicationExist && plus.runtime.isApplicationExist({ + pname: 'com.tencent.mm', + action: 'weixin://' + }); + }; + + function share(id, msg, callback) { + var service = shareServices[id]; + if(!service) { + callback && callback(false); + return; + } + var _share = function() { + service.send(msg, function() { + plus.nativeUI.toast("分享到\"" + service.description + "\"成功!"); + callback && callback(true); + }, function(e) { + plus.nativeUI.toast("分享到\"" + service.description + "\"失败!"); + callback && callback(false); + }) + }; + if(service.authenticated) { + _share(service, msg, callback); + } else { + service.authorize(function() { + _share(service, msg, callback); + }, function(e) { + console.log("认证授权失败"); + callback && callback(false); + }) + } + }; + + function openSystem(msg, callback) { + if(plus.share.sendWithSystem) { + plus.share.sendWithSystem(msg, function() { + //TODO 系统分享暂不支持回调 + //callback && callback(true); + }, function() { + //TODO 系统分享暂不支持回调 + //callback && callback(false); + }); + } else { + callback && callback(false); + } + } + var open = function(msg, callback) { + /** + *如下情况直接打开系统分享 + * 1、未配置微信分享通道 + * 2、用户手机未安装威胁你 + * 3、360浏览器下 + */ + + if(shareServices.weixin && isWechatInstalled() && !/360\sAphone/.test(navigator.userAgent)) { + plus.nativeUI.actionSheet({ + title: '分享到', + cancel: "取消", + buttons: [{ + title: "微信消息" + }, { + title: "微信朋友圈" + }, { + title: "更多分享" + }] + }, function(e) { + var index = e.index; + switch(index) { + case 1: //分享到微信好友 + msg.extra = { + scene: 'WXSceneSession' + }; + share('weixin', msg, callback); + break; + case 2: //分享到微信朋友圈 + msg.title = msg.content; + msg.extra = { + scene: 'WXSceneTimeline' + }; + share('weixin', msg, callback); + break; + case 3: //更多分享 + var url = msg.href ? ('( ' + msg.href + ' )') : ''; + msg.title = msg.title + url; + msg.content = msg.content + url; + openSystem(msg, callback); + break; + } + }) + } else { + //系统分享 + var url = msg.href ? ('( ' + msg.href + ' )') : ''; + msg.title = msg.title + url; + msg.content = msg.content + url; + openSystem(msg, callback); + } + }; + plusReady(init); + window.plusShare = open; +})(); \ No newline at end of file diff --git a/view/taoler/index/public/base.html b/view/taoler/index/public/base.html index b10981a..55e585b 100644 --- a/view/taoler/index/public/base.html +++ b/view/taoler/index/public/base.html @@ -6,10 +6,22 @@ - + + + + {include file="public/header" /} {block name="column"}导航{/block} {block name="content"}内容{/block} diff --git a/view/taoler/index/public/flink.html b/view/taoler/index/public/flink.html index 8ab4d83..14f70f6 100644 --- a/view/taoler/index/public/flink.html +++ b/view/taoler/index/public/flink.html @@ -1,4 +1,4 @@ -