var ws = null,
wo = null;
var scan = null;
var flag = false;
mui.plusReady(function() {
plus.screen.lockOrientation("portrait-primary");
setTimeout(()=>{
// 获取窗口对象
ws = plus.webview.currentWebview();
wo = ws.opener();
//打开关闭闪光灯处理
document.getElementById("turnTheLight").addEventListener('tap', function() {
if (flag == false) {
this.style.color = "wheat";
scan.setFlash(true);
flag = true;
} else {
this.style.color = "";
scan.setFlash(false);
flag = false;
}
});
// 开始扫描
ws.addEventListener('show', function() {
scan = new plus.barcode.Barcode('bcid', [plus.barcode.QR, plus.barcode.EAN13, plus.barcode.EAN8, plus.barcode
.CODE128,
plus.barcode.ITF
], {
frameColor: '#108EE9',
scanbarColor: '#108EE9',
position: 'absolute',
});
scan.onmarked = onmarked;
scan.start({
// conserve: true,
// filename: '_doc/barcode/'
});
}, false);
// 显示页面并关闭等待框
ws.show('pop-in');
},500);
})
var oldBack = mui.back;
mui.back = function() {
plus.screen.lockOrientation("landscape-primary");
setTimeout(function() {
plus.webview.currentWebview().hide();
}, 300);
}
// 二维码扫描成功
function onmarked(type, result, file) {
switch (type) {
case plus.barcode.QR:
type = 'QR';
break;
case plus.barcode.EAN13:
type = 'EAN13';
break;
case plus.barcode.EAN8:
type = 'EAN8';
break;
default:
type = '其它' + type;
break;
}
result = result.replace(/\n/g, '');
var callback = ws.callback || scaned;
wo.evalJS(`${callback}('${result}','${type}')`);
mui.back();
}
APP扫描二维码
最新推荐文章于 2022-03-17 15:02:18 发布