From 10ae883d6368fb8fc3f95620f610c3aaf6c6a3cd Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期二, 14 七月 2026 13:50:35 +0800
Subject: [PATCH] PDA扫码调试
---
src/components/pda-scan/pda-scan.vue | 226 +++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 207 insertions(+), 19 deletions(-)
diff --git a/src/components/pda-scan/pda-scan.vue b/src/components/pda-scan/pda-scan.vue
index 341200f..de3f9bf 100644
--- a/src/components/pda-scan/pda-scan.vue
+++ b/src/components/pda-scan/pda-scan.vue
@@ -18,9 +18,17 @@
extraKey: { type: String, default: "" },
debounceMs: { type: Number, default: 150 },
},
+ data() {
+ return {
+ _ensureTimer: null,
+ _ensureTries: 0,
+ };
+ },
mounted() {
- this.init();
- if (this.active) this.start();
+ this.ensureStarted();
+ },
+ onHide() {
+ this.stop();
},
beforeUnmount() {
this.stop();
@@ -28,14 +36,45 @@
watch: {
active(val) {
if (val) {
- this.init();
- this.start();
+ this.ensureStarted();
} else {
this.stop();
}
},
},
methods: {
+ ensureStarted() {
+ if (!this.active) return;
+ this._ensureTries = 0;
+ if (this._ensureTimer) {
+ clearInterval(this._ensureTimer);
+ this._ensureTimer = null;
+ }
+
+ const tick = () => {
+ if (!this.active) return;
+ if (isRegistered) return;
+ this.init();
+ this.start();
+ this._ensureTries += 1;
+ if (isRegistered) {
+ if (this._ensureTimer) {
+ clearInterval(this._ensureTimer);
+ this._ensureTimer = null;
+ }
+ } else if (this._ensureTries >= 50) {
+ if (this._ensureTimer) {
+ clearInterval(this._ensureTimer);
+ this._ensureTimer = null;
+ }
+ }
+ };
+
+ tick();
+ if (!isRegistered) {
+ this._ensureTimer = setInterval(tick, 200);
+ }
+ },
canUseAndroidBroadcast() {
try {
if (typeof plus === "undefined") return false;
@@ -47,22 +86,22 @@
}
},
resolveBroadcastConfig(sys) {
+ try {
+ const brand = String(sys?.brand || "").toUpperCase();
+ const model = String(sys?.model || "").toUpperCase();
+ if (
+ brand.includes("DROI") ||
+ model.includes("MV-IDP5204") ||
+ model.includes("IDP")
+ ) {
+ return { action: "com.service.scanner.data", extraKey: "ScanCode" };
+ }
+ } catch (e) {}
if (this.action && this.extraKey) {
return { action: this.action, extraKey: this.extraKey };
}
- const brand = String(sys?.brand || "").toUpperCase();
- const model = String(sys?.model || "").toUpperCase();
-
- if (
- brand.includes("DROI") ||
- model.includes("MV-IDP5204") ||
- model.includes("IDP")
- ) {
- return { action: "com.service.scanner.data", extraKey: "ScanCode" };
- }
-
- return { action: "", extraKey: "" };
+ return { action: "com.service.scanner.data", extraKey: "ScanCode" };
},
init() {
if (!this.canUseAndroidBroadcast()) return;
@@ -86,14 +125,157 @@
"android.content.IntentFilter"
);
intentFilter = new IntentFilter();
- intentFilter.addAction(action);
+ const pickActions = v => {
+ const list = [];
+ if (v) {
+ String(v)
+ .split(/[,\s]+/)
+ .map(s => s.trim())
+ .filter(Boolean)
+ .forEach(a => list.push(a));
+ }
+ [
+ "com.service.scanner.data",
+ "com.scanner.broadcast",
+ "com.android.scanner.broadcast",
+ "com.seuic.scanner.data",
+ "com.android.scanner.receiver",
+ "com.android.scanner.result",
+ "com.rfid.SCAN",
+ "com.honeywell.decode.intent.action",
+ "com.symbol.datawedge.data",
+ "com.symbol.datawedge.api.RESULT_ACTION",
+ "com.datalogic.decodewedge.decode_action",
+ "android.intent.ACTION_DECODE_DATA",
+ "android.intent.action.SCANRESULT",
+ "android.intent.action.DECODE_DATA",
+ "scan.rcv.message",
+ ].forEach(a => {
+ if (!list.includes(a)) list.push(a);
+ });
+ return list;
+ };
+
+ const actions = pickActions(action);
+ actions.forEach(a => intentFilter.addAction(a));
+
+ const pickExtraKeys = key => {
+ const list = [];
+ if (key) {
+ String(key)
+ .split(/[,\s]+/)
+ .map(s => s.trim())
+ .filter(Boolean)
+ .forEach(k => list.push(k));
+ }
+ [
+ "ScanCode",
+ "scanCode",
+ "barcode",
+ "barCode",
+ "data",
+ "DATA",
+ "code",
+ "CODE",
+ "result",
+ "RESULT",
+ "scannerdata",
+ "decode_data",
+ "SCAN_RESULT",
+ "data_string",
+ "com.symbol.datawedge.data_string",
+ "com.symbol.datawedge.label_type",
+ ].forEach(k => {
+ if (!list.includes(k)) list.push(k);
+ });
+ return list;
+ };
+
+ const extraKeys = pickExtraKeys(extraKey);
receiver = plus.android.implements(
"io.dcloud.feature.internal.reflect.BroadcastReceiver",
{
onReceive(context, intent) {
plus.android.importClass(intent);
- const code = intent.getStringExtra(extraKey);
+ let code = "";
+ for (let i = 0; i < extraKeys.length; i++) {
+ const k = extraKeys[i];
+ try {
+ const v = intent.getStringExtra(k);
+ if (v) {
+ code = v;
+ break;
+ }
+ } catch (e) {}
+ try {
+ const bytes = intent.getByteArrayExtra(k);
+ if (bytes && bytes.length) {
+ const JString = plus.android.importClass("java.lang.String");
+ code = new JString(bytes);
+ if (code) break;
+ }
+ } catch (e) {}
+ }
+ if (!code) {
+ try {
+ const ds = intent.getDataString();
+ if (ds) code = ds;
+ } catch (e) {}
+ }
+ if (!code) {
+ try {
+ const extras = intent.getExtras();
+ if (extras) {
+ plus.android.importClass(extras);
+ const keySet = extras.keySet();
+ if (keySet) {
+ plus.android.importClass(keySet);
+ const it = keySet.iterator();
+ if (it) {
+ plus.android.importClass(it);
+ while (it.hasNext()) {
+ const k = it.next();
+ const ks = String(k);
+ let v = "";
+ try {
+ v = extras.getString(ks);
+ } catch (e) {}
+ if (!v) {
+ try {
+ const any = extras.get(ks);
+ if (any != null) v = String(any);
+ } catch (e) {}
+ }
+ const text = (v == null ? "" : String(v))
+ .replace(/\n/g, "")
+ .trim();
+ if (
+ text &&
+ text.length >= 3 &&
+ text.length <= 300 &&
+ /[0-9A-Za-z]/.test(text) &&
+ !text.includes("android.") &&
+ !text.includes("com.")
+ ) {
+ code = text;
+ break;
+ }
+ if (
+ !code &&
+ text &&
+ text.length >= 3 &&
+ text.length <= 300 &&
+ /[0-9A-Za-z]/.test(text)
+ ) {
+ code = text;
+ }
+ }
+ }
+ }
+ }
+ } catch (e) {}
+ }
_this.emitCode(code);
},
}
@@ -106,9 +288,15 @@
try {
mainActivity.registerReceiver(receiver, intentFilter);
isRegistered = true;
- } catch (e) {}
+ } catch (e) {
+ isRegistered = false;
+ }
},
stop() {
+ if (this._ensureTimer) {
+ clearInterval(this._ensureTimer);
+ this._ensureTimer = null;
+ }
if (!this.canUseAndroidBroadcast()) return;
if (!mainActivity || !receiver) return;
if (!isRegistered) return;
--
Gitblit v1.9.3