This commit is contained in:
2026-06-02 15:28:25 +08:00
commit b271b84f70
249 changed files with 42240 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
<template>
<view>
<view class="uni-section">
<text>扫描测试统一扫码模块</text>
</view>
<view class="uni-form-item uni-column">
<button class="btn btn-primary" @click="startScan">开始扫描</button>
<button class="btn" @click="stopScan">停止扫描</button>
</view>
<view v-if="scanResult">
<text>最近扫描结果: {{ scanResult }}</text>
</view>
</view>
</template>
<script>
import scan from '@/utils/scan.js'
export default {
data() {
return {
scanResult: ''
}
},
onLoad() {
// 初始化(默认自动检测模式,也可手动指定)
// scan.setMode('idata') // 强制 iData 模式
scan.setMode('android') // 强制 Android 系统模式
scan.init()
// 注册扫码结果回调
scan.register(this.onScanResult)
},
onUnload() {
scan.unregister()
},
methods: {
/**
* 扫码结果回调
* @param {string} codeStr - 解码后的扫描字符串
*/
onScanResult(codeStr) {
console.log('codeStr:', codeStr)
this.scanResult = codeStr
uni.showToast({
title: codeStr,
duration: 2000
})
},
startScan() {
scan.startScan()
},
stopScan() {
scan.stopScan()
}
}
}
</script>
<style>
</style>