gaoluyang
2026-08-28 3f85e5410dda49e7e6a6292859649513f3644cb2
src/pages/works.vue
@@ -656,6 +656,10 @@
    //    label: '设备台账',
    // },
    {
      icon: "/static/images/icon/saomashebei.svg",
      label: "扫码查设备",
    },
    {
      icon: "/static/images/icon/yunxingguanli.svg",
      label: "运行管理",
    },
@@ -672,6 +676,42 @@
      label: "设备巡检",
    },
  ]);
  // 扫码查设备:解析 deviceId 后跳转到设备信息页
  const 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;
  };
  const startScanDevice = () => {
    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" });
      },
    });
  };
  // 处理常用功能点击
  const handleCommonItemClick = item => {
@@ -938,6 +978,9 @@
        uni.navigateTo({
          url: "/pages/equipmentManagement/ledger/index",
        });
        break;
      case "扫码查设备":
        startScanDevice();
        break;
      case "运行管理":
        uni.navigateTo({
@@ -1258,7 +1301,7 @@
    // 收集所有有权限的菜单标题(根据 meta.title)
    const allowedMenuTitles = new Set();
    const alwaysShowTitles = new Set(["采购退货单", "供应商管理"]);
    const alwaysShowTitles = new Set(["采购退货单", "供应商管理", "扫码查设备"]);
    const collectMenuTitles = routes => {
      if (!Array.isArray(routes)) return;
      routes.forEach(route => {
@@ -1284,6 +1327,7 @@
    // 通用过滤函数
    const filterArray = (targetArray, specialMapping) => {
      const filtered = targetArray.filter(item => {
        if (alwaysShowTitles.has(item.label)) return true;
        let matched = allowedMenuTitles.has(item.label);
        if (specialMapping && !matched && specialMapping[item.label]) {
          matched = allowedMenuTitles.has(specialMapping[item.label]);