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/pages/equipmentManagement/upkeep/add.vue |  147 +++++++++++++++++++++++++++++--------------------
 1 files changed, 87 insertions(+), 60 deletions(-)

diff --git a/src/pages/equipmentManagement/upkeep/add.vue b/src/pages/equipmentManagement/upkeep/add.vue
index 457b265..a42b362 100644
--- a/src/pages/equipmentManagement/upkeep/add.vue
+++ b/src/pages/equipmentManagement/upkeep/add.vue
@@ -85,8 +85,9 @@
                         @confirm="onDateConfirm"
                         @cancel="showDate = false"
                         mode="date" />
-    <PdaScan :active="pdaScanActive"
-             eventName="scan_upkeep_device" />
+    <ScanWaitMask :show="scanMaskShow"
+                  :status="scanMaskStatus" />
+    <PdaScan />
   </view>
 </template>
 
@@ -95,6 +96,7 @@
   import { onShow } from "@dcloudio/uni-app";
   import PageHeader from "@/components/PageHeader.vue";
   import CommonUpload from "@/components/CommonUpload.vue";
+  import ScanWaitMask from "@/components/ScanWaitMask.vue";
   import PdaScan from "@/components/pda-scan/pda-scan.vue";
   import { getDeviceLedger } from "@/api/equipmentManagement/ledger";
   import {
@@ -143,8 +145,51 @@
   // 鎵爜鐩稿叧鐘舵��
   const isScanning = ref(false);
   const scanTimer = ref(null);
-  const pdaScanActive = ref(false);
-  const pdaScanTimer = ref(null);
+  const pendingDeviceScan = ref(false);
+  let pendingDeviceScanTimer = null;
+  const scanMaskShow = ref(false);
+  const scanMaskStatus = ref("waiting");
+  const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
+
+  const canUsePdaBroadcast = () => {
+    try {
+      if (typeof plus === "undefined") return false;
+      if (plus?.os?.name !== "Android") return false;
+      if (!plus?.android) return false;
+
+      const sys = uni.getSystemInfoSync?.() || {};
+      const brand = String(sys?.brand || "").toUpperCase();
+      const model = String(sys?.model || "").toUpperCase();
+
+      return (
+        brand.includes("DROI") ||
+        model.includes("MV-IDP5204") ||
+        model.includes("IDP")
+      );
+    } catch (e) {
+      return false;
+    }
+  };
+
+  onShow(() => {
+    uni.$off("scan");
+    uni.$on("scan", data => {
+      console.log("onscan");
+      console.log("鎵爜缁撴灉锛�", data.code);
+      if (!pendingDeviceScan.value) return;
+      pendingDeviceScan.value = false;
+      scanMaskStatus.value = "done";
+      if (pendingDeviceScanTimer) {
+        clearTimeout(pendingDeviceScanTimer);
+        pendingDeviceScanTimer = null;
+      }
+      delay(350).then(() => {
+        scanMaskShow.value = false;
+        processScanResult(data.code);
+      });
+    });
+    getPageParams();
+  });
 
   // 琛ㄥ崟楠岃瘉瑙勫垯
   const formRules = {
@@ -210,62 +255,47 @@
 
   // 鎵弿浜岀淮鐮佸姛鑳�
   const startScan = () => {
-    if (isScanning.value) {
-      showToast("姝e湪鎵弿涓紝璇风◢鍊�...");
-      return;
+    pendingDeviceScan.value = true;
+    scanMaskStatus.value = "waiting";
+    scanMaskShow.value = true;
+    if (pendingDeviceScanTimer) {
+      clearTimeout(pendingDeviceScanTimer);
+      pendingDeviceScanTimer = null;
     }
-
-    const canUsePdaBroadcast = () => {
-      try {
-        if (typeof plus === "undefined") return false;
-        if (plus?.os?.name !== "Android") return false;
-        if (!plus?.android) return false;
-
-        const sys = uni.getSystemInfoSync?.() || {};
-        const brand = String(sys?.brand || "").toUpperCase();
-        const model = String(sys?.model || "").toUpperCase();
-
-        return (
-          brand.includes("DROI") ||
-          model.includes("MV-IDP5204") ||
-          model.includes("IDP")
-        );
-      } catch (e) {
-        return false;
-      }
-    };
-
-    if (canUsePdaBroadcast()) {
-      if (pdaScanTimer.value) {
-        clearTimeout(pdaScanTimer.value);
-        pdaScanTimer.value = null;
-      }
-      uni.$off("scan_upkeep_device");
-      uni.$on("scan_upkeep_device", data => {
-        pdaScanActive.value = false;
-        uni.$off("scan_upkeep_device");
-        if (pdaScanTimer.value) {
-          clearTimeout(pdaScanTimer.value);
-          pdaScanTimer.value = null;
-        }
-        handleScanResult(data?.code);
+    pendingDeviceScanTimer = setTimeout(() => {
+      pendingDeviceScan.value = false;
+      pendingDeviceScanTimer = null;
+      scanMaskStatus.value = "timeout";
+      delay(900).then(() => {
+        scanMaskShow.value = false;
       });
-      pdaScanActive.value = true;
-      uni.showToast({ title: "璇蜂娇鐢≒DA鎵爜", icon: "none" });
-      pdaScanTimer.value = setTimeout(() => {
-        pdaScanActive.value = false;
-        uni.$off("scan_upkeep_device");
-        pdaScanTimer.value = null;
-      }, 20000);
-      return;
-    }
+    }, 20000);
 
+    if (canUsePdaBroadcast()) return;
     uni.scanCode({
       scanType: ["qrCode", "barCode"],
       success: res => {
-        handleScanResult(res.result);
+        pendingDeviceScan.value = false;
+        scanMaskStatus.value = "done";
+        if (pendingDeviceScanTimer) {
+          clearTimeout(pendingDeviceScanTimer);
+          pendingDeviceScanTimer = null;
+        }
+        delay(350).then(() => {
+          scanMaskShow.value = false;
+          handleScanResult(res.result);
+        });
       },
       fail: err => {
+        pendingDeviceScan.value = false;
+        scanMaskStatus.value = "timeout";
+        delay(900).then(() => {
+          scanMaskShow.value = false;
+        });
+        if (pendingDeviceScanTimer) {
+          clearTimeout(pendingDeviceScanTimer);
+          pendingDeviceScanTimer = null;
+        }
         console.error("鎵爜澶辫触:", err);
         showToast("鎵爜澶辫触锛岃閲嶈瘯");
       },
@@ -342,11 +372,6 @@
     showDate.value = false;
   };
 
-  onShow(() => {
-    // 椤甸潰鏄剧ず鏃惰幏鍙栧弬鏁�
-    getPageParams();
-  });
-
   onMounted(() => {
     // 椤甸潰鍔犺浇鏃惰幏鍙栬澶囧垪琛ㄥ拰鍙傛暟
     loadDeviceName();
@@ -358,10 +383,12 @@
     if (scanTimer.value) {
       clearTimeout(scanTimer.value);
     }
-    if (pdaScanTimer.value) {
-      clearTimeout(pdaScanTimer.value);
+    if (pendingDeviceScanTimer) {
+      clearTimeout(pendingDeviceScanTimer);
+      pendingDeviceScanTimer = null;
     }
-    uni.$off("scan_upkeep_device");
+    scanMaskShow.value = false;
+    uni.$off("scan");
   });
 
   // 鎻愪氦琛ㄥ崟

--
Gitblit v1.9.3