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"],