Преглед изворни кода

fix: 扫码deviceId提取逻辑与haha-mp保持一致

- 三档回退: URL路径提取 → JSON解析 → 原始值
- 格式: /([A-Z0-9]+) 匹配路径末尾设备SN
- 与客户小程序ha!a-mp扫码开门保持同一解析逻辑

Co-Authored-By: Claude <noreply@anthropic.com>
skyline пре 3 дана
родитељ
комит
61c7adadfb
1 измењених фајлова са 19 додато и 9 уклоњено
  1. 19 9
      haha-admin-mp/src/pages/replenish/home.vue

+ 19 - 9
haha-admin-mp/src/pages/replenish/home.vue

@@ -89,17 +89,27 @@ const handleScan = () => {
     onlyFromCamera: true,
     scanType: ['qrCode', 'barCode'],
     success: (res: any) => {
-      const result = (res.result || '').trim();
-      if (!result) {
-        uni.showToast({ title: '未识别到设备ID', icon: 'none' });
+      // 与 haha-mp 一致的 deviceId 提取逻辑
+      let deviceId = '';
+      try {
+        const urlPattern = /\/([A-Z0-9]+)(\?|$)/;
+        const match = res.result.match(urlPattern);
+        if (match && match[1]) {
+          deviceId = match[1];
+        } else {
+          try {
+            const qrData = JSON.parse(res.result);
+            if (qrData.deviceId) deviceId = qrData.deviceId;
+          } catch (e) {
+            deviceId = res.result;
+          }
+        }
+        if (!deviceId) throw new Error('无法解析设备ID');
+      } catch (error) {
+        uni.showToast({ title: '二维码格式错误', icon: 'none' });
         return;
       }
-      // 提取设备ID(支持直接扫描设备SN或URL中的设备ID参数)
-      let deviceId = result;
-      if (result.includes('deviceId=')) {
-        const match = result.match(/deviceId=([^&\s]+)/);
-        if (match) deviceId = match[1];
-      }
+
       uni.showActionSheet({
         itemList: ['设备补货', '库存盘点'],
         success: (sheetRes) => {