1***@qq.com
1***@qq.com
  • 发布:2019-04-26 15:19
  • 更新:2019-04-26 16:33
  • 阅读:1905

使用h5+的webview和barcode自定义扫码页,打包发布以后异常

分类:uni-app

项目需要自定义条码扫描页 真机调试是正常的


但是打包后出现异常

 var barcodeWebview;  
function openStartRecognize () {  
     barcodeWebview = plus.webview.create('_www/hybrid/html/scan.html', 'barcodeWebview', {  
        titleNView: {  
            autoBackButton: true,  
            backgroundColor: '#03B7BE',  
            titleColor: '#FFFFFF',  
            titleText: '扫描条码',  
        },  
        backButtonAutoControl: 'hide',  
        hardwareAccelerated: true,  
    background:"transparent"  
    })  
}  

function openStartRecog (title) {  
    return new Promise(function (resolve, reject) {  
        barcodeWebview.show('slide-in-right', 200, function() {  
        });  
        barcodeWebview.addEventListener('hide', function() {  
            var barcodeValue = plus.storage.getItem('barcode_value');  
            if (barcodeValue) {  
                var barcodeResult = JSON.parse(barcodeValue);  
                if (barcodeResult.code === 0) {  
                    resolve (barcodeResult.result)  
                } else {  
                    reject (barcodeResult.result)  
                }  
            }else{  
        reject ('关闭')  
      }  
        });  
    })  
}

scan.html

var plusReady = function(callback) {
if (window.plus && window.plus.isReady) {
callback();
} else {
document.addEventListener('plusready', function() {
callback();
}, false);
}
}
plusReady(function() {
var storageKey = 'barcode_value'
var currentWebview = plus.webview.currentWebview();
var barcode = plus.barcode.create('barcode', [plus.barcode.CODE128], {
top: 0,
left: 0,
width: '100%',
height: '100%'
});
currentWebview.append(barcode);
barcode.start({
vibrate:false
});
//此处未演示扫码成功回调的地址设置,实际请参考HTML5Plus API自行处理
//注意扫码区域需为正方形,否则影响扫码识别率
var goBack = function () {
barcode.cancel();
currentWebview.hide();
}
plus.storage.removeItem(storageKey);
barcode.onmarked = function(type, code, file) {
plus.storage.setItem(storageKey, JSON.stringify({
code: 0,
result: code
}));
goBack();
};
barcode.onerror = function(error) {
plus.storage.setItem(storageKey, JSON.stringify({
code: 1000,
result: ''
}));
goBack();
};
// 监控扫码页的返回按钮
plus.key.addEventListener('backbutton', function() {
goBack();
});
})

2019-04-26 15:19 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com (作者)

异常图片:
https://share.weiyun.com/5DnfImv

正常图片
https://share.weiyun.com/5XiBtsC

DCloud_Android_zl

DCloud_Android_zl

麻烦提供一个简单的demo,或提供可复现的apk,并说明可复现的设备信息。

  • 1***@qq.com (作者)

    https://service.dcloud.net.cn/build/download/9cf641b0-67e3-11e9-abfe-e575e9cfc507 这是可下载的地址 用得华为荣耀9

    2019-04-26 16:39

  • DCloud_Android_zl

    回复 1***@qq.com: app是空白的

    2019-04-26 17:00

  • 1***@qq.com (作者)

    回复 DCloud_Android_zl: 忘记改内部接口地址了,目前使用其他方式解决了。我进入app首页会创建一个包含自定义扫码的barcode的webview页面,然后分别去show webview页,start barcode页面。在正式测试时,这个流程是走得通的,但是云打包发布以后,在手机上就发现扫码框飘了。

    2019-04-26 17:18

  • DCloud_Android_zl

    回复 1***@qq.com: 你给我个简单的能复现的demo,我这边测试一下。

    2019-04-26 17:43

该问题目前已经被锁定, 无法添加新回复