From 0d173acd51210b78c5ef0e0e41028fec05c2d769 Mon Sep 17 00:00:00 2001 From: hwj Date: Wed, 25 Mar 2026 11:51:16 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=A8=A1=E5=85=B7=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2-=E6=89=AB=E4=B8=80=E6=89=AB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages_function/pages/mold/index.vue | 72 +++++++++++-------------- tsconfig.json | 2 + 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/pages_function/pages/mold/index.vue b/src/pages_function/pages/mold/index.vue index b20892a..55b72fb 100644 --- a/src/pages_function/pages/mold/index.vue +++ b/src/pages_function/pages/mold/index.vue @@ -31,10 +31,7 @@ - 正在扫描中... - - - + 正在打开扫码... @@ -68,7 +65,6 @@ import { ref } from 'vue'; const moldCode = ref(''); const isScanning = ref(false); -const scanProgress = ref(0); function goBack() { uni.navigateBack(); @@ -76,27 +72,38 @@ function goBack() { function startScan() { if (isScanning.value) return; - + isScanning.value = true; - scanProgress.value = 0; - - const duration = 2000; - const interval = 50; - const steps = duration / interval; - let currentStep = 0; - - const timer = setInterval(() => { - currentStep++; - scanProgress.value = Math.min((currentStep / steps) * 100, 100); - - if (currentStep >= steps) { - clearInterval(timer); - setTimeout(() => { - isScanning.value = false; - navigateToDetail('MOLD-SCAN-001'); - }, 200); - } - }, interval); + + const finish = () => { + isScanning.value = false; + } + + uni.scanCode({ + onlyFromCamera: true, + scanType: ['qrCode', 'barCode'], + success: (res) => { + const code = String(res?.result || res?.code || res?.qrCode || res?.barCode || '').trim() + if (!code) { + uni.showToast({ title: '未获取到扫码结果', icon: 'none' }) + return + } + navigateToDetail(code) + }, + fail: (err) => { + const msg = String(err?.errMsg || '') + if (msg.includes('cancel')) { + uni.showToast({ title: '已取消扫码', icon: 'none' }) + return + } + if (msg.toLowerCase().includes('not support') || msg.toLowerCase().includes('not supported')) { + uni.showToast({ title: '当前平台不支持扫码', icon: 'none' }) + return + } + uni.showToast({ title: '扫码失败', icon: 'none' }) + }, + complete: finish + }) } function confirmInput() { @@ -317,21 +324,6 @@ function navigateToDetail(code) { margin-bottom: 30rpx; } -.progress-bar { - width: 400rpx; - height: 8rpx; - background: rgba(255, 255, 255, 0.2); - border-radius: 4rpx; - overflow: hidden; -} - -.progress-fill { - height: 100%; - background: #ff8c00; - border-radius: 4rpx; - transition: width 0.05s linear; -} - .divider { display: flex; align-items: center; diff --git a/tsconfig.json b/tsconfig.json index a2e32ae..80c4289 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,8 @@ "moduleResolution": "node", "module": "ES2022", "lib": ["ES2020", "dom"], + "types": ["node"], + "skipLibCheck": true, "declaration": true, "paths": { "@": ["src"],