zhangwencui
2026-07-09 9f1324fb9e73e5b53ac67542227e63cdc0b505ba
src/pages/equipmentManagement/upkeep/add.vue
@@ -85,6 +85,8 @@
                        @confirm="onDateConfirm"
                        @cancel="showDate = false"
                        mode="date" />
    <PdaScan :active="pdaScanActive"
             eventName="scan_upkeep_device" />
  </view>
</template>
@@ -93,6 +95,7 @@
  import { onShow } from "@dcloudio/uni-app";
  import PageHeader from "@/components/PageHeader.vue";
  import CommonUpload from "@/components/CommonUpload.vue";
  import PdaScan from "@/components/pda-scan/pda-scan.vue";
  import { getDeviceLedger } from "@/api/equipmentManagement/ledger";
  import {
    addUpkeep,
@@ -140,6 +143,8 @@
  // 扫码相关状态
  const isScanning = ref(false);
  const scanTimer = ref(null);
  const pdaScanActive = ref(false);
  const pdaScanTimer = ref(null);
  // 表单验证规则
  const formRules = {
@@ -210,7 +215,51 @@
      return;
    }
    // 调用uni-app的扫码API
    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);
      });
      pdaScanActive.value = true;
      uni.showToast({ title: "请使用PDA扫码", icon: "none" });
      pdaScanTimer.value = setTimeout(() => {
        pdaScanActive.value = false;
        uni.$off("scan_upkeep_device");
        pdaScanTimer.value = null;
      }, 20000);
      return;
    }
    uni.scanCode({
      scanType: ["qrCode", "barCode"],
      success: res => {
@@ -309,6 +358,10 @@
    if (scanTimer.value) {
      clearTimeout(scanTimer.value);
    }
    if (pdaScanTimer.value) {
      clearTimeout(pdaScanTimer.value);
    }
    uni.$off("scan_upkeep_device");
  });
  // 提交表单
@@ -441,4 +494,4 @@
    margin-left: 8px;
    cursor: pointer;
  }
</style>
</style>