From 3f85e5410dda49e7e6a6292859649513f3644cb2 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 28 八月 2026 14:44:12 +0800
Subject: [PATCH] 天津豹鸣app 1.添加扫码查看设备变更记录功能
---
src/pages/index.vue | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 45 insertions(+), 1 deletions(-)
diff --git a/src/pages/index.vue b/src/pages/index.vue
index 2d253b2..47fd3fe 100644
--- a/src/pages/index.vue
+++ b/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)
);
}
--
Gitblit v1.9.3