fix: 增强库位任务数据处理逻辑,添加错误处理和数据验证,确保组件稳定性

This commit is contained in:
xudan 2025-08-06 09:14:58 +08:00
parent a2412fcf3c
commit b35fe5e98b

View File

@ -138,32 +138,55 @@ const parseBinTask = (binTaskString: string): BinTaskItem[] => {
// //
const binTaskData = computed(() => { const binTaskData = computed(() => {
const rawData = editor.value.getBinLocationsList(); try {
const rawData = editor.value.getBinLocationsList();
if (!rawData || !point.value) return []; if (!rawData || !point.value) return [];
const currentPointName = pen.value?.label || pen.value?.id; const currentPointName = pen.value?.label || pen.value?.id;
if (!currentPointName) return []; if (!currentPointName) return [];
// //
const binLocationGroups = Array.isArray(rawData) const binLocationGroups = Array.isArray(rawData)
? (rawData as BinLocationGroup[]) ? (rawData as BinLocationGroup[])
: (rawData as BinLocationsList)?.binLocationsList; : (rawData as BinLocationsList)?.binLocationsList;
if (!binLocationGroups) return []; if (!binLocationGroups || !Array.isArray(binLocationGroups)) return [];
const allBinLocations = binLocationGroups.flatMap((group) => group.binLocationList); const allBinLocations = binLocationGroups
.filter((group) => group && Array.isArray(group.binLocationList))
.flatMap((group) => group.binLocationList)
.filter((item) => item && typeof item === 'object');
return allBinLocations return allBinLocations
.filter((item) => item.pointName === currentPointName) .filter((item) => item.pointName === currentPointName)
.map((item) => { .map((item) => {
const binTaskProperty = item.property.find((prop) => prop.key === 'binTask'); try {
return { if (!item.property || !Array.isArray(item.property)) {
instanceName: item.instanceName, return {
binTasks: binTaskProperty ? parseBinTask(binTaskProperty.stringValue) : [], instanceName: item.instanceName || '未知库位',
}; binTasks: [],
}) };
.filter((item) => item.binTasks.length > 0); }
const binTaskProperty = item.property.find((prop) => prop && prop.key === 'binTask');
return {
instanceName: item.instanceName || '未知库位',
binTasks: binTaskProperty && binTaskProperty.stringValue ? parseBinTask(binTaskProperty.stringValue) : [],
};
} catch (error) {
console.error('处理库位任务数据失败:', error, item);
return {
instanceName: item.instanceName || '未知库位',
binTasks: [],
};
}
})
.filter((item) => item.binTasks.length > 0);
} catch (error) {
console.error('获取库位任务数据失败:', error);
return [];
}
}); });
</script> </script>
@ -271,24 +294,24 @@ const binTaskData = computed(() => {
<a-typography-text class="bin-location-name">{{ binLocation.instanceName }}</a-typography-text> <a-typography-text class="bin-location-name">{{ binLocation.instanceName }}</a-typography-text>
<div class="bin-tasks"> <div class="bin-tasks">
<div v-for="(task, taskIndex) in binLocation.binTasks" :key="taskIndex" class="bin-task-item"> <div v-for="(task, taskIndex) in binLocation.binTasks" :key="taskIndex" class="bin-task-item">
<div v-if="task.Load" class="task-operation"> <div v-if="task && task.Load && typeof task.Load === 'object'" class="task-operation">
<a-typography-text class="operation-title">装载</a-typography-text> <a-typography-text class="operation-title">装载</a-typography-text>
<div class="operation-details"> <div class="operation-details">
<div v-for="(value, key) in task.Load" :key="key" class="detail-item"> <div v-for="(value, key) in task.Load" :key="key" class="detail-item">
<span class="detail-key">{{ key }}:</span> <span class="detail-key">{{ key }}:</span>
<span class="detail-value"> <span class="detail-value">
{{ typeof value === 'boolean' ? (value ? '是' : '否') : value }} {{ typeof value === 'boolean' ? (value ? '是' : '否') : (value ?? '未知') }}
</span> </span>
</div> </div>
</div> </div>
</div> </div>
<div v-if="task.Unload" class="task-operation"> <div v-if="task && task.Unload && typeof task.Unload === 'object'" class="task-operation">
<a-typography-text class="operation-title">卸载</a-typography-text> <a-typography-text class="operation-title">卸载</a-typography-text>
<div class="operation-details"> <div class="operation-details">
<div v-for="(value, key) in task.Unload" :key="key" class="detail-item"> <div v-for="(value, key) in task.Unload" :key="key" class="detail-item">
<span class="detail-key">{{ key }}:</span> <span class="detail-key">{{ key }}:</span>
<span class="detail-value"> <span class="detail-value">
{{ typeof value === 'boolean' ? (value ? '是' : '否') : value }} {{ typeof value === 'boolean' ? (value ? '是' : '否') : (value ?? '未知') }}
</span> </span>
</div> </div>
</div> </div>