gaoluyang
2026-08-28 3f85e5410dda49e7e6a6292859649513f3644cb2
src/pages/index.vue
@@ -231,6 +231,11 @@
    action: "scan",
  },
  {
    label: "扫码查设备",
    icon: "/static/images/icon/saomashebei.svg",
    action: "scanDevice",
  },
  {
    label: "设备巡检",
    icon: "/static/images/icon/xunjianshangchuan.svg",
    route: "/pages/inspectionUpload/index",
@@ -265,6 +270,41 @@
  overviewExpanded.value = !overviewExpanded.value;
}
function getDeviceIdFromScan(scanResult) {
  if (!scanResult) return null;
  const match = scanResult.match(/deviceId=(\d+)/);
  if (match && match[1]) return match[1];
  if (/^\d+$/.test(scanResult.trim())) return scanResult.trim();
  try {
    const obj = JSON.parse(scanResult);
    if (obj.deviceId) return String(obj.deviceId);
  } catch (e) {
    // 忽略非 JSON 内容
  }
  return null;
}
function scanDevice() {
  uni.scanCode({
    scanType: ["qrCode", "barCode"],
    success: (res) => {
      console.log("扫码结果:", res.result);
      const deviceId = getDeviceIdFromScan(res.result);
      if (!deviceId) {
        uni.showToast({ title: "未识别到设备ID", icon: "none" });
        return;
      }
      uni.navigateTo({
        url: `/pages/equipmentManagement/deviceInfo/index?deviceId=${deviceId}`,
      });
    },
    fail: (err) => {
      console.error("扫码失败:", err);
      uni.showToast({ title: "扫码失败,请重试", icon: "none" });
    },
  });
}
function handleQuickTool(item) {
  if (item?.action === "scan") {
    // 生产报工 - 调用扫码
@@ -286,6 +326,10 @@
        console.error("扫码失败:", err);
      }
    });
    return;
  }
  if (item?.action === "scanDevice") {
    scanDevice();
    return;
  }
  if (!item?.route) return;
@@ -322,7 +366,7 @@
  allowedMenuTitles.value = titles;
  quickTools.value = quickToolSource.filter((item) =>
    titles.has(item.label)
    item.action === "scanDevice" || titles.has(item.label)
  );
}