diff --git a/src/pages_function/pages/moldoperate/deviceSelect.vue b/src/pages_function/pages/moldoperate/deviceSelect.vue index 8714cd9..cac770e 100644 --- a/src/pages_function/pages/moldoperate/deviceSelect.vue +++ b/src/pages_function/pages/moldoperate/deviceSelect.vue @@ -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) } diff --git a/src/pages_function/pages/moldoperate/dismount.vue b/src/pages_function/pages/moldoperate/dismount.vue index acd1683..8b11943 100644 --- a/src/pages_function/pages/moldoperate/dismount.vue +++ b/src/pages_function/pages/moldoperate/dismount.vue @@ -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 { diff --git a/src/pages_function/pages/moldoperate/index.vue b/src/pages_function/pages/moldoperate/index.vue index be8e0ff..20cbaf9 100644 --- a/src/pages_function/pages/moldoperate/index.vue +++ b/src/pages_function/pages/moldoperate/index.vue @@ -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) { diff --git a/src/utils/permissionMenu.js b/src/utils/permissionMenu.js index baf5a51..885dbe5 100644 --- a/src/utils/permissionMenu.js +++ b/src/utils/permissionMenu.js @@ -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] } }