barcode自定义扫码,相机可以正常打开,但是扫码没反应,也没失败返回,请问各位大佬有谁知道怎么解决这个问题嘛?
import permision from "./permission.js";
import helper from "./helper.js";
const ScanCode = {}
// #ifdef APP-PLUS
ScanCode.checkPermission = async (code) => {
let status = permision.isIOS ? await permision.requestIOS('camera') :
await permision.requestAndroid('android.permission.CAMERA');
if (status === null || status === 1) {
status = 1;
} else {
uni.showModal({
content: "需要相机权限",
confirmText: "设置",
success: function(res) {
if (res.confirm) {
permision.gotoAppSetting();
}
}
})
}
return status;
}
// #endif
ScanCode.CreateBarcode = async (pageInfo) => {
const currentWebview = pageInfo.$mp.page.$getAppWebview();
// #ifdef APP-PLUS
var barcode = null;
if (!barcode) {
barcode = plus.barcode.create('barcode', [plus.barcode.QR,
plus.barcode.EAN13,
plus.barcode.EAN8,
plus.barcode.CODE39,
plus.barcode.AZTEC,
plus.barcode.DATAMATRIX,
plus.barcode.UPCA,
plus.barcode.UPCE,
plus.barcode.CODABAR,
plus.barcode.CODE39,
plus.barcode.CODE93,
plus.barcode.CODE128,
plus.barcode.ITF,
plus.barcode.MAXICODE,
plus.barcode.PDF417,
plus.barcode.RSS14,
plus.barcode.RSSEXPANDED], {
top: '60%',
width: '100%',
height: '300px',
position: 'static'
});
currentWebview.append(barcode);
}
// #endif
return barcode;
}
ScanCode.ContinuousScanCode = async (pageInfo, isContinue, callBackFunc) => {
var that = pageInfo;
let status = await ScanCode.checkPermission();
if (status !== 1) {
return;
}
var barcode = null;
await ScanCode.CreateBarcode(pageInfo);
barcode.setFlash(false)
barcode.start() //开始识别二维码
barcode.onmarked = function(type, code) {
alert(code);
callBackFunc(code);
if (isContinue) {
setTimeout(function() {
barcode.start() //开始识别二维码
}, 1000)
}
else
{
barcode.close(); // 关闭二维码扫描
}
return code;
},
barcode.onerror = function(err){
console.log(JSON.stringify(err));
alert(err);
}
}
export default ScanCode
0 个回复