feat:模具查询-扫一扫功能

master
黄伟杰 1 month ago
parent 93da020626
commit 0d173acd51

@ -31,10 +31,7 @@
<view class="corner corner-br"></view>
</view>
</view>
<text class="scanning-text">正在扫描中...</text>
<view class="progress-bar">
<view class="progress-fill" :style="{ width: scanProgress + '%' }"></view>
</view>
<text class="scanning-text">正在打开扫码...</text>
</view>
</view>
@ -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;

@ -14,6 +14,8 @@
"moduleResolution": "node",
"module": "ES2022",
"lib": ["ES2020", "dom"],
"types": ["node"],
"skipLibCheck": true,
"declaration": true,
"paths": {
"@": ["src"],

Loading…
Cancel
Save