Skip to content

Commit

Permalink
更新版本为2.3.2
Browse files Browse the repository at this point in the history
修改分享示例页面逻辑(微信、微博、QQ为独立分享页面)
原生界面添加图片预览示例
  • Loading branch information
YanYiLin committed Aug 10, 2018
1 parent ed059a2 commit 0e22210
Show file tree
Hide file tree
Showing 8 changed files with 970 additions and 193 deletions.
Binary file modified img/barcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"id": "HelloH5",
"name": "HelloH5",
"version": {
"name": "2.3.1",
"code": "20301"
"name": "2.3.2",
"code": "20302"
},
"description": "HTML5 Plus能力演示",
"icons": {
Expand Down Expand Up @@ -127,7 +127,7 @@
},
"plus": {
"splashscreen": {
"autoclose": false,
"autoclose": true,
"waiting": true
},
"statusbar": {
Expand Down
12 changes: 12 additions & 0 deletions plus/nativeui.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
<title>Hello H5+</title>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript">
function previewImage() {
outSet("预览图片");
plus.nativeUI.previewImage([
"_www/img/h5p.jpg",
"../img/shake/2.jpg",
"http://img-cdn-qiniu.dcloud.net.cn/newpage/images/logo4.png"
],{
current:1,
loop:true
});
}
function pickDate() {
outSet( "打开系统日期选择框:");
var dDate=new Date();
Expand Down Expand Up @@ -94,6 +105,7 @@
</header>
<div id="dcontent" class="dcontent">
<ul class="dlist">
<li class="ditem" onclick="previewImage()">预览图片</li>
<li class="ditem" onclick="pickDate()">系统日期选择框</li>
<li class="ditem" onclick="pickTime()">系统时间选择框</li>
<li class="ditem" onclick="showAlert()">提示框</li>
Expand Down
198 changes: 8 additions & 190 deletions plus/share.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
function shareSystem(){
outSet('调用系统分享');
var msg={content:sharecontent.value};
if(pic&&pic.realUrl){
msg.pictures=[pic.realUrl];
}
if('iOS'==plus.os.name){//iOS平台添加链接地址
msg.href='http://www.dcloud.io/';
}
Expand All @@ -59,174 +56,11 @@
return;
}
var intent=new Intent(Intent.ACTION_SEND);
if(pic&&pic.realUrl){
var p = '';
p = pic.realUrl;
if(p.substr(0,7)==='file://'){
p=p.substr(7);
}else if(p.sub(0)!=='/'){
p=plus.io.convertLocalFileSystemURL(p);
}
}
var f = new File(p);
var uri = Uri.fromFile(f);
if(f.exists()&&f.isFile()){
console.log('image/*');
intent.setType('image/*');
intent.putExtra(Intent.EXTRA_STREAM,uri);
}else{
console.log('text/plain');
intent.setType('text/plain');
}
intent.setType('text/plain');
intent.putExtra(Intent.EXTRA_SUBJECT,'HelloH5');
intent.putExtra(Intent.EXTRA_TEXT,sharecontent.value);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
main.startActivity(Intent.createChooser(intent,'系统分享HelloH5'));
}
/**
* 分享操作
* @param {JSON} sb 分享操作对象s.s为分享通道对象(plus.share.ShareService)
* @param {Boolean} bh 是否分享链接
*/
function shareAction(sb,bh) {
outSet('分享操作:');
if(!sb||!sb.s){
outLine('无效的分享服务!');
return;
}
var msg={content:sharecontent.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/logo.png'];
msg.pictures=['_www/logo.png'];
}else{
if(pic&&pic.realUrl){
msg.pictures=[pic.realUrl];
}
}
// 发送分享
if(sb.s.authenticated){
outLine('---已授权---');
shareMessage(msg, sb.s);
}else{
outLine('---未授权---');
sb.s.authorize(function(){
shareMessage(msg,sb.s);
}, function(e){
outLine('认证授权失败:'+e.code+' - '+e.message);
});
}
}
/**
* 发送分享消息
* @param {JSON} msg
* @param {plus.share.ShareService} s
*/
function shareMessage(msg, s){
outLine(JSON.stringify(msg));
s.send(msg, function(){
outLine('分享到"'+s.description+'"成功!');
}, function(e){
outLine('分享到"'+s.description+'"失败: '+JSON.stringify(e));
});
}
/**
* 解除所有分享服务的授权
*/
function cancelAuth(){try{
outSet('解除授权:');
for(var i in shares){
var s=shares[i];
if(s.authenticated){
outLine('取消"'+s.description+'"');
}
s.forbid();
}
// 取消授权后需要更新服务列表
updateSerivces();
outLine('操作成功!');}catch(e){alert(e);}
}
// 拍照添加图片分享
function shareCameraPicture(){
outSet('拍照添加分享图片:');
var cmr=plus.camera.getCamera();
cmr.captureImage(function(p){
plus.io.resolveLocalFileSystemURL(p,function(entry){
pic.src=entry.toLocalURL();
pic.realUrl=p;
outLine('拍照图片:'+pic.realUrl);
},function(e){
outLine('读取拍照文件错误:'+e.message);
} );
},function(e){
outLine('拍照失败:'+e.message);
});
}
// 从相册添加图片分享
function shareGalleryPicture(){
outSet('从相册添加分享图片:');
plus.gallery.pick(function(p){
// 从相册返回的路径不需要转换可以直接使用
pic.src=p;
pic.realUrl=pic.src;
outLine('选择图片:'+pic.realUrl);
// plus.io.resolveLocalFileSystemURL(p,function(entry){
// pic.src=entry.toLocalURL();
// pic.realUrl=pic.src;
// outLine('选择图片:'+pic.realUrl);
// },function(e){
// outLine('读取拍照文件错误:'+e.message);
// } );
});
}
// 使用Logo图片分享
function shareLogoPicture(){
outSet('使用Logo分享图片:');
var url='_www/logo.png';
plus.io.resolveLocalFileSystemURL(url, function(entry){
pic.src=entry.toLocalURL();
pic.realUrl=url;
}, function(e){
outLine('读取Logo文件错误:'+e.message);
});
}
// 打开分享
function shareShow(){
var shareBts=[];
// 更新分享列表
var ss=shares['weixin'];
if(navigator.userAgent.indexOf('qihoo')<0){ //在360流应用中微信不支持分享图片
ss&&ss.nativeClient&&(shareBts.push({title:'微信朋友圈',s:ss,x:'WXSceneTimeline'}),
shareBts.push({title:'微信好友',s:ss,x:'WXSceneSession'}));
}
ss=shares['sinaweibo'];
ss&&shareBts.push({title:'新浪微博',s:ss});
ss=shares['qq'];
ss&&ss.nativeClient&&shareBts.push({title:'QQ',s:ss});
// 弹出分享列表
shareBts.length>0?plus.nativeUI.actionSheet({title:'分享',cancel:'取消',buttons:shareBts}, function(e){
(e.index>0)&&shareAction(shareBts[e.index-1],false);
}):plus.nativeUI.alert('当前环境无法支持分享操作!');
}
// 分析链接
function shareHref(){
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});
// 弹出分享列表
shareBts.length>0?plus.nativeUI.actionSheet({title:'分享链接',cancel:'取消',buttons:shareBts},function(e){
(e.index>0)&&shareAction(shareBts[e.index-1],true);
}):plus.nativeUI.alert('当前环境无法支持分享链接操作!');
}
</script>
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
Expand Down Expand Up @@ -260,36 +94,20 @@
<div class="nvbt idoc" onclick="openDoc('Share Document','/doc/share.html')"></div>
</header>
<div id="dcontent" class="dcontent">
<br/>
<div class="button" onclick="clicked('share_weixin.html',true)">微信分享</div>
<div class="button" onclick="clicked('share_qq.html',true)">QQ分享</div>
<div class="button" onclick="clicked('share_sinaweibo.html',true)">微博分享</div>

<br/>
<p class="heading">分享内容:</p>
<textarea id="sharecontent" rows="3">我正在使用HBuilder+HTML5开发移动应用,赶紧跟我一起来体验!</textarea>
<br/><br/>
<p class="heading">分享图片:</p>
<table style="width:100%;">
<tbody>
<tr>
<td style="width:30%"><div class="button button-select" onclick="shareCameraPicture()">拍照</div></td>
<td style="width:30%"><div class="button button-select" onclick="shareGalleryPicture()">相册选取</div></td>
<td style="width:30%"><div class="button button-select" onclick="shareLogoPicture()">使用logo图</div></td>
</tr>
</tbody>
</table>
<img id="pic" src="../img/add.png"/>
<br/>
<div class="button" onclick="shareShow()">分 享</div>
<div class="button" onclick="shareSystem()">系统分享</div>
<div style="padding: 0.5em 1em;"><hr color="#EEE"/></div>
<p class="heading">链接地址:</p>
<input id="sharehref" class="sharehref" type="url" value="http://www.dcloud.io/" placeholder="请输入要分享的链接地址"/>
<p class="heading">链接标题:</p>
<input id="sharehrefTitle" class="sharehref" type="text" value="DCloud HBuilder-做最好的HTML5开发工具" placeholder="请输入要分享的链接标题"/>
<p class="heading">链接描述:</p>
<input id="sharehrefDes" class="sharehref" type="text" value="我正在使用HBuilder+HTML5开发移动应用,赶紧跟我一起来体验!" placeholder="请输入要分享的链接描述"/>
<div class="button" onclick="shareHref()">分享链接</div>
<br/><br/>
<div style="padding: 0.5em 1em;"><hr color="#EEE"/></div>
<!--
<p class="des">如果需要解除分享中绑定的用户信息,请点击解除授权:</p>
<div class="button" onclick="cancelAuth()">解除授权</div>
-->
</div>
<div id="output">
Share模块管理客户端的社交分享功能,提供调用终端社交软件的分享能力。通过plus.share可获取社交分享管理对象。
Expand Down
Loading

0 comments on commit 0e22210

Please sign in to comment.