<div id="barcode" style="margin-top:45px;background-color: #000000;">
<div style="height:40%"></div>
<p class="tip">...Loading...</p>
</div>
<footer>
<div class="fbt" onclick="mui.back()" style="background-color: #000000;">
<img src="images/insert_up.png" style="height: 28px; float: left;margin-top:5px;margin-left: 15px; display: none;" /><img src="images/22.png" style="height:28px;margin-top: 5px; display: none; float: left;margin-left: 10px;" /><span style="float: left; margin-left: 15px; font-size: 13px;">If not scanned,Please bind manually</span></div>
<div class="fbte" onclick="MuiUse.openWindow('cancas.html')">Manual Binding</div>
</footer>
2, the JS section is also the logic for scanning QR codes, which includes requesting server data and printing scan result information.
var scan = null;
var ws=null,wo=null;
mui.plusReady(function() {
plus.webview.close('cancas.html', 'none');//Here to jump from the home page to the scan interface, open the scan window
ws = plus.webview.currentWebview();
wo=ws.opener();
ws.addEventListener('show', function() {
startRecognize();
});
});
function onmarked(type,result,file){ //Bar Code Identification Success Event
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 = "Other"+type;
break;
}
console.log("Scan results:" + result);
if(result.length>=10 && result.length<=15){
imeisat(result);
}else{
mui.toast('2-D code at 10~15 Between characters');
}
var a = 0;
function startRecognize() { //Create Barcode Object
/*scan = new plus.barcode.Barcode('barcode');
// Create an identification control that supports the default barcode type
scan.onmarked = onmarked;
scan.start();*/
//startScan();
scan=new plus.barcode.Barcode('barcode');
scan.onmarked=onmarked;
scan.start({conserve:true,filename:"_doc/barcode/"});
}
function cancelScan() { //End Barcode Recognition
scan.cancel();
}
function closeScan() { //Turn off barcode recognition
scan.close();
}
function startScan() { //Start barcode recognition
scan.start();
}
function setFlash() { //Whether to turn on the flash
scan.setFlash();
}
// Select QR Code Picture from Album
function scanPicture() {
plus.gallery.pick(function(path) {
plus.barcode.scan(path, onmarked, function(error) {
plus.nativeUI.alert("Can't recognize this picture");
});
}, function(err) {
plus.nativeUI.alert("Failed: " + err.message);
});
}
function scaned(r) {
console.log("Binding device number:" + r);
wo.evalJS("getResult('" + r + "');");
back();
}
function imeisat(ims){
var stt= JSON.parse(localStorage.logdata);
var data =
{imei:ims,
id:stt.id,
username:stt.username,
viewflag:1
}
obj.ajax({methodName:"bindDevices",data:data},function(data){//Here is the encapsulated server ajax request, which mainly determines whether the scanned 2D code is the encoding of the device.Binding succeeds if it is correct and fails if it is wrong.
var json = eval('('+ data.d + ")");
console.log(json.success);
if(json.success=="true"){
wo.evalJS("getResult('"+ ims +"');");
mui.back();
}else{
mui.toast("Binding Failure!");
}
});
}
**OK, that's the basic function. All that's left is jumping. I don't think it's a problem. This is an app I made before that shared bike type. It gets the function of binding device id. By sweeping, it recognizes the correct code returned by the server. If it's correct, it binds successfully and if it's wrong, it returns to the client and binds fails.
Welcome to leave a message if you have any questions. The blogger will respond when he sees them.I hope this article can help more aspiring young people.Come on.You can watch me see more of the latest developments.Strict reprinting, original text, something to contact the blogger, thank you!!**