APP扫描二维码

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();
            }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值