恢复挂载行为树请求
This commit is contained in:
@@ -72,7 +72,7 @@ import { createGraphScenarioElement, createGraphTaskElementFromScenario } from '
|
||||
|
||||
import PlatformCard from './platform-card.vue';
|
||||
import NodesCard from './nodes-card.vue';
|
||||
import { findOneScenarioById, saveScenario, findRelations } from './api';
|
||||
import { findOneScenarioById, saveScenario, findRelations, getAllBehaviorTreesBySceneId } from './api';
|
||||
import { resolveConnectionRelation } from './relation';
|
||||
import { generateRandomCommunicationData } from './random-data-generator';
|
||||
import { convertRecordsToGraphContainer, type CommunicationRecord } from './data-converter';
|
||||
@@ -241,56 +241,74 @@ export default defineComponent({
|
||||
|
||||
currentScenarioEditing.value = true;
|
||||
|
||||
// 如果场景有ID且没有已保存的图数据,尝试从后端加载通信关系
|
||||
if (scenario.id > 0 && !nodeGraph) {
|
||||
// 并行加载通信关系和行为树列表
|
||||
if (scenario.id > 0) {
|
||||
try {
|
||||
message.loading({ content: '正在加载通信关系...', key: 'loading-relations' });
|
||||
const response = await findRelations(scenario.id);
|
||||
|
||||
console.log('API完整响应:', response);
|
||||
|
||||
// 解析API响应(支持多种格式)
|
||||
let relations: any[] = [];
|
||||
if (Array.isArray(response.data)) {
|
||||
relations = response.data;
|
||||
} else if (response.data && Array.isArray((response.data as any).data)) {
|
||||
relations = (response.data as any).data;
|
||||
} else if (response.data && Array.isArray((response.data as any).rows)) {
|
||||
relations = (response.data as any).rows;
|
||||
} else if (response.data && Array.isArray((response.data as any).list)) {
|
||||
relations = (response.data as any).list;
|
||||
// 1. 加载通信关系(如果没有已保存的图数据)
|
||||
if (!nodeGraph) {
|
||||
message.loading({ content: '正在加载通信关系...', key: 'loading-relations' });
|
||||
const response = await findRelations(scenario.id);
|
||||
|
||||
console.log('API完整响应:', response);
|
||||
|
||||
// 解析API响应(支持多种格式)
|
||||
let relations: any[] = [];
|
||||
if (Array.isArray(response.data)) {
|
||||
relations = response.data;
|
||||
} else if (response.data && Array.isArray((response.data as any).data)) {
|
||||
relations = (response.data as any).data;
|
||||
} else if (response.data && Array.isArray((response.data as any).rows)) {
|
||||
relations = (response.data as any).rows;
|
||||
} else if (response.data && Array.isArray((response.data as any).list)) {
|
||||
relations = (response.data as any).list;
|
||||
}
|
||||
|
||||
console.log('解析后的通信关系数量:', relations.length);
|
||||
|
||||
if (relations.length > 0) {
|
||||
// 字段名标准化(驼峰转下划线)
|
||||
const normalizedRelations = relations.map((item: any) => ({
|
||||
id: item.id,
|
||||
command_platform: item.commandPlatform || item.command_platform,
|
||||
subordinate_platform: item.subordinatePlatform || item.subordinate_platform,
|
||||
command_comm: item.commandComm || item.command_comm,
|
||||
subordinate_comm: item.subordinateComm || item.subordinate_comm,
|
||||
scenary_id: item.scenaryId || item.scenary_id,
|
||||
}));
|
||||
|
||||
console.log('标准化后的第一条记录:', normalizedRelations[0]);
|
||||
|
||||
// 转换为图数据
|
||||
const convertedGraph = convertRecordsToGraphContainer(normalizedRelations);
|
||||
console.log('转换后的图数据:', convertedGraph);
|
||||
|
||||
// 更新当前场景的图数据
|
||||
currentScenario.value.graph = convertedGraph;
|
||||
currentScenario.value.communicationGraph = JSON.stringify(convertedGraph);
|
||||
|
||||
message.success({ content: `成功加载 ${normalizedRelations.length} 条通信关系`, key: 'loading-relations' });
|
||||
} else {
|
||||
message.warning({ content: '该场景暂无通信关系数据', key: 'loading-relations' });
|
||||
}
|
||||
}
|
||||
|
||||
console.log('解析后的通信关系数量:', relations.length);
|
||||
|
||||
if (relations.length > 0) {
|
||||
// 字段名标准化(驼峰转下划线)
|
||||
const normalizedRelations = relations.map((item: any) => ({
|
||||
id: item.id,
|
||||
command_platform: item.commandPlatform || item.command_platform,
|
||||
subordinate_platform: item.subordinatePlatform || item.subordinate_platform,
|
||||
command_comm: item.commandComm || item.command_comm,
|
||||
subordinate_comm: item.subordinateComm || item.subordinate_comm,
|
||||
scenary_id: item.scenaryId || item.scenary_id,
|
||||
}));
|
||||
|
||||
console.log('标准化后的第一条记录:', normalizedRelations[0]);
|
||||
|
||||
// 转换为图数据
|
||||
const convertedGraph = convertRecordsToGraphContainer(normalizedRelations);
|
||||
console.log('转换后的图数据:', convertedGraph);
|
||||
|
||||
// 更新当前场景的图数据
|
||||
currentScenario.value.graph = convertedGraph;
|
||||
currentScenario.value.communicationGraph = JSON.stringify(convertedGraph);
|
||||
|
||||
message.success({ content: `成功加载 ${normalizedRelations.length} 条通信关系`, key: 'loading-relations' });
|
||||
// 2. 加载行为树列表并缓存到graph对象
|
||||
const treesResponse = await getAllBehaviorTreesBySceneId(scenario.id);
|
||||
if (treesResponse.code === 200 && treesResponse.data) {
|
||||
console.log('[communication] 行为树列表加载完成:', treesResponse.data.length, '个');
|
||||
// 将行为树列表存储到graph对象中供node.vue使用
|
||||
if (graph.value) {
|
||||
(graph.value as any).behaviorTrees = treesResponse.data;
|
||||
}
|
||||
} else {
|
||||
message.warning({ content: '该场景暂无通信关系数据', key: 'loading-relations' });
|
||||
console.warn('[communication] 行为树列表加载失败或为空');
|
||||
if (graph.value) {
|
||||
(graph.value as any).behaviorTrees = [];
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('从后端加载通信关系失败:', error);
|
||||
message.error({ content: '加载通信关系失败,请手动点击"从后端加载"', key: 'loading-relations' });
|
||||
console.error('从后端加载数据失败:', error);
|
||||
message.error({ content: '加载数据失败', key: 'loading-relations' });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user