From b3cfcdd210536fa672b36e37b0f54bb9c4e98ada Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期五, 20 六月 2025 14:22:13 +0800
Subject: [PATCH] feat(tabbar): 二维码扫描功能适配 H5 端- 在 fg-tabbar 组件中添加了对 H5 端二维码扫描的支持 - 引入 qrcode 解析库以处理 H5 端的二维码扫描结果 - 根据平台类型(app 或 H5)选择不同的扫描方式

---
 eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue |   66 ++++++++++++++++++++++++++++----
 1 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue b/eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue
index e8d12de..59233d0 100644
--- a/eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue
+++ b/eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue
@@ -6,7 +6,7 @@
     safeAreaInsetBottom
     placeholder
     @change="selectTabBar"
-    active-color="#007aff"
+    active-color="#4D80F0"
     inactive-color="#7d7e80"
   >
     <block v-for="(item, idx) in tabbarList" :key="item.path">
@@ -53,6 +53,7 @@
 // i-carbon-code
 import { tabBar } from '@/pages.json'
 import { tabbarStore } from './tabbar'
+import qrcode from "@/utils/qrcode";
 
 /** tabbarList 閲岄潰鐨� path 浠� pages.config.ts 寰楀埌 */
 const tabbarList = tabBar.list.map((item) => ({ ...item, path: `/${item.pagePath}` }))
@@ -62,14 +63,61 @@
   // scan鐗规畩澶勭悊
   if (index === 2) {
     tabbarStore.setCurIdx(tabbarStore.lastIdx)
-    // 鍙厑璁搁�氳繃鐩告満鎵爜
-    uni.scanCode({
-      onlyFromCamera: true,
-      success: function (res) {
-        console.log('鏉$爜绫诲瀷锛�' + res.scanType)
-        console.log('鏉$爜鍐呭锛�' + res.result)
-      },
-    })
+
+    // 妯℃嫙鎴愬姛
+    // uni.navigateTo({
+    //   url: `/pages/scan/index?result=GPA2024NL025`,
+    // })
+    // return false
+    // 妯℃嫙鎴愬姛
+    const systemInfo = uni.getSystemInfoSync()
+    if (systemInfo.uniPlatform === 'app') {
+      // 鍙厑璁搁�氳繃鐩告満鎵爜
+      uni.scanCode({
+        onlyFromCamera: true,
+        success: function(res) {
+          console.log('鏉$爜绫诲瀷锛�' + res.scanType)
+          console.log('鏉$爜鍐呭锛�' + res.result)
+          if (res?.scanType !== 'QR_CODE') {
+            uni.showToast({
+              title: '璇蜂娇鐢ㄤ簩缁寸爜杩涜鎵爜',
+              icon: 'none',
+            })
+            return false
+          }
+
+          // 浣跨敤split鏂规硶鎴彇璧勪骇缂栧彿
+          // const assetCode = res.result.split('璧勪骇缂栧彿锛�')[1].split(' ')[0]
+          uni.navigateTo({
+            url: `/pages/scan/index?result=${res.result}`,
+          })
+        },
+        fail: function (res) {},
+      })
+    } else {
+      uni.chooseImage({
+        count: 1,
+        sizeType: ['original', 'compressed'],
+        sourceType: ['camera'],
+        success: function(response) {
+          qrcode.decode(response.tempFilePaths[0])
+          qrcode.callback = (res) => {
+            console.log('res', res)
+            if (res === 'error decoding QR Code') {
+              uni.showToast({
+                title: '浜岀淮鐮佽В鏋愬け璐�',
+                duration: 2000,
+                icon: 'none',
+              })
+            } else {
+              uni.navigateTo({
+                url: `/pages/scan/index?result=${res}`,
+              })
+            }
+          }
+        },
+      })
+    }
   } else {
     tabbarStore.setCurIdx(index)
     tabbarStore.setLastIdx(index)

--
Gitblit v1.9.3