-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshare.html
186 lines (170 loc) · 6.47 KB
/
share.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<script src="js/mui.min.js"></script>
<link href="css/mui.min.css" rel="stylesheet" />
<style type="text/css">
.mui-grid-9 {
background: white !important;
}
li {
border-left: none !important;
}
img {
width: 50px !important;
}
body {
background: transparent !important;
}
.mui-content {
background: white;
text-align: center;
}
</style>
</head>
<body onclick="closeShare();">
<div class="mui-content">
<img id="pic" src="img/add.png" style="display: none;" />
</div>
<footer style="position: absolute;bottom: 0px; width:100%;background: white;">
<div style="height: 30px; line-height: 30px ;font-family: '黑体'; margin-left:40%; ;margin-top: 50%;">分享本文</div>
<ul class="mui-table-view mui-grid-view mui-grid-9">
<li onclick="shareHref(1);" class="mui-table-view-cell mui-media mui-col-xs-4">
<img class="mui-media-object" src="images/share_to_icon_wx.png">
<div class="mui-media-body">微信</div>
</li>
<li onclick="shareHref(0);" class="mui-table-view-cell mui-media mui-col-xs-4">
<img class="mui-media-object" src="images/share_to_icon_wxq.png">
<div class="mui-media-body">朋友圈</div>
</li>
<li onclick="shareHref(2);" class="mui-table-view-cell mui-media mui-col-xs-4">
<img class="mui-media-object" src="images/share_to_icon_qq.png">
<div class="mui-media-body">QQ</div>
</li>
</ul>
</footer>
<input id="sharehref" style="display: none;" class="sharehref" type="url" value="www.baidu.com" placeholder="请输入要分享的链接地址" />
<input id="sharehrefTitle" style="display: none;" class="sharehref" type="text" value="加工详情" placeholder="请输入要分享的链接标题" />
<input id="sharehrefDes" style="display: none;" class="sharehref" type="text" value="我正在使用HBuilder+HTML5开发移动应用,赶紧跟我一起来体验!" placeholder="请输入要分享的链接描述" />
</body>
<script type="text/javascript" charset="utf-8">
var shares=null;
var Intent=null,File=null,Uri=null,main=null;
// H5 plus事件处理
function plusReady(){
updateSerivces();
if(plus.os.name=="Android"){
main = plus.android.runtimeMainActivity();
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();
}
var shareInfo = plus.webview.currentWebview().shareInfo;
sharehref.value = shareInfo.href;
sharehrefTitle.value = shareInfo.title;
sharehrefDes.value = shareInfo.content;
pageSourceId = shareInfo.pageSourceId;
console.log("pageSource:" + pageSourceId);
}
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}
/**
*
* 更新分享服务
*/
function updateSerivces(){
plus.share.getServices( function(s){
shares={};
for(var i in s){
var t=s[i];
shares[t.id]=t;
}
}, function(e){
outSet("获取分享服务列表失败:"+e.message );
} );
}
/**
* 分享操作
* @param {JSON} sb 分享操作对象s.s为分享通道对象(plus.share.ShareService)
* @param {Boolean} bh 是否分享链接
*/
function shareAction(sb,bh) {
if(!sb||!sb.s){
console.log("无效的分享服务!");
return;
}
if (plus.os.name !== "Android") {
plus.nativeUI.alert("此平台暂不支持系统分享功能!");
return;
}
var msg={content:sharehrefDes.value,extra:{scene:sb.x}};
if(bh){
msg.href=sharehref.value;
if(sharehrefTitle&&sharehrefTitle.value!=""){
msg.title=sharehrefTitle.value;
}
if(sharehrefDes&&sharehrefDes.value!=""){
msg.content=sharehrefDes.value;
}
msg.thumbs=["_www/images/logo1024.png"];
msg.pictures=["_www/images/logo1024logo.png"];
}else{
if(pic&&pic.realUrl){
msg.pictures=[pic.realUrl];
}
}
// 发送分享
if ( sb.s.authenticated ) {
console.log("---已授权---");
shareMessage(msg,sb.s);
} else {
console.log("---未授权---");
sb.s.authorize( function(){
shareMessage(msg,sb.s);
},function(e){
console.log("认证授权失败:"+e.code+" - "+e.message );
});
}
}
/**
* 发送分享消息
* @param {JSON} msg
* @param {plus.share.ShareService} s
*/
function shareMessage(msg,s){
console.log(JSON.stringify(msg));
s.send( msg, function(){
console.log("分享到\""+s.description+"\"成功! " );
}, function(e){
console.log( "分享到\""+s.description+"\"失败: "+JSON.stringify(e) );
} );
}
// 分析链接
function shareHref(index){
var shareBts=[];
// 更新分享列表
var ss=shares['weixin'];
ss&&ss.nativeClient&&(shareBts.push({title:'微信朋友圈',s:ss,x:'WXSceneTimeline'}),
shareBts.push({title:'微信好友',s:ss,x:'WXSceneSession'}));
ss=shares['qq'];
ss&&ss.nativeClient&&shareBts.push({title:'QQ',s:ss});
shareAction(shareBts[index],true);
}
mui.back = function() {
var sourcePage = plus.webview.getWebviewById(pageSourceId);
if (sourcePage) {
sourcePage.evalJS("closeMask()");
}
}
function closeShare() {
console.log("e:" + event.target.name);
}
</script>
</html>