This commit is contained in:
2026-06-02 15:28:25 +08:00
commit b271b84f70
249 changed files with 42240 additions and 0 deletions
+91
View File
@@ -0,0 +1,91 @@
/**
* iData 扫码功能 MixinAPP + 小程序双端通用)
* 提供可复用的跨端扫码能力
*/
// #ifdef APP-PLUS
import scan from '@/utils/scan.js'
// #endif
export default {
data() {
return {
scanStatus: ''
}
},
// #ifdef APP-PLUS
onLoad() {
this.initScanner()
},
onUnload() {
this.cleanupScanner()
},
// #endif
methods: {
// #ifdef APP-PLUS
/**
* APP端:初始化扫码模块
*/
initScanner() {
try {
const mode = (this.$store && this.$store.state && this.$store.state.scan && this.$store.state.scan.scanMode) || 'idata'
scan.setMode(mode)
scan.init()
scan.register((codeStr) => {
this.onBarcodeScanned(codeStr)
})
} catch (e) {
console.error('[BarcodeMixin] 扫码初始化失败:', e)
}
},
/**
* APP端:清理扫码资源
*/
cleanupScanner() {
scan.unregister()
},
/**
* APP端扫码:点一次开始扫描,再点一次停止扫描
*/
scanCode() {
if (scan.isScanning()) {
scan.stopScan()
} else {
scan.startScan()
}
},
// #endif
// #ifdef MP
/**
* 小程序端扫码:调用 uni 跨平台扫码 API
*/
scanCode() {
uni.scanCode({
success: (res) => {
this.onBarcodeScanned(res.result)
},
fail: (err) => {
console.error('[BarcodeMixin] 小程序扫码失败:', err)
if (err.errMsg && err.errMsg.indexOf('cancel') === -1) {
uni.showToast({ title: '扫码失败', icon: 'none' })
}
}
})
},
// #endif
/**
* 扫码成功后的默认处理(页面可覆盖此方法自定义处理逻辑)
* @param {string} barcode - 扫码结果
*/
onBarcodeScanned(barcode) {
console.log('[BarcodeMixin] 收到条码:', barcode)
}
}
}