From b83e8417c341636a6da3a8eb7db7c151ef3c00cd Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期二, 04 十一月 2025 15:34:40 +0800
Subject: [PATCH] 巡查菜单权限设置
---
src/App.vue | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/src/App.vue b/src/App.vue
index 220abd9..e1a44ed 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,22 +1,81 @@
<script setup lang="ts">
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import { useThemeStore } from "@/store";
+import { ref } from "vue";
// 涓婚鍒濆鍖�
const themeStore = useThemeStore();
+
+// 鍏ㄥ眬鎵爜骞挎挱鎺ユ敹鍣�
+let main: any = null;
+let receiver: any = null;
+let filter: any = null;
+
+// 鍒濆鍖栨壂鐮佸箍鎾帴鏀�
+const initGlobalScan = () => {
+ // #ifdef APP-PLUS
+ try {
+ main = plus.android.runtimeMainActivity();
+ const IntentFilter = plus.android.importClass("android.content.IntentFilter");
+ filter = new IntentFilter();
+ filter.addAction("com.dwexample.ACTION");
+
+ receiver = plus.android.implements("io.dcloud.feature.internal.reflect.BroadcastReceiver", {
+ onReceive: (context: any, intent: any) => {
+ console.log("馃攳 [鍏ㄥ眬Scan] onReceive 瑙﹀彂:", context, intent);
+ plus.android.importClass(intent);
+ const scanResult = intent.getStringExtra("com.motorolasolutions.emdk.datawedge.data_string");
+ console.log("馃攳 [鍏ㄥ眬Scan] 鎵弿缁撴灉:", scanResult);
+
+ // 鍙戦�佸埌鎵�鏈夊彲鑳界殑浜嬩欢
+ const eventNames = ["scan", "scanIndex", "scanJX", "scanLS"];
+ eventNames.forEach((eventName) => {
+ uni.$emit(eventName, { code: scanResult });
+ console.log(`馃攳 [鍏ㄥ眬Scan] 宸插彂閫� ${eventName} 浜嬩欢`);
+ });
+ },
+ });
+
+ // 娉ㄥ唽骞挎挱鎺ユ敹鍣�
+ main.registerReceiver(receiver, filter);
+ console.log("馃攳 [鍏ㄥ眬Scan] 鍏ㄥ眬鎵爜骞挎挱鎺ユ敹鍣ㄥ凡鍚姩");
+ } catch (error) {
+ console.error("馃攳 [鍏ㄥ眬Scan] 鍒濆鍖栧け璐�:", error);
+ }
+ // #endif
+};
+
+// 鍋滄鎵爜骞挎挱鎺ユ敹
+const stopGlobalScan = () => {
+ // #ifdef APP-PLUS
+ try {
+ if (main && receiver) {
+ main.unregisterReceiver(receiver);
+ console.log("馃攳 [鍏ㄥ眬Scan] 鍏ㄥ眬鎵爜骞挎挱鎺ユ敹鍣ㄥ凡鍋滄");
+ }
+ } catch (error) {
+ console.error("馃攳 [鍏ㄥ眬Scan] 鍋滄澶辫触:", error);
+ }
+ // #endif
+};
onLaunch(() => {
console.log("App Launch");
// 鍒濆鍖栦富棰�
themeStore.initTheme();
+ // 鍒濆鍖栧叏灞�鎵爜骞挎挱鎺ユ敹鍣�
+ initGlobalScan();
});
onShow(() => {
console.log("App Show");
+ // 搴旂敤鏄剧ず鏃堕噸鏂板惎鍔ㄥ箍鎾帴鏀跺櫒
+ initGlobalScan();
});
onHide(() => {
console.log("App Hide");
+ // 搴旂敤闅愯棌鏃朵笉鍋滄骞挎挱锛堜繚鎸佸悗鍙版帴鏀讹級
});
</script>
--
Gitblit v1.9.3