|
|
|
|
@ -57,6 +57,20 @@ import AppTitleHeader from '@/components/common/AppTitleHeader.vue'
|
|
|
|
|
|
|
|
|
|
const moldCode = ref('');
|
|
|
|
|
const isScanning = ref(false);
|
|
|
|
|
const SCAN_TYPE = 'MOLD';
|
|
|
|
|
const MODULE_NAME = '模具';
|
|
|
|
|
|
|
|
|
|
function parseScanResult(res) {
|
|
|
|
|
const raw = String(res?.result || '').trim();
|
|
|
|
|
if (!raw) return {};
|
|
|
|
|
const splitIndex = raw.indexOf('-');
|
|
|
|
|
if (splitIndex <= 0 || splitIndex >= raw.length - 1) return {};
|
|
|
|
|
return {
|
|
|
|
|
type: raw.slice(0, splitIndex),
|
|
|
|
|
id: raw.slice(splitIndex + 1)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startScan() {
|
|
|
|
|
if (isScanning.value) return;
|
|
|
|
|
|
|
|
|
|
@ -67,18 +81,19 @@ function startScan() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uni.scanCode({
|
|
|
|
|
onlyFromCamera: true,
|
|
|
|
|
onlyFromCamera: false,
|
|
|
|
|
scanType: ['qrCode', 'barCode'],
|
|
|
|
|
success: (res) => {
|
|
|
|
|
console.log(res)
|
|
|
|
|
const info = JSON.parse(res.result)
|
|
|
|
|
console.log('info',info)
|
|
|
|
|
if (!info) {
|
|
|
|
|
const { type, id } = parseScanResult(res);
|
|
|
|
|
if (!type || !id) {
|
|
|
|
|
uni.showToast({ title: '未获取到扫码结果', icon: 'none' })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
console.log('info.id',info.id)
|
|
|
|
|
navigateToDetail(info.id)
|
|
|
|
|
if (type !== SCAN_TYPE) {
|
|
|
|
|
uni.showToast({ title: `二维码类型不匹配,请扫描${MODULE_NAME}二维码`, icon: 'none' })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
navigateToDetail(id)
|
|
|
|
|
},
|
|
|
|
|
fail: (err) => {
|
|
|
|
|
const msg = String(err?.errMsg || '')
|
|
|
|
|
@ -109,7 +124,6 @@ function confirmInput() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function navigateToDetail(id) {
|
|
|
|
|
console.log('id',id)
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
url: `/pages_function/pages/mold/detail?id=${encodeURIComponent(id)}`
|
|
|
|
|
});
|
|
|
|
|
|