fix: 增强库位任务数据处理逻辑,添加错误处理和数据验证,确保组件稳定性
This commit is contained in:
parent
a2412fcf3c
commit
b35fe5e98b
@ -138,32 +138,55 @@ const parseBinTask = (binTaskString: string): BinTaskItem[] => {
|
||||
|
||||
// 获取当前动作点对应的库位任务数据
|
||||
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;
|
||||
if (!currentPointName) return [];
|
||||
const currentPointName = pen.value?.label || pen.value?.id;
|
||||
if (!currentPointName) return [];
|
||||
|
||||
// 获取库位组数据
|
||||
const binLocationGroups = Array.isArray(rawData)
|
||||
? (rawData as BinLocationGroup[])
|
||||
: (rawData as BinLocationsList)?.binLocationsList;
|
||||
// 获取库位组数据
|
||||
const binLocationGroups = Array.isArray(rawData)
|
||||
? (rawData as BinLocationGroup[])
|
||||
: (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
|
||||
.filter((item) => item.pointName === currentPointName)
|
||||
.map((item) => {
|
||||
const binTaskProperty = item.property.find((prop) => prop.key === 'binTask');
|
||||
return {
|
||||
instanceName: item.instanceName,
|
||||
binTasks: binTaskProperty ? parseBinTask(binTaskProperty.stringValue) : [],
|
||||
};
|
||||
})
|
||||
.filter((item) => item.binTasks.length > 0);
|
||||
return allBinLocations
|
||||
.filter((item) => item.pointName === currentPointName)
|
||||
.map((item) => {
|
||||
try {
|
||||
if (!item.property || !Array.isArray(item.property)) {
|
||||
return {
|
||||
instanceName: item.instanceName || '未知库位',
|
||||
binTasks: [],
|
||||
};
|
||||
}
|
||||
|
||||
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>
|
||||
|
||||
@ -271,24 +294,24 @@ const binTaskData = computed(() => {
|
||||
<a-typography-text class="bin-location-name">{{ binLocation.instanceName }}</a-typography-text>
|
||||
<div class="bin-tasks">
|
||||
<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>
|
||||
<div class="operation-details">
|
||||
<div v-for="(value, key) in task.Load" :key="key" class="detail-item">
|
||||
<span class="detail-key">{{ key }}:</span>
|
||||
<span class="detail-value">
|
||||
{{ typeof value === 'boolean' ? (value ? '是' : '否') : value }}
|
||||
{{ typeof value === 'boolean' ? (value ? '是' : '否') : (value ?? '未知') }}
|
||||
</span>
|
||||
</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>
|
||||
<div class="operation-details">
|
||||
<div v-for="(value, key) in task.Unload" :key="key" class="detail-item">
|
||||
<span class="detail-key">{{ key }}:</span>
|
||||
<span class="detail-value">
|
||||
{{ typeof value === 'boolean' ? (value ? '是' : '否') : value }}
|
||||
{{ typeof value === 'boolean' ? (value ? '是' : '否') : (value ?? '未知') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user