mui 扫描二维码

html

<div id="bcid"></div>
<!-- <div id="turnTheLight"></div> -->

css

html, body ,div{
	height:100%;
	width: 100%;
}

#bcid{
	width: 100%;
	height: 100%;
	position: absolute;
	background: #000000;
}


js

var 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){  
        
	}  
};

function onerror(e){  
	console.log('扫码错误', 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;
	}
	scan.close();
	document.getElementById('bcid').remove();
	// 跳转页面
	mui.openWindow({
		id: "saosaomsg.html",
		url: "../../pages/newpages/saosaomsg.html",
		extras: {
			result: result.split('=')[1]
		}
	}) 
}

// 从相册中选择二维码图片   
// 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);  
// 	});  
// }