| | |
| | | action: "scan", |
| | | }, |
| | | { |
| | | label: "扫码查设备", |
| | | icon: "/static/images/icon/saomashebei.svg", |
| | | action: "scanDevice", |
| | | }, |
| | | { |
| | | label: "设备巡检", |
| | | icon: "/static/images/icon/xunjianshangchuan.svg", |
| | | route: "/pages/inspectionUpload/index", |
| | |
| | | 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") { |
| | | // 生产报工 - 调用扫码 |
| | |
| | | console.error("扫码失败:", err); |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | if (item?.action === "scanDevice") { |
| | | scanDevice(); |
| | | return; |
| | | } |
| | | if (!item?.route) return; |
| | |
| | | allowedMenuTitles.value = titles; |
| | | |
| | | quickTools.value = quickToolSource.filter((item) => |
| | | titles.has(item.label) |
| | | item.action === "scanDevice" || titles.has(item.label) |
| | | ); |
| | | } |
| | | |