越王够贱
越王够贱
  • 发布:2021-09-22 01:09
  • 更新:2021-09-22 09:27
  • 阅读:973

uni.previewImage itemlist 加个识别远程图片中二维码 如何用plus.barcode.scan识别?

分类:uni-app

uni.previewImage({
urls: urls,
longPressActions: {
itemList: ['发送给朋友', '保存图片', '识别二维码'],
success: function(data) {
console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');

                    if(data.tapIndex == 1){  
                        _that.initCheckDownload(urls[data.index]);  
                    }  

                    if(data.tapIndex == 2){  
                        _that.parseCode(urls[data.index]);  
                    }  

                },  
                fail: function(err) {  
                    console.log(err.errMsg);  
                },  
                complete: () => {  

                }  
            },  
            complete: () => {  
                uni.hideLoading();  
            }  
        });  

//识别二维码
parseCode : function(data){
plus.barcode.scan(data,
function(type,result) {
console.log("Scan success:("+type+")"+result);
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, '');
result = result.toLowerCase();//url转为全小写
result = result.replace(/\"/g, "");
browser.init(result);//跳转APP内置浏览器
}, function(e){
console.log("Scan failed: "+JSON.stringify(e));
})
},

这里不能传入远程地址

2021-09-22 01:09 负责人:无 分享
已邀请:
越王够贱

越王够贱 (作者)

我用下载后再删除的方式实现了。但是还有个问题

如果不关闭预览图片执行不了保存图片

// 预览图片  
            let aa = uni.previewImage({  
                urls: urls,  
                longPressActions: {  
                    itemList: ['发送给朋友', '保存图片', '识别二维码并打开'],  
                    success: function(data) {  

                        if(data.tapIndex == 1){  
                            _that.initCheckDownload(urls[data.index]);  
                        }  

                        if(data.tapIndex == 2){  
                            _that.initParseQRCode(urls[data.index]);  
                        }  

                        console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');  

                    },  
                    fail: function(err) {  
                        console.log(err.errMsg);  
                    },  
                    complete: () => {  
                        aa.close()  
                    }  
                },  
                complete: () => {  
                    uni.hideLoading();  
                },  
            });  

        },  
        initParseQRCode : function(address){  
            let _that = this;  
            uni.saveImageToPhotosAlbum({//保存图片到系统相册。  
                filePath: address,//图片文件路径  
                success: function(data) {  
                    console.log('保存出来的地址:'+data.path);  
                    _that.parseCode(data.path);  
                    _that.errmsg('二维码保存成功!');  
                },  
                fail: function(e) {  
                    console.log(e);  
                    _that.errmsg('识别二维码失败!');  
                }  
            });  
        },  
        //识别二维码  
        parseCode : function(address){  
            //address = 'file:///storage/emulated/0/DCIM/Camera/1632237648300wKKPNhSJoI.PNG';  
            plus.barcode.scan(address,  
                function(type,result) {  
                    console.log("Scan success:("+type+")"+result);  
                    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, '');    
                    result = result.toLowerCase();//url转为全小写    
                    result = result.replace(/\"/g, "");    
                    //browser.init(result);//跳转APP内置浏览器    

                    console.log("要打开的地址:"+result)  
                    plus.runtime.openURL(result, function(res) {  
                        console.log(res);  
                    });  

                     uni.removeSavedFile({  
                        filePath: address,  
                        complete: function (res) {  
                          console.log(res);  
                        }  
                    });  
                }, function(e){  
                    console.log("Scan failed: "+JSON.stringify(e));  
                })  
        },

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