<!doctype html>
<html>
<head>
<meta charset=
"UTF-8"
>
<title></title>
<meta name=
"viewport"
content=
"width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"
/>
<link href=
"css/mui.min.css"
rel=
"stylesheet"
/>
<script src=
"js/mui.min.js"
></script>
<style type=
"text/css"
>
#bcid{
width: 100%;
height: 100%;
position: absolute;
background: #000000;
}
html, body ,p{
height:100%;
width: 100%;
}
.fbt{
color: #0E76E1;
width: 50%;
background-color: #ffffff;
float: left;
line-height: 44px;
text-align: center;
}
</style>
</head>
<body>
<header
class
=
"mui-bar mui-bar-nav"
style=
"background-color: #ffffff;"
>
<a
class
=
"mui-action-back mui-icon mui-icon-left-nav mui-pull-left"
></a>
<h1
class
=
"mui-title"
style=
"color: #0E76E1;"
>物品二维码扫描</h1>
<span
class
=
"mui-icon mui-icon-spinner-cycle mui-spin mui-pull-right"
id=
"turnTheLight"
></span>
</header>
<p id=
"bcid"
>
<!--盛放扫描控件的p-->
</p>
<p
class
=
"mui-bar mui-bar-footer"
style=
"padding: 0px;"
>
<p
class
=
"fbt"
onclick=
"scanPicture();"
>从相册选择二维码</p>
<p
class
=
"fbt mui-action-back"
>取 消</p>
</p>
<script type=
"text/javascript"
>
scan = null;
mui.plusReady(
function
() {
mui.init();
startRecognize();
});
function
startRecognize(){
try
{
var
filter;
var
styles = {frameColor:
"#29E52C"
,scanbarColor:
"#29E52C"
,background:
""
}
scan =
new
plus.barcode.Barcode(
'bcid'
,filter,styles);
scan.onmarked = onmarked;
scan.onerror = onerror;
scan.start();
var
flag = false;
document.getElementById(
"turnTheLight"
).addEventListener(
'tap'
,
function
(){
if
(flag == false){
scan.setFlash(true);
flag = true;
}
else
{
scan.setFlash(false);
flag = false;
}
});
}
catch
(e){
alert(
"出现错误啦:\n"
+e);
}
};
function
onerror(e){
alert(e);
};
function
onmarked( type, result ) {
var
text =
''
;
switch
(type){
case
plus.barcode.QR:
text =
'QR: '
;
break
;
case
plus.barcode.EAN13:
text =
'EAN13: '
;
break
;
case
plus.barcode.EAN8:
text =
'EAN8: '
;
break
;
}
alert( text +
" : "
+ result );
};
function
scanPicture() {
plus.gallery.pick(
function
(path){
plus.barcode.scan(path,onmarked,
function
(error){
plus.nativeUI.alert(
"无法识别此图片"
);
});
},
function
(err){
plus.nativeUI.alert(
"Failed: "
+err.message);
});
}
</script>
</body>
</html>