style: 上模/下模修复扫码

master
zhongwenkai 1 week ago
parent f09dc10301
commit 773e58c0af

@ -112,12 +112,9 @@ const deviceMoldMap = ref(new Map())
async function loadDeviceMolds() {
try {
const res = await getMoldBrandPage({ pageSize: 100 })
console.log('[deviceSelect] getMoldBrandPage 原始响应:', JSON.stringify(res))
const root = res && res.data !== undefined ? res.data : res
console.log('[deviceSelect] root 类型:', typeof root, 'keys:', Object.keys(root || {}))
const pageData = root?.pageResult || root
const list = Array.isArray(pageData) ? pageData : (Array.isArray(pageData?.list) ? pageData.list : [])
console.log('[deviceSelect] 模具型号总数:', list.length, '前3条:', list.slice(0, 3).map(m => ({ name: m.name, deviceName: m.deviceName })))
const map = new Map()
for (const mold of list) {
const deviceName = mold.deviceName
@ -127,7 +124,6 @@ async function loadDeviceMolds() {
}
}
deviceMoldMap.value = map
console.log('[deviceSelect] 在机模具映射表:', map.size, '个设备, keys:', [...map.keys()])
} catch (e) {
console.error('loadDeviceMolds error', e)
}

@ -364,11 +364,26 @@ function handleScan() {
onlyFromCamera: false,
scanType: ['qrCode', 'barCode'],
success(res) {
const code = res.result?.trim()
const code = (res.result || '').trim()
if (!code) return
const matched = deviceOptions.value.find((d) =>
d.raw.deviceCode === code || String(d.raw.code) === code || d.label.includes(code)
)
let matched = null
if (code.toUpperCase().startsWith('EQUIPMENT-')) {
const idFromQr = code.replace(/EQUIPMENT-/i, '')
matched = deviceOptions.value.find((d) => String(d.raw.id) === idFromQr)
}
if (!matched) {
matched = deviceOptions.value.find((d) =>
Object.values(d.raw).some((v) =>
typeof v === 'string' && v.trim().toUpperCase() === code.toUpperCase()
) || d.label.toUpperCase().includes(code.toUpperCase())
)
}
if (!matched) {
const idMatch = code.match(/(\d+)$/)
if (idMatch) {
matched = deviceOptions.value.find((d) => String(d.raw.id) === idMatch[1])
}
}
if (matched) {
selectDevice(matched.raw)
} else {

@ -150,6 +150,7 @@ import { useI18n } from 'vue-i18n'
import NavBar from '@/components/common/NavBar.vue'
import { getDeviceLedgerList, createMoldOperate } from '@/api/mes/moldoperate'
import { getMoldBrandPage } from '@/api/mes/mold'
import { getDeviceLineTree } from '@/api/mes/deviceLine'
import useUserStore from '@/store/modules/user'
const { t } = useI18n()
@ -190,6 +191,70 @@ async function loadDevices() {
}
}
// 线 - 线
const lineInfoMap = ref(new Map())
function flattenLineTree(nodes, parentId) {
if (!Array.isArray(nodes)) return
for (const node of nodes) {
if (node.id != null && node.name != null) {
lineInfoMap.value.set(String(node.id), {
id: node.id,
name: node.name,
parentId: node.parentId != null ? node.parentId : (parentId || null),
parentChain: node.parentChain || ''
})
}
if (Array.isArray(node.children)) {
flattenLineTree(node.children, node.id)
}
}
}
function getTopLineName(deviceLineId) {
if (deviceLineId == null) return '-'
const node = lineInfoMap.value.get(String(deviceLineId))
if (!node) return '-'
if (node.parentChain) {
const firstId = node.parentChain.split(',')[0]?.trim()
if (firstId) {
const topNode = lineInfoMap.value.get(firstId)
if (topNode) return topNode.name
}
}
let current = node
const visited = new Set()
while (current.parentId != null && current.parentId > 0 && !visited.has(current.id)) {
visited.add(current.id)
const parent = lineInfoMap.value.get(String(current.parentId))
if (!parent) break
current = parent
}
return current.name || '-'
}
async function loadLineTree() {
if (lineInfoMap.value.size > 0) return
try {
const res = await getDeviceLineTree()
const tree = (res && res.data !== undefined) ? res.data : res
const nodes = Array.isArray(tree) ? tree : (tree?.list || tree?.children || [])
flattenLineTree(nodes)
} catch (e) {
console.error('load line tree error', e)
}
}
// 线线
function setDeviceLineName(device) {
if (device && device.deviceLine != null) {
const lineName = getTopLineName(device.deviceLine)
if (lineName && lineName !== '-') {
device.workshopName = lineName
}
}
}
// ==================== ====================
const selectedDevice = ref({})
@ -238,13 +303,10 @@ async function fetchCurrentMolds(deviceName) {
try {
//
const params = { deviceName, pageSize: 100 }
console.log('[上模] fetchCurrentMolds 请求参数:', JSON.stringify(params))
const res = await getMoldBrandPage(params)
console.log('[上模] fetchCurrentMolds 原始响应:', JSON.stringify(res))
const root = res && res.data !== undefined ? res.data : res
const pageData = root?.pageResult || root
const list = Array.isArray(pageData) ? pageData : (Array.isArray(pageData?.list) ? pageData.list : [])
console.log('[上模] fetchCurrentMolds 解析后:', list.length, '条数据', list.map(m => ({ id: m.id, name: m.name, currentDevice: m.currentDevice })))
currentMoldList.value = list
} catch (e) {
console.error('fetchCurrentMolds error', e)
@ -350,12 +412,31 @@ function handleScan() {
onlyFromCamera: false,
scanType: ['qrCode', 'barCode'],
success(res) {
const code = res.result?.trim()
const code = (res.result || '').trim()
if (!code) return
const matched = deviceOptions.value.find((d) =>
d.raw.deviceCode === code || String(d.raw.code) === code || d.label.includes(code)
)
let matched = null
// 1: EQUIPMENT-{ID}
if (code.toUpperCase().startsWith('EQUIPMENT-')) {
const idFromQr = code.replace(/EQUIPMENT-/i, '')
matched = deviceOptions.value.find((d) => String(d.raw.id) === idFromQr)
}
// 2: label
if (!matched) {
matched = deviceOptions.value.find((d) =>
Object.values(d.raw).some((v) =>
typeof v === 'string' && v.trim().toUpperCase() === code.toUpperCase()
) || d.label.toUpperCase().includes(code.toUpperCase())
)
}
// 3: ID
if (!matched) {
const idMatch = code.match(/(\d+)$/)
if (idMatch) {
matched = deviceOptions.value.find((d) => String(d.raw.id) === idMatch[1])
}
}
if (matched) {
setDeviceLineName(matched.raw)
selectDevice(matched.raw)
} else {
uni.showToast({ title: t('moldOperate.deviceNotFound'), icon: 'none' })
@ -385,7 +466,7 @@ function goToHistory() {
onShow(async () => {
autoSetOperator()
await Promise.allSettled([loadDevices()])
await Promise.allSettled([loadDevices(), loadLineTree()])
// globalData
const device = getApp().globalData._deviceSelectResult
if (device) {

@ -317,7 +317,6 @@ export function resolveMenuUrl(menu) {
for (const key of keys) {
const normalizedKey = normalizeMenuKey(key)
if (normalizedKey && MENU_ROUTE_MAP[normalizedKey]) {
console.log('[resolveMenuUrl] menu.name="', menu?.name, '" matched key="', normalizedKey, '" → route="', MENU_ROUTE_MAP[normalizedKey], '"')
return MENU_ROUTE_MAP[normalizedKey]
}
}

Loading…
Cancel
Save