From f26f29d84e0a68831a6af14dab3eec5500496d2e Mon Sep 17 00:00:00 2001 From: spring <2396852758@qq.com> Date: 星期三, 28 五月 2025 16:48:52 +0800 Subject: [PATCH] 初始化项目 --- components/scan/scan.vue | 93 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 93 insertions(+), 0 deletions(-) diff --git a/components/scan/scan.vue b/components/scan/scan.vue new file mode 100644 index 0000000..c39741c --- /dev/null +++ b/components/scan/scan.vue @@ -0,0 +1,93 @@ +<template> + <view> + <view class="content"> + </view> + </view> +</template> + +<script> + var main, receiver, filter; + var action, extraKey; + var _codeQueryTag = false; + export default { + data() { + return { + scanCode: '' + } + }, + created: function(option) { + uni.getSystemInfo({ + success: (res) => { + var brand = res.brand.toUpperCase(); + var model = res.model.toUpperCase(); + if (brand.indexOf("ZEBRA")!=-1 && model.indexOf("TC2")!=-1) { + action = "com.zebra.scan"; + extraKey = "com.motorolasolutions.emdk.datawedge.data_string"; + } else if (brand.indexOf("SEUIC")!=-1||brand.indexOf("AUTOID")!=-1) { + action = "com.android.server.scannerservice.broadcast"; + extraKey = "scannerdata"; + }else{ + return; + } + console.log(action); + console.log(extraKey); + this.initScan() + this.startScan(); + } + }) + + + + }, + onHide: function() { + this.stopScan(); + }, + destroyed: function() { + this.stopScan(); + }, + methods: { + initScan() { + console.log('initScan'); + let _this = this; + main = plus.android.runtimeMainActivity(); //鑾峰彇activity + var IntentFilter = plus.android.importClass('android.content.IntentFilter'); + filter = new IntentFilter(); + //涓嬮潰鐨刟ddAction鍐呮敼涓鸿嚜宸辩殑骞挎挱鍔ㄤ綔 + filter.addAction(action); + receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', { + onReceive: function(context, intent) { + console.log('onReceive'); + plus.android.importClass(intent); + //涓嬮潰鐨刧etStringExtra鍐呮敼涓鸿嚜宸辩殑骞挎挱鏍囩--鏈夎 + let code = intent.getStringExtra(extraKey); + _this.queryCode(code); + } + }); + }, + startScan() { + console.log('startScan'); + main.registerReceiver(receiver, filter); + }, + stopScan() { + console.log('stopScan'); + main.unregisterReceiver(receiver); + }, + queryCode: function(code) { + console.log('queryCode'); + if (_codeQueryTag) return false; + _codeQueryTag = true; + setTimeout(function() { + _codeQueryTag = false; + }, 150); + var id = code + uni.$emit('scan', { + code: id + }) + } + } + } +</script> + +<style> + +</style> -- Gitblit v1.9.3