From 716c7c0d9c55883ed88f7cfe61557d33175cab7a Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期五, 30 十月 2026 16:19:18 +0800
Subject: [PATCH] 增加巡检扫码设备验证功能
---
src/pages/inspectionUpload/index.vue | 130 ++++++++++++++++++++++++++++++++-----------
1 files changed, 96 insertions(+), 34 deletions(-)
diff --git a/src/pages/inspectionUpload/index.vue b/src/pages/inspectionUpload/index.vue
index 80c4c76..cfec613 100644
--- a/src/pages/inspectionUpload/index.vue
+++ b/src/pages/inspectionUpload/index.vue
@@ -316,10 +316,11 @@
};
// 涓烘寚瀹氫换鍔″紑濮嬫壂鐮侊紙鐪熸満锛�
- const startScanForTask = async task => {
+ const startScanForTask = task => {
try {
currentScanningTask.value = task;
uni.scanCode({
+ scanType: ["qrCode", "barCode"],
success: res => {
handleScanSuccess(res);
},
@@ -341,48 +342,109 @@
};
// 鎵爜鎴愬姛澶勭悊锛氭牎楠屽悗鎵撳紑涓婁紶寮圭獥
- const handleScanSuccess = result => {
- try {
- // 瑙f瀽浜岀淮鐮佹暟鎹紝鎻愬彇deviceId
- let deviceId = "";
+ const getScannedDeviceId = scanResult => {
+ if (!scanResult || typeof scanResult !== "string") return "";
- if (result?.result && typeof result.result === "string") {
- if (result.result.includes("deviceId=")) {
- const match = result.result.match(/deviceId=(\d+)/);
- if (match && match[1]) deviceId = match[1];
- } else {
- try {
- const qrData = JSON.parse(result.result);
- deviceId = qrData.deviceId || qrData.qrCodeId || "";
- } catch (e) {
- deviceId = result.result;
- }
- }
- }
+ const value = scanResult.trim();
+ const urlMatch = value.match(/[?&]deviceId=([^&#]+)/i);
+ if (urlMatch?.[1]) {
+ return decodeURIComponent(urlMatch[1]).trim();
+ }
+
+ try {
+ const qrData = JSON.parse(value);
+ return String(
+ qrData?.deviceId ??
+ qrData?.deviceLedgerId ??
+ qrData?.data?.deviceId ??
+ ""
+ ).trim();
+ } catch (e) {
+ // 鍏煎鍙瓨鏀捐澶嘔D鐨勪簩缁寸爜/鏉″舰鐮�
+ return /^\d+$/.test(value) ? value : "";
+ }
+ };
+
+ const getTaskDeviceIdentity = task => {
+ const id =
+ task?.deviceLedgerId ??
+ task?.deviceId ??
+ task?.ledgerId ??
+ task?.equipmentId ??
+ task?.deviceLedger?.id ??
+ task?.device?.id;
+ const code =
+ task?.deviceCode ??
+ task?.equipmentCode ??
+ task?.deviceLedger?.deviceCode ??
+ task?.device?.deviceCode;
+ const name =
+ task?.deviceName ??
+ task?.equipmentName ??
+ task?.deviceLedger?.deviceName ??
+ task?.device?.deviceName ??
+ task?.taskName;
+
+ return { id, code, name };
+ };
+
+ const isTaskDevice = (task, device, scannedDeviceId) => {
+ const expected = getTaskDeviceIdentity(task);
+
+ if (
+ expected.id !== undefined &&
+ expected.id !== null &&
+ expected.id !== ""
+ ) {
+ return String(expected.id) === String(device?.id ?? scannedDeviceId);
+ }
+ if (expected.code && device?.deviceCode) {
+ return String(expected.code).trim() === String(device.deviceCode).trim();
+ }
+ if (expected.name && device?.deviceName) {
+ return String(expected.name).trim() === String(device.deviceName).trim();
+ }
+
+ return false;
+ };
+
+ const handleScanSuccess = async result => {
+ try {
+ const deviceId = getScannedDeviceId(result?.result);
if (!deviceId) {
- uni.showToast({ title: "鏈瘑鍒埌璁惧ID", icon: "error" });
+ uni.showToast({ title: "鏈瘑鍒埌璁惧鐮�", icon: "none" });
return;
}
- const currentTaskId =
- currentScanningTask.value?.taskId || currentScanningTask.value?.id;
- if (!currentTaskId) {
- uni.showToast({ title: "浠诲姟淇℃伅缂哄け", icon: "error" });
+ const task = currentScanningTask.value;
+ if (!task) {
+ uni.showToast({ title: "宸℃浠诲姟淇℃伅缂哄け", icon: "none" });
return;
}
- if (deviceId === currentTaskId.toString()) {
- uni.showToast({ title: "璇嗗埆鎴愬姛", icon: "success" });
- openUploadDialog(currentScanningTask.value);
- } else {
- uni.showToast({ title: "璇锋壂鎻忔纭殑璁惧", icon: "error" });
+ uni.showLoading({ title: "姝e湪楠岃瘉璁惧...", mask: true });
+ const { code, data } = await getLedgerById(deviceId);
+ uni.hideLoading();
+
+ if (code !== 200 || !data) {
+ uni.showToast({ title: "鏈壘鍒拌璁惧", icon: "none" });
+ return;
}
+
+ if (!isTaskDevice(task, data, deviceId)) {
+ uni.showToast({ title: "璁惧涓嶅尮閰嶏紝璇锋壂鎻忓綋鍓嶅贰妫�璁惧", icon: "none" });
+ return;
+ }
+
+ uni.showToast({ title: "璁惧楠岃瘉鎴愬姛", icon: "success" });
+ setTimeout(() => openUploadDialog(task), 300);
} catch (error) {
+ uni.hideLoading();
console.error("鎵爜缁撴灉澶勭悊澶辫触:", error);
uni.showToast({
- title: error?.message || "鏁版嵁瑙f瀽澶辫触",
- icon: "error",
+ title: error?.message || "璁惧楠岃瘉澶辫触",
+ icon: "none",
});
}
};
@@ -397,9 +459,9 @@
};
// 鍥剧墖涓婁紶(鍙�夋嫨鍥剧墖涓婁紶鎴栬�呮槸鐩告満鎷嶇収)
- const startUploadForTask = async (task, type) => {
- // 鎵撳紑涓婁紶椤甸潰
- openUploadDialog(task);
+ const startUploadForTask = task => {
+ // 涓婁紶鍓嶅繀椤诲厛鎵爜楠岃瘉褰撳墠璁惧
+ startScanForTask(task);
};
// 鏌ョ湅闄勪欢 - 璺宠浆鍒伴檮浠堕〉闈�
@@ -765,4 +827,4 @@
max-height: 60vh;
display: block;
}
-</style>
\ No newline at end of file
+</style>
--
Gitblit v1.9.3