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("加载机器人设备失败");
}