···
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
<meta name="HandheldFriendly" content="true" />
<meta name="MobileOptimized" content="320" />
<title>Hello H5+</title>
<script src="../../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript">
var ws = null,
wo = null;
var scan = null;
var bFlash = false;
// H5 plus事件处理
function plusReady() {
// 获取窗口对象
ws = plus.webview.currentWebview();
wo = ws.opener();
// 开始扫描
ws.addEventListener('show', function() {
scan = new plus.barcode.Barcode('bcid');
scan.onmarked = onmarked;
scan.start({
conserve: true,
filename: '_doc/barcode/'
});
createSubview();
}, false);
// 显示页面并关闭等待框
ws.show('pop-in');
// mui("#pictureclickbutton").on('tap','#pictureclickbutton',function(){
// scanPicture()
// })
// mui("#lightclickbutton").on('tap','#lightclickbutton',function(){
// switchFlash()
// })
console.log('here the function add')
// document.getElementById('pictureclickbutton').addEventListener('touchend', function() {
// console.log('dksllkd?')
// scanPicture()
// });
// document.getElementById('lightclickbutton').addEventListener('touchend', function() {
// console.log(bFlash)
// switchFlash()
// });
}
document.addEventListener('plusready', plusReady, false);
// 二维码扫描成功
function onmarked(type, result, file) {
console.log(type, result)
// var extra = plus.webview.currentWebview().baseurl
// console.log(extra)
var webviewiframe = plus.webview.getWebviewById('iframes');
// console.log(JSON.stringify(webviewnow))
mui.fire(webviewiframe, 'scanended', {
result: result
})
plus.webview.currentWebview().close()
}
function switchFlash() {
console.log('ksdjlf')
bFlash = !bFlash;
scan.setFlash(bFlash);
// ws.setStyle({titleNView: {
// buttons: [{
// fontSrc: '_www/helloh5.ttf',
// text: (bFlash?'\ue400':'\ue401'),
// fontSize: '18px',
// onclick: 'javascript:switchFlash()'
// }]
// }});
}
// 创建子窗口
function createSubview() {
//
}
// 从相册中选择二维码图片
function scanPicture() {
plus.gallery.pick(function(e) {
var pathlist = []
for (var i in e.files) {
pathlist.push(e.files[i]);
}
console.log(pathlist[0])
plus.barcode.scan(pathlist[0], function(type, result, file){
onmarked(type, result, file)
path = ''
}, function(error) {
plus.nativeUI.alert('无法识别此图片');
});
}, function(err) {
console.log('Failed: ' + err.message);
}, {
multiple: true,
maximum: 1
});
}
</script>
<!-- <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" /> -->
<style type="text/css">
#bcid {
width: 100%;
height: calc(100% - 100px);
position: absolute;
top: 0px;
bottom: 0px;
text-align: center;
}
.tip {
color: #FFFFFF;
font-weight: bold;
text-shadow: 0px -1px #103E5C;
}
.underbutton {
position: absolute;
bottom: 0px;
width: 100%;
height: 100px;
background: #000;
z-index: 100000;
display: flex;
justify-content: space-around;
align-items: center;
}
.underbutton .underbut {
flex: 1;
text-align: center;
/* background: rgb(107,120,127); */
color: #fff;
}
.underbut img {
width: 60px;
height: 60px;
}
.imgblock {
width: 60px;
height: 60px;
margin: 0 auto;
}
.imgblock a {
width: 60px;
height: 60px;
}
/* #pictureclickbutton,#lightclickbutton{
cursor: pointer;
}
#pictureclickbutton:hover,#lightclickbutton:hover{
background: #fff;
} */
a {
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
-webkit-user-select: none;
-moz-user-focus: none;
-moz-user-select: none;
}
a,
a:hover,
a:active,
a:visited,
a:link,
a:focus {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
-webkit-tap-highlight-color: transparent;
outline: none;
background: none;
text-decoration: none;
}
</style>
</head>
<body style="background-color:#000000;">
<div id="bcid">
<div style="height:40%"></div>
<p class="tip">...载入中...</p>
</div>
<div class="underbutton">
<div class="underbut">
<div class="imgblock">
<a href="javascript:void(0);" onclick="scanPicture()">
<img id="pictureclickbutton" src="./picture.png" />
</a>
</div>
<div>
相册
</div>
</div>
<div class="underbut">
<div class="imgblock">
<a href="javascript:void(0);" onclick="switchFlash()">
<img id="lightclickbutton" src="./light.png" />
</a>
</div>
<div>
开灯
</div>
</div>
</div>
</body>
</html>
···
0 个回复