修改app扫码问题

master
denghaohaoya 2026-04-02 22:45:01 +08:00
parent 2f98ab970f
commit c401d817d5
1 changed files with 40 additions and 2 deletions

View File

@ -155,6 +155,37 @@
onLoad() {
this.storeId = getStoreId()
},
onShow() {
//
this.lastScanValue = ''
this.lastScanAt = 0
// #ifdef APP-PLUS
if (this._isFirstShow === undefined) {
// onReady
this._isFirstShow = false
} else {
//
if (!this.barcodeView) {
// DOM
setTimeout(() => {
this.initAppScanner()
}, 200)
} else if (!this.paused) {
try {
this.barcodeView.start && this.barcodeView.start()
} catch (e) {}
}
}
// #endif
},
onHide() {
//
// #ifdef APP-PLUS
// ( addProduct uni.scanCode)
// onShow
this.destroyAppScanner()
// #endif
},
methods: {
/* ========== 通用:处理识别结果 ========== */
async handleScanResult(type, result) {
@ -386,7 +417,8 @@
width: rect.width + 'px',
height: rect.height + 'px'
}
const barcode = plus.barcode.create('scan-barcode', types, {
const barcodeId = 'scan-barcode-' + Date.now()
const barcode = plus.barcode.create(barcodeId, types, {
frameColor: '#FFFFFF',
scanbarColor: '#FFFFFF'
})
@ -398,7 +430,13 @@
this.handleScanResult(type, result)
}
//
barcode.start()
if (!this.paused) {
barcode.start()
}
//
if (this.flashOn && typeof barcode.setFlash === 'function') {
barcode.setFlash(true)
}
this.barcodeView = barcode
})
.exec()