From b2593bf85701f64d0b0d8562dba2d2c2f9d0510b Mon Sep 17 00:00:00 2001 From: lixiaolong <702156524@qq.com> Date: Wed, 5 Aug 2026 10:46:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(flow):=20=E4=BC=98=E5=8C=96=E6=9C=BA?= =?UTF-8?q?=E5=99=A8=E4=BA=BA=E8=AE=BE=E5=A4=87=E7=BB=91=E5=AE=9A=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=B9=B6=E6=94=B9=E8=BF=9B=E7=8A=B6=E6=80=81=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 保留原始设备ID和选项作为默认值,避免数据丢失 - 当机器人无匹配在线设备时显示警告并保留原有设置 - 改进设备选择逻辑,支持设备种类过滤和自动填充 - 添加未触动手动设备节点统计功能 - 更新绑定面板状态显示,区分缺失设备和手动设备 - 优化错误处理机制,失败时恢复原始参数值 - 完善设备匹配成功和失败的消息提示内容 --- src/views/flow/components/TestRun.vue | 44 ++++++++++++++++----------- src/views/flow/index.vue | 42 +++++++++++++++++-------- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/views/flow/components/TestRun.vue b/src/views/flow/components/TestRun.vue index 241f387..dc5b567 100644 --- a/src/views/flow/components/TestRun.vue +++ b/src/views/flow/components/TestRun.vue @@ -19,7 +19,8 @@
正在读取机器人在线设备...
已匹配 {{ bindingSummary.matched }} 个设备节点 - ,{{ bindingSummary.missing }} 个节点暂无匹配设备 + ,{{ bindingSummary.missing }} 个节点未匹配并保留原值 + ,{{ bindingSummary.untouched }} 个手动设备节点保持不变
选择机器人后,将按节点类型自动填充该机器人上报的在线设备。
@@ -90,7 +91,8 @@ const ruleFormRef = ref() const rules = ref({}); const tableData = ref([]) const bindingLoading = ref(false) -const bindingSummary = ref({ robotId: '', matched: 0, missing: 0 }) +const emptyBindingSummary = (robotId = '') => ({ robotId, matched: 0, missing: 0, untouched: 0 }) +const bindingSummary = ref(emptyBindingSummary()) const emits = defineEmits(['close', 'changeState']) @@ -104,7 +106,7 @@ watch(() => props.drawer, if (newVal) { const data = getStartNodeFormData() tableData.value = data - bindingSummary.value = { robotId: '', matched: 0, missing: 0 } + bindingSummary.value = emptyBindingSummary() loadRobotOptions() } } @@ -142,7 +144,7 @@ const confirm = () => { const robotIdOptions = ref([]) const handleRobotChange = async (robotId) => { - bindingSummary.value = { robotId: robotId || '', matched: 0, missing: 0 } + bindingSummary.value = emptyBindingSummary(robotId || '') if (!robotId) return bindingLoading.value = true try { @@ -150,6 +152,7 @@ const handleRobotChange = async (robotId) => { const devices = Array.isArray(response.data) ? response.data : [] let matched = 0 let missing = 0 + let untouched = 0 const missingNodes = [] const { nodes } = lf.getGraphData() @@ -166,30 +169,37 @@ const handleRobotChange = async (robotId) => { } const kind = getDeviceKindForAction(node.properties.action) - const candidates = kind - ? devices.filter(device => Number(device.deviceKind) === kind) - : devices - deviceParam.input = candidates[0]?.deviceId || '' + if (!kind) { + untouched += 1 + if (robotParam) lf.setProperties(node.id, { ...node.properties, nodeParams }) + return + } + + const candidates = devices.filter(device => Number(device.deviceKind) === kind) + if (!candidates.length) { + missing += 1 + missingNodes.push(node.properties.name || node.id) + if (robotParam) lf.setProperties(node.id, { ...node.properties, nodeParams }) + return + } + + const currentCandidate = candidates.find(device => device.deviceId === deviceParam.input) + deviceParam.input = (currentCandidate || candidates[0]).deviceId deviceParam.componentType = 'select' deviceParam.selectOptions = toDeviceOptions(candidates) deviceParam.deviceLocked = candidates.length === 1 lf.setProperties(node.id, { ...node.properties, nodeParams }) - - if (candidates.length > 0) matched += 1 - else { - missing += 1 - missingNodes.push(node.properties.name || node.id) - } + matched += 1 }) - bindingSummary.value = { robotId, matched, missing } + bindingSummary.value = { robotId, matched, missing, untouched } if (missingNodes.length) { - ElMessage.warning(`以下节点没有匹配的在线设备:${missingNodes.join('、')}`) + ElMessage.warning(`以下节点没有匹配的在线设备,已保留原值:${missingNodes.join('、')}`) } else if (matched > 0) { ElMessage.success(`已自动匹配 ${matched} 个设备节点`) } } catch (error) { - bindingSummary.value = { robotId, matched: 0, missing: 0 } + bindingSummary.value = emptyBindingSummary(robotId) console.error('自动匹配机器人设备失败:', error) ElMessage.error('读取机器人设备失败') } finally { diff --git a/src/views/flow/index.vue b/src/views/flow/index.vue index 3a5182d..6161aec 100644 --- a/src/views/flow/index.vue +++ b/src/views/flow/index.vue @@ -913,29 +913,47 @@ const singleNodeDeviceId = computed(() => const handleSingleNodeRobotChange = async (robotId) => { const deviceParam = formData.nodeParams.find((item) => item.name === "deviceId"); if (!deviceParam) return; - deviceParam.input = ""; - deviceParam.deviceLocked = false; - deviceParam.componentType = "select"; - deviceParam.selectOptions = []; + const originalDeviceId = deviceParam.input; + const originalOptions = [...(deviceParam.selectOptions || [])]; + const originalLocked = Boolean(deviceParam.deviceLocked); const stationParam = formData.nodeParams.find((item) => item.name === "stationId"); - if (stationParam) { - stationParam.input = ""; - stationParam.selectOptions = []; - } if (!robotId) return; try { const deviceKind = getDeviceKindForAction(nodeAction.value); const response = await getRobotDevicesByRobotId(robotId, deviceKind ? { deviceKind } : {}); const devices = Array.isArray(response.data) ? response.data : []; + if (!devices.length) { + deviceParam.input = originalDeviceId; + deviceParam.selectOptions = originalOptions; + deviceParam.deviceLocked = originalLocked; + ElMessage.warning("当前机器人没有匹配的在线设备,已保留原设备"); + return; + } + + if (stationParam) { + stationParam.input = ""; + stationParam.selectOptions = []; + } + deviceParam.componentType = "select"; deviceParam.selectOptions = toDeviceOptions(devices); - if (devices.length > 0) { - deviceParam.input = devices[0].deviceId; + if (deviceKind) { + const currentDevice = devices.find((device) => device.deviceId === originalDeviceId); + deviceParam.input = (currentDevice || devices[0]).deviceId; deviceParam.deviceLocked = devices.length === 1; - } else { - ElMessage.warning("当前机器人没有匹配的在线设备"); + return; + } + + const originalStillAvailable = devices.some((device) => device.deviceId === originalDeviceId); + deviceParam.input = originalDeviceId || ""; + deviceParam.deviceLocked = devices.length === 1 && originalStillAvailable; + if (originalDeviceId && !originalStillAvailable) { + ElMessage.warning("已保留通用指令原设备;该设备未出现在当前机器人的在线列表中"); } } catch (error) { + deviceParam.input = originalDeviceId; + deviceParam.selectOptions = originalOptions; + deviceParam.deviceLocked = originalLocked; console.error("加载机器人设备失败:", error); ElMessage.error("加载机器人设备失败"); }