From 89ae534b45980080490bab2205c06f1aae4b012f Mon Sep 17 00:00:00 2001 From: caill <815519168@qq.com> Date: Wed, 16 Jul 2025 17:06:35 +0800 Subject: [PATCH] =?UTF-8?q?rfid=E5=B9=BF=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 26 ++++++++++++-------------- pages.json | 8 ++++++++ pages/manage/test.vue | 42 ++++++++++++++++++++++++++++++++++++++++++ utils/rfid.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 pages/manage/test.vue create mode 100644 utils/rfid.js diff --git a/manifest.json b/manifest.json index 487dc7a..7ffb35a 100644 --- a/manifest.json +++ b/manifest.json @@ -21,28 +21,25 @@ }, /* 模块配置 */ "modules" : { - "Barcode" : {}, - "Camera" : {} + "Bluetooth" : {} }, /* 应用发布信息 */ "distribute" : { /* android打包配置 */ "android" : { "permissions" : [ - "", - "", - "", - "", - "", - "", + "", "", - "", - "", - "", + "", + "", + "", + "", "", + "", + "", + "", + "", "", - "", - "", "" ], "abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ] @@ -87,7 +84,8 @@ } } } - } + }, + "nativePlugins" : {} }, /* 快应用特有相关 */ "quickapp" : {}, diff --git a/pages.json b/pages.json index 68332c7..a980ffb 100644 --- a/pages.json +++ b/pages.json @@ -32,6 +32,14 @@ } } + ,{ + "path" : "pages/manage/test", + "style" : + { + "navigationStyle": "custom" + } + + } ], "globalStyle": { // "pageOrientation": "landscape", diff --git a/pages/manage/test.vue b/pages/manage/test.vue new file mode 100644 index 0000000..d83e765 --- /dev/null +++ b/pages/manage/test.vue @@ -0,0 +1,42 @@ + + + \ No newline at end of file diff --git a/utils/rfid.js b/utils/rfid.js new file mode 100644 index 0000000..d18ceb4 --- /dev/null +++ b/utils/rfid.js @@ -0,0 +1,43 @@ +export const initRfidScan = (callback) => { + // #ifdef APP-PLUS + const main = plus.android.runtimeMainActivity(); + const IntentFilter = plus.android.importClass('android.content.IntentFilter'); + const filter = new IntentFilter(); + filter.addAction('com.ubx.scan.rfid'); // 广播动作 + + const processedData = new Set(); // 用于记录已处理的数据 + let debounceTimer = null; // 用于存储定时器 + const debounceDelay = 500; // 防抖延迟时间(毫秒) + + const receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', { + onReceive: (context, intent) => { + plus.android.importClass(intent); + const rfidEpc = intent.getStringExtra('rfid_epc'); // 广播标签数据 + const rfidData = intent.getStringExtra('rfid_data'); // 广播标签数据 + + // 防抖处理 + clearTimeout(debounceTimer); + debounceTimer = setTimeout(() => { + // 检查是否已经处理过该数据 + if (!processedData.has(rfidData)) { + processedData.add(rfidData); // 记录已处理的数据 + if (callback) { + callback({ rfidEpc, rfidData }); + } + } else { + console.log('Duplicate RFID Data:', rfidData); + } + }, debounceDelay); + }, + }); + + main.registerReceiver(receiver, filter); + + // 保存引用以便后续注销 + return () => { + clearTimeout(debounceTimer); // 清除定时器 + main.unregisterReceiver(receiver); + processedData.clear(); // 清空已处理的数据记录 + }; + // #endif +}; \ No newline at end of file