You've already forked qlg.frontend
Init Repo
This commit is contained in:
77
js/saoyisao.js
Normal file
77
js/saoyisao.js
Normal file
@ -0,0 +1,77 @@
|
||||
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) {
|
||||
mui.alert("出现错误啦:\n" + e);
|
||||
}
|
||||
};
|
||||
|
||||
function onerror(e) {
|
||||
mui.alert(e);
|
||||
};
|
||||
|
||||
function onmarked(type, result) {
|
||||
var text = '';
|
||||
switch(type) {
|
||||
case plus.barcode.QR:
|
||||
text = 'QR: ';
|
||||
break;
|
||||
case plus.barcode.EAN13:
|
||||
text = '条码: ';
|
||||
break;
|
||||
case plus.barcode.EAN8:
|
||||
text = '条码: ';
|
||||
break;
|
||||
}
|
||||
|
||||
if('http' == result.substring(0,4)){
|
||||
console.log(result);
|
||||
plus.runtime.openURL(result);
|
||||
}else{
|
||||
mui.alert(text + " : " + result);
|
||||
}
|
||||
|
||||
scan.cancel();
|
||||
scan.close();
|
||||
// scanDoit(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);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user