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

master
黄伟杰 2 months ago
parent 93da020626
commit 0d173acd51

@ -31,10 +31,7 @@
<view class="corner corner-br"></view> <view class="corner corner-br"></view>
</view> </view>
</view> </view>
<text class="scanning-text">正在扫描中...</text> <text class="scanning-text">正在打开扫码...</text>
<view class="progress-bar">
<view class="progress-fill" :style="{ width: scanProgress + '%' }"></view>
</view>
</view> </view>
</view> </view>
@ -68,7 +65,6 @@ import { ref } from 'vue';
const moldCode = ref(''); const moldCode = ref('');
const isScanning = ref(false); const isScanning = ref(false);
const scanProgress = ref(0);
function goBack() { function goBack() {
uni.navigateBack(); uni.navigateBack();
@ -76,27 +72,38 @@ function goBack() {
function startScan() { function startScan() {
if (isScanning.value) return; if (isScanning.value) return;
isScanning.value = true; isScanning.value = true;
scanProgress.value = 0;
const finish = () => {
const duration = 2000; isScanning.value = false;
const interval = 50; }
const steps = duration / interval;
let currentStep = 0; uni.scanCode({
onlyFromCamera: true,
const timer = setInterval(() => { scanType: ['qrCode', 'barCode'],
currentStep++; success: (res) => {
scanProgress.value = Math.min((currentStep / steps) * 100, 100); const code = String(res?.result || res?.code || res?.qrCode || res?.barCode || '').trim()
if (!code) {
if (currentStep >= steps) { uni.showToast({ title: '未获取到扫码结果', icon: 'none' })
clearInterval(timer); return
setTimeout(() => { }
isScanning.value = false; navigateToDetail(code)
navigateToDetail('MOLD-SCAN-001'); },
}, 200); fail: (err) => {
} const msg = String(err?.errMsg || '')
}, interval); 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() { function confirmInput() {
@ -317,21 +324,6 @@ function navigateToDetail(code) {
margin-bottom: 30rpx; 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 { .divider {
display: flex; display: flex;
align-items: center; align-items: center;

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

Loading…
Cancel
Save