回退扫码方案:删除自定义扫码页,直接使用uni.scanCode(安卓原生)
This commit is contained in:
parent
a52a8cc404
commit
19865348c7
@ -53,13 +53,6 @@
|
|||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "图书上传"
|
"navigationBarTitleText": "图书上传"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "pages/upload/scan-isbn",
|
|
||||||
"style": {
|
|
||||||
"navigationBarTitleText": "",
|
|
||||||
"navigationStyle": "custom"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"globalStyle": {
|
"globalStyle": {
|
||||||
|
|||||||
@ -1,107 +0,0 @@
|
|||||||
<template>
|
|
||||||
<view class="page">
|
|
||||||
<view id="barcodeContainer" class="barcode-container"></view>
|
|
||||||
<view class="close-btn" @click="goBack">
|
|
||||||
<text class="close-icon">✕</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
barcode: null,
|
|
||||||
scanned: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.initBarcode()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
onUnload() {
|
|
||||||
this.destroyBarcode()
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
initBarcode() {
|
|
||||||
if (typeof plus === 'undefined') {
|
|
||||||
uni.showToast({ title: '扫码初始化失败', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var options = {
|
|
||||||
top: '0px',
|
|
||||||
left: '0px',
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
frameColor: '#00000000',
|
|
||||||
scanbarColor: '#00000000',
|
|
||||||
background: '#00000000'
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
this.barcode = new plus.barcode.Barcode('barcodeContainer', [plus.barcode.EAN13, plus.barcode.EAN8, plus.barcode.UPCA, plus.barcode.CODE128], options)
|
|
||||||
this.barcode.onmarked = (type, result) => {
|
|
||||||
if (this.scanned) return
|
|
||||||
this.scanned = true
|
|
||||||
if (result && result.length >= 10 && result.length <= 14) {
|
|
||||||
this.barcode.cancel()
|
|
||||||
uni.$emit('scan-isbn-result', result)
|
|
||||||
uni.navigateBack()
|
|
||||||
} else {
|
|
||||||
this.scanned = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.barcode.onerror = (e) => {
|
|
||||||
console.error('扫码错误:', e)
|
|
||||||
uni.showToast({ title: '扫码异常', icon: 'none' })
|
|
||||||
}
|
|
||||||
this.barcode.start()
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Barcode init error:', e)
|
|
||||||
uni.showToast({ title: '扫码初始化失败', icon: 'none' })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
destroyBarcode() {
|
|
||||||
if (this.barcode) {
|
|
||||||
try { this.barcode.cancel() } catch(e) {}
|
|
||||||
try { this.barcode.close() } catch(e) {}
|
|
||||||
this.barcode = null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
goBack() {
|
|
||||||
this.destroyBarcode()
|
|
||||||
uni.navigateBack()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.page {
|
|
||||||
flex: 1;
|
|
||||||
background-color: #000;
|
|
||||||
position: relative;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
.barcode-container {
|
|
||||||
position: absolute;
|
|
||||||
top: 0; left: 0; right: 0; bottom: 0;
|
|
||||||
}
|
|
||||||
.close-btn {
|
|
||||||
position: fixed;
|
|
||||||
top: 60rpx;
|
|
||||||
left: 30rpx;
|
|
||||||
width: 60rpx;
|
|
||||||
height: 60rpx;
|
|
||||||
border-radius: 50%;
|
|
||||||
background: rgba(255,255,255,0.2);
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
z-index: 9999;
|
|
||||||
}
|
|
||||||
.close-icon {
|
|
||||||
color: #fff;
|
|
||||||
font-size: 36rpx;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@ -958,21 +958,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow() {
|
|
||||||
// 每次页面显示时注册扫码结果监听
|
|
||||||
uni.$off('scan-isbn-result')
|
|
||||||
uni.$on('scan-isbn-result', (code) => {
|
|
||||||
if (code) {
|
|
||||||
this.isbn = code.trim()
|
|
||||||
this.searchISBN()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
onUnload() {
|
|
||||||
uni.$off('scan-isbn-result')
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
conditionValue() {
|
conditionValue() {
|
||||||
const map = {
|
const map = {
|
||||||
@ -1162,8 +1147,16 @@ export default {
|
|||||||
uni.showToast({ title: '请先登录孔网账号', icon: 'none' })
|
uni.showToast({ title: '请先登录孔网账号', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 打开nvue扫码页面(全屏摄像头,无取景框,实时识别)
|
// 手机系统原生扫码(实时识别,对准即出结果)
|
||||||
uni.navigateTo({ url: '/pages/upload/scan-isbn' })
|
uni.scanCode({
|
||||||
|
onlyFromCamera: true,
|
||||||
|
scanType: ['barcode'],
|
||||||
|
success: (res) => {
|
||||||
|
this.isbn = (res.result || '').trim()
|
||||||
|
this.searchISBN()
|
||||||
|
},
|
||||||
|
fail: () => {}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// ISBN搜索 - 查询图书中心 + 孔网市场
|
// ISBN搜索 - 查询图书中心 + 孔网市场
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user