style:功能导航-扫一扫添加二维码类型判断

master
黄伟杰 1 month ago
parent f8082bd587
commit 1514cdf7b4

@ -57,6 +57,19 @@ import AppTitleHeader from '@/components/common/AppTitleHeader.vue'
const equipmentCode = ref('');
const isScanning = ref(false);
const SCAN_TYPE = 'EQUIPMENT';
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;
@ -71,12 +84,16 @@ function startScan() {
onlyFromCamera: true,
scanType: ['qrCode', 'barCode'],
success: (res) => {
const info = JSON.parse(res.result)
if (!info || !info.id) {
const { type, id } = parseScanResult(res);
if (!type || !id) {
uni.showToast({ title: '未获取到扫码结果', icon: 'none' })
return
}
navigateToDetail(info.id)
if (type !== SCAN_TYPE) {
uni.showToast({ title: `二维码类型不匹配,请扫描${MODULE_NAME}二维码`, icon: 'none' })
return
}
navigateToDetail(id)
},
fail: (err) => {
const msg = String(err?.errMsg || '')

@ -57,6 +57,19 @@ import AppTitleHeader from '@/components/common/AppTitleHeader.vue'
const keypartCode = ref('');
const isScanning = ref(false);
const SCAN_TYPE = 'KEY_PART';
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;
@ -71,12 +84,16 @@ function startScan() {
onlyFromCamera: true,
scanType: ['qrCode', 'barCode'],
success: (res) => {
const info = JSON.parse(res.result)
if (!info || !info.id) {
const { type, id } = parseScanResult(res);
if (!type || !id) {
uni.showToast({ title: '未获取到扫码结果', icon: 'none' })
return
}
navigateToDetail(info.id)
if (type !== SCAN_TYPE) {
uni.showToast({ title: `二维码类型不匹配,请扫描${MODULE_NAME}二维码`, icon: 'none' })
return
}
navigateToDetail(id)
},
fail: (err) => {
const msg = String(err?.errMsg || '')

@ -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)}`
});

@ -57,6 +57,19 @@ import AppTitleHeader from '@/components/common/AppTitleHeader.vue'
const productId = ref('')
const isScanning = ref(false)
const SCAN_TYPE = 'PRODUCTMATERIAL'
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
@ -68,12 +81,16 @@ function startScan() {
onlyFromCamera: true,
scanType: ['qrCode', 'barCode'],
success: (res) => {
const info = JSON.parse(res.result)
if (!info || !info.id) {
const { type, id } = parseScanResult(res)
if (!type || !id) {
uni.showToast({ title: '未获取到扫码结果', icon: 'none' })
return
}
navigateToDetail(info.id)
if (type !== SCAN_TYPE) {
uni.showToast({ title: `二维码类型不匹配,请扫描${MODULE_NAME}二维码`, icon: 'none' })
return
}
navigateToDetail(id)
},
fail: (err) => {
const msg = String(err?.errMsg || '')

@ -57,6 +57,19 @@ import AppTitleHeader from '@/components/common/AppTitleHeader.vue'
const spareCode = ref('');
const isScanning = ref(false);
const SCAN_TYPE = 'SPARE';
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;
@ -71,12 +84,16 @@ function startScan() {
onlyFromCamera: true,
scanType: ['qrCode', 'barCode'],
success: (res) => {
const info = JSON.parse(res.result)
if (!info || !info.id) {
const { type, id } = parseScanResult(res);
if (!type || !id) {
uni.showToast({ title: '未获取到扫码结果', icon: 'none' })
return
}
navigateToDetail(info.id);
if (type !== SCAN_TYPE) {
uni.showToast({ title: `二维码类型不匹配,请扫描${MODULE_NAME}二维码`, icon: 'none' })
return
}
navigateToDetail(id);
},
fail: (err) => {
const msg = String(err?.errMsg || '')

Loading…
Cancel
Save