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 | 68 +++++++++++++++++++++++---------- 1 files changed, 47 insertions(+), 21 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 c3370a9..59233d0 100644 --- a/eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue +++ b/eims-ui-mobile/src/components/fg-tabbar/fg-tabbar.vue @@ -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}` })) @@ -69,29 +70,54 @@ // }) // 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 + } - // 鍙厑璁搁�氳繃鐩告満鎵爜 - 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', + // 浣跨敤split鏂规硶鎴彇璧勪骇缂栧彿 + // const assetCode = res.result.split('璧勪骇缂栧彿锛�')[1].split(' ')[0] + uni.navigateTo({ + url: `/pages/scan/index?result=${res.result}`, }) - return false - } - - // 浣跨敤split鏂规硶鎴彇璧勪骇缂栧彿 - // const assetCode = res.result.split('璧勪骇缂栧彿锛�')[1].split(' ')[0] - uni.navigateTo({ - url: `/pages/scan/index?result=${res.result}`, - }) - }, - fail: function (res) {}, - }) + }, + 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