window.isEnterPlus=0; window.geolocation=function(){ if(window.isEnterPlus!=1)return ; now_time=new Date().getTime(); last_time=parseInt(localStorage.getItem("last_time")); if(now_time-last_time<=30000)return ; } window.initPlus=function(){ window.isEnterPlus=1; window.geolocation(); } scan = null; window.ObjScan=null; window.OnMark=null; document.addEventListener("changeUI", function(){ window.closeRecognize(); }); window.clear_buffer=function(func){ func("清除成功"); } window.scan_qrcode=function(func){ if(!plus){ alert("仅支持安卓手机下APP打开,暂时不支持苹果或微信下打开!"); return ; } window.OnMark=func; startRecognize(); } window.closeRecognize=function(){ if(window.ObjScan){ window.ObjScan.close(); window.ObjScan=null; } closebutton=document.getElementById("close_Recognize"); closebutton.style.display = "none"; } function startRecognize() { try { var filter; //自定义的扫描控件样式 var styles = { top: '0px', left: '0px', width: '100%', height: '100%', position: 'absolute', autoZoom:false } //扫描控件构造 scan = plus.barcode.create('bcid', filter, styles); scan.onmarked = onmarked; scan.onerror = onerror; try{ var currentWebView=plus.webview.currentWebview() }catch(e){ alert("您的手机不支持:\n" + e); window.closeRecognize(); return ; } currentWebView.append(scan); scan.start(); //打开关闭闪光灯处理 closebutton=document.getElementById("close_Recognize"); closebutton.style.display = "block"; closebutton.onclick=function(){ window.closeRecognize(); } window.ObjScan=scan; var flag = false; if (flag == false) { scan.setFlash(true); flag = true; } else { scan.setFlash(false); flag = false; } } catch (e) { alert("出现错误啦:\n" + e); window.closeRecognize(); } }; function onerror(e) { window.closeRecognize(); 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; } //扫描成功之后的处理 result=encodeURIComponent(result); window.closeRecognize(); window.OnMark(result); };