fix(flow): 优化机器人设备绑定逻辑并改进状态提示
- 保留原始设备ID和选项作为默认值,避免数据丢失 - 当机器人无匹配在线设备时显示警告并保留原有设置 - 改进设备选择逻辑,支持设备种类过滤和自动填充 - 添加未触动手动设备节点统计功能 - 更新绑定面板状态显示,区分缺失设备和手动设备 - 优化错误处理机制,失败时恢复原始参数值 - 完善设备匹配成功和失败的消息提示内容
This commit is contained in:
parent
65d219062e
commit
b2593bf857
@ -19,7 +19,8 @@
|
|||||||
<div class="binding-panel__text" v-if="bindingLoading">正在读取机器人在线设备...</div>
|
<div class="binding-panel__text" v-if="bindingLoading">正在读取机器人在线设备...</div>
|
||||||
<div class="binding-panel__text" v-else-if="bindingSummary.robotId">
|
<div class="binding-panel__text" v-else-if="bindingSummary.robotId">
|
||||||
已匹配 {{ bindingSummary.matched }} 个设备节点
|
已匹配 {{ bindingSummary.matched }} 个设备节点
|
||||||
<span v-if="bindingSummary.missing">,{{ bindingSummary.missing }} 个节点暂无匹配设备</span>
|
<span v-if="bindingSummary.missing">,{{ bindingSummary.missing }} 个节点未匹配并保留原值</span>
|
||||||
|
<span v-if="bindingSummary.untouched">,{{ bindingSummary.untouched }} 个手动设备节点保持不变</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="binding-panel__text" v-else>选择机器人后,将按节点类型自动填充该机器人上报的在线设备。</div>
|
<div class="binding-panel__text" v-else>选择机器人后,将按节点类型自动填充该机器人上报的在线设备。</div>
|
||||||
</div>
|
</div>
|
||||||
@ -90,7 +91,8 @@ const ruleFormRef = ref()
|
|||||||
const rules = ref({});
|
const rules = ref({});
|
||||||
const tableData = ref([])
|
const tableData = ref([])
|
||||||
const bindingLoading = ref(false)
|
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'])
|
const emits = defineEmits(['close', 'changeState'])
|
||||||
|
|
||||||
@ -104,7 +106,7 @@ watch(() => props.drawer,
|
|||||||
if (newVal) {
|
if (newVal) {
|
||||||
const data = getStartNodeFormData()
|
const data = getStartNodeFormData()
|
||||||
tableData.value = data
|
tableData.value = data
|
||||||
bindingSummary.value = { robotId: '', matched: 0, missing: 0 }
|
bindingSummary.value = emptyBindingSummary()
|
||||||
loadRobotOptions()
|
loadRobotOptions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,7 +144,7 @@ const confirm = () => {
|
|||||||
const robotIdOptions = ref([])
|
const robotIdOptions = ref([])
|
||||||
|
|
||||||
const handleRobotChange = async (robotId) => {
|
const handleRobotChange = async (robotId) => {
|
||||||
bindingSummary.value = { robotId: robotId || '', matched: 0, missing: 0 }
|
bindingSummary.value = emptyBindingSummary(robotId || '')
|
||||||
if (!robotId) return
|
if (!robotId) return
|
||||||
bindingLoading.value = true
|
bindingLoading.value = true
|
||||||
try {
|
try {
|
||||||
@ -150,6 +152,7 @@ const handleRobotChange = async (robotId) => {
|
|||||||
const devices = Array.isArray(response.data) ? response.data : []
|
const devices = Array.isArray(response.data) ? response.data : []
|
||||||
let matched = 0
|
let matched = 0
|
||||||
let missing = 0
|
let missing = 0
|
||||||
|
let untouched = 0
|
||||||
const missingNodes = []
|
const missingNodes = []
|
||||||
const { nodes } = lf.getGraphData()
|
const { nodes } = lf.getGraphData()
|
||||||
|
|
||||||
@ -166,30 +169,37 @@ const handleRobotChange = async (robotId) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const kind = getDeviceKindForAction(node.properties.action)
|
const kind = getDeviceKindForAction(node.properties.action)
|
||||||
const candidates = kind
|
if (!kind) {
|
||||||
? devices.filter(device => Number(device.deviceKind) === kind)
|
untouched += 1
|
||||||
: devices
|
if (robotParam) lf.setProperties(node.id, { ...node.properties, nodeParams })
|
||||||
deviceParam.input = candidates[0]?.deviceId || ''
|
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.componentType = 'select'
|
||||||
deviceParam.selectOptions = toDeviceOptions(candidates)
|
deviceParam.selectOptions = toDeviceOptions(candidates)
|
||||||
deviceParam.deviceLocked = candidates.length === 1
|
deviceParam.deviceLocked = candidates.length === 1
|
||||||
lf.setProperties(node.id, { ...node.properties, nodeParams })
|
lf.setProperties(node.id, { ...node.properties, nodeParams })
|
||||||
|
matched += 1
|
||||||
if (candidates.length > 0) matched += 1
|
|
||||||
else {
|
|
||||||
missing += 1
|
|
||||||
missingNodes.push(node.properties.name || node.id)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
bindingSummary.value = { robotId, matched, missing }
|
bindingSummary.value = { robotId, matched, missing, untouched }
|
||||||
if (missingNodes.length) {
|
if (missingNodes.length) {
|
||||||
ElMessage.warning(`以下节点没有匹配的在线设备:${missingNodes.join('、')}`)
|
ElMessage.warning(`以下节点没有匹配的在线设备,已保留原值:${missingNodes.join('、')}`)
|
||||||
} else if (matched > 0) {
|
} else if (matched > 0) {
|
||||||
ElMessage.success(`已自动匹配 ${matched} 个设备节点`)
|
ElMessage.success(`已自动匹配 ${matched} 个设备节点`)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
bindingSummary.value = { robotId, matched: 0, missing: 0 }
|
bindingSummary.value = emptyBindingSummary(robotId)
|
||||||
console.error('自动匹配机器人设备失败:', error)
|
console.error('自动匹配机器人设备失败:', error)
|
||||||
ElMessage.error('读取机器人设备失败')
|
ElMessage.error('读取机器人设备失败')
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -913,29 +913,47 @@ const singleNodeDeviceId = computed(() =>
|
|||||||
const handleSingleNodeRobotChange = async (robotId) => {
|
const handleSingleNodeRobotChange = async (robotId) => {
|
||||||
const deviceParam = formData.nodeParams.find((item) => item.name === "deviceId");
|
const deviceParam = formData.nodeParams.find((item) => item.name === "deviceId");
|
||||||
if (!deviceParam) return;
|
if (!deviceParam) return;
|
||||||
deviceParam.input = "";
|
const originalDeviceId = deviceParam.input;
|
||||||
deviceParam.deviceLocked = false;
|
const originalOptions = [...(deviceParam.selectOptions || [])];
|
||||||
deviceParam.componentType = "select";
|
const originalLocked = Boolean(deviceParam.deviceLocked);
|
||||||
deviceParam.selectOptions = [];
|
|
||||||
const stationParam = formData.nodeParams.find((item) => item.name === "stationId");
|
const stationParam = formData.nodeParams.find((item) => item.name === "stationId");
|
||||||
if (stationParam) {
|
|
||||||
stationParam.input = "";
|
|
||||||
stationParam.selectOptions = [];
|
|
||||||
}
|
|
||||||
if (!robotId) return;
|
if (!robotId) return;
|
||||||
try {
|
try {
|
||||||
const deviceKind = getDeviceKindForAction(nodeAction.value);
|
const deviceKind = getDeviceKindForAction(nodeAction.value);
|
||||||
const response = await getRobotDevicesByRobotId(robotId,
|
const response = await getRobotDevicesByRobotId(robotId,
|
||||||
deviceKind ? { deviceKind } : {});
|
deviceKind ? { deviceKind } : {});
|
||||||
const devices = Array.isArray(response.data) ? response.data : [];
|
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);
|
deviceParam.selectOptions = toDeviceOptions(devices);
|
||||||
if (devices.length > 0) {
|
if (deviceKind) {
|
||||||
deviceParam.input = devices[0].deviceId;
|
const currentDevice = devices.find((device) => device.deviceId === originalDeviceId);
|
||||||
|
deviceParam.input = (currentDevice || devices[0]).deviceId;
|
||||||
deviceParam.deviceLocked = devices.length === 1;
|
deviceParam.deviceLocked = devices.length === 1;
|
||||||
} else {
|
return;
|
||||||
ElMessage.warning("当前机器人没有匹配的在线设备");
|
}
|
||||||
|
|
||||||
|
const originalStillAvailable = devices.some((device) => device.deviceId === originalDeviceId);
|
||||||
|
deviceParam.input = originalDeviceId || "";
|
||||||
|
deviceParam.deviceLocked = devices.length === 1 && originalStillAvailable;
|
||||||
|
if (originalDeviceId && !originalStillAvailable) {
|
||||||
|
ElMessage.warning("已保留通用指令原设备;该设备未出现在当前机器人的在线列表中");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
deviceParam.input = originalDeviceId;
|
||||||
|
deviceParam.selectOptions = originalOptions;
|
||||||
|
deviceParam.deviceLocked = originalLocked;
|
||||||
console.error("加载机器人设备失败:", error);
|
console.error("加载机器人设备失败:", error);
|
||||||
ElMessage.error("加载机器人设备失败");
|
ElMessage.error("加载机器人设备失败");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user