优化节点初始化逻辑
This commit is contained in:
@@ -104,7 +104,6 @@ export default defineComponent({
|
|||||||
const isDraggingOver = ref(false);
|
const isDraggingOver = ref(false);
|
||||||
const currentScenarioEditing = ref<boolean>(false);
|
const currentScenarioEditing = ref<boolean>(false);
|
||||||
const currentScenario = ref<Scenario | null>(null);
|
const currentScenario = ref<Scenario | null>(null);
|
||||||
const currentGraph = ref<GraphContainer | null>(null);
|
|
||||||
const selectedModelNode = ref<Node<NodeProperties> | null>(null);
|
const selectedModelNode = ref<Node<NodeProperties> | null>(null);
|
||||||
const selectedNodeTaskElement = ref<GraphTaskElement | null>(null);
|
const selectedNodeTaskElement = ref<GraphTaskElement | null>(null);
|
||||||
const changed = ref<boolean>(false);
|
const changed = ref<boolean>(false);
|
||||||
@@ -403,10 +402,6 @@ export default defineComponent({
|
|||||||
(graph.value as any).currentScenario = null;
|
(graph.value as any).currentScenario = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentGraph.value = {
|
|
||||||
edges: [],
|
|
||||||
nodes: [],
|
|
||||||
};
|
|
||||||
selectedModelNode.value = null;
|
selectedModelNode.value = null;
|
||||||
selectedNodeTaskElement.value = null;
|
selectedNodeTaskElement.value = null;
|
||||||
|
|
||||||
@@ -743,7 +738,6 @@ export default defineComponent({
|
|||||||
handleCreate,
|
handleCreate,
|
||||||
currentScenarioEditing,
|
currentScenarioEditing,
|
||||||
currentScenario,
|
currentScenario,
|
||||||
currentGraph,
|
|
||||||
selectedNodeTaskElement,
|
selectedNodeTaskElement,
|
||||||
selectedModelNode,
|
selectedModelNode,
|
||||||
graph,
|
graph,
|
||||||
|
|||||||
@@ -115,7 +115,6 @@ export default defineComponent({
|
|||||||
const isDraggingOver = ref(false);
|
const isDraggingOver = ref(false);
|
||||||
const currentTreeEditing = ref<boolean>(false);
|
const currentTreeEditing = ref<boolean>(false);
|
||||||
const currentBehaviorTree = ref<BehaviorTree | null>(null);
|
const currentBehaviorTree = ref<BehaviorTree | null>(null);
|
||||||
const currentGraph = ref<GraphContainer | null>(null);
|
|
||||||
const selectedModelNode = ref<Node<NodeProperties> | null>(null);
|
const selectedModelNode = ref<Node<NodeProperties> | null>(null);
|
||||||
const selectedNodeTaskElement = ref<GraphTaskElement | null>(null);
|
const selectedNodeTaskElement = ref<GraphTaskElement | null>(null);
|
||||||
const changed = ref<boolean>(false);
|
const changed = ref<boolean>(false);
|
||||||
@@ -309,30 +308,25 @@ export default defineComponent({
|
|||||||
const createElements = () => {
|
const createElements = () => {
|
||||||
clearGraph();
|
clearGraph();
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
setTimeout(() => {
|
if (currentBehaviorTree.value?.graph && graph.value) {
|
||||||
if (currentBehaviorTree.value?.graph && graph.value) {
|
if (currentBehaviorTree.value?.graph.nodes) {
|
||||||
if (currentBehaviorTree.value?.graph.nodes) {
|
currentBehaviorTree.value?.graph.nodes.forEach(ele => {
|
||||||
currentBehaviorTree.value?.graph.nodes.forEach(ele => {
|
const node = createGraphTaskElement(ele as GraphTaskElement);
|
||||||
const node = createGraphTaskElement(ele as GraphTaskElement);
|
console.info('create node: ', ele);
|
||||||
console.info('create node: ', ele);
|
// 将节点添加到画布
|
||||||
// 将节点添加到画布
|
graph.value?.addNode(node as Node);
|
||||||
graph.value?.addNode(node as Node);
|
});
|
||||||
});
|
fitToScreen();
|
||||||
fitToScreen();
|
|
||||||
}
|
|
||||||
if (currentBehaviorTree.value?.graph.edges) {
|
|
||||||
// 然后添加所有边,确保包含桩点信息
|
|
||||||
setTimeout(() => {
|
|
||||||
currentBehaviorTree.value?.graph.edges.forEach(edgeData => {
|
|
||||||
graph.value?.addEdge({
|
|
||||||
...edgeData,
|
|
||||||
...createLineOptions(),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, 100); // 延迟一会儿,免得连线错位
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 100);
|
|
||||||
|
// 然后添加所有边,确保包含桩点信息
|
||||||
|
currentBehaviorTree.value?.graph.edges.forEach(edgeData => {
|
||||||
|
graph.value?.addEdge({
|
||||||
|
...edgeData,
|
||||||
|
...createLineOptions(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -354,7 +348,6 @@ export default defineComponent({
|
|||||||
currentScenarioId.value = storedId;
|
currentScenarioId.value = storedId;
|
||||||
fromScenarioPage.value = true;
|
fromScenarioPage.value = true;
|
||||||
} else {
|
} else {
|
||||||
currentScenarioId.value = undefined;
|
|
||||||
fromScenarioPage.value = false;
|
fromScenarioPage.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -371,8 +364,11 @@ export default defineComponent({
|
|||||||
currentScenarioId.value = scenario.id;
|
currentScenarioId.value = scenario.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCreateTree = () => {
|
const initGraphConfig = (_graph?: GraphContainer) => {
|
||||||
destroyGraph();
|
const graph: GraphContainer = _graph ? _graph : {
|
||||||
|
nodes: [],
|
||||||
|
edges: [],
|
||||||
|
};
|
||||||
|
|
||||||
currentBehaviorTree.value = {
|
currentBehaviorTree.value = {
|
||||||
id: 0,
|
id: 0,
|
||||||
@@ -383,16 +379,15 @@ export default defineComponent({
|
|||||||
createdAt: null,
|
createdAt: null,
|
||||||
platformId: currentPlatformId.value,
|
platformId: currentPlatformId.value,
|
||||||
scenarioId: currentScenarioId.value,
|
scenarioId: currentScenarioId.value,
|
||||||
graph: {
|
graph: { ...graph },
|
||||||
edges: [],
|
|
||||||
nodes: [],
|
|
||||||
},
|
|
||||||
updatedAt: null,
|
updatedAt: null,
|
||||||
};
|
};
|
||||||
currentGraph.value = {
|
};
|
||||||
edges: [],
|
|
||||||
nodes: [],
|
const handleCreateTree = () => {
|
||||||
};
|
destroyGraph();
|
||||||
|
initGraphConfig();
|
||||||
|
|
||||||
selectedModelNode.value = null;
|
selectedModelNode.value = null;
|
||||||
selectedNodeTaskElement.value = null;
|
selectedNodeTaskElement.value = null;
|
||||||
subPlatforms.value = []; // 重置下属平台
|
subPlatforms.value = []; // 重置下属平台
|
||||||
@@ -412,6 +407,7 @@ export default defineComponent({
|
|||||||
try {
|
try {
|
||||||
graph.value = createCanvas(canvas.value);
|
graph.value = createCanvas(canvas.value);
|
||||||
console.log('画布初始化成功');
|
console.log('画布初始化成功');
|
||||||
|
initGraphConfig();
|
||||||
createElements();
|
createElements();
|
||||||
|
|
||||||
// 监听缩放变化
|
// 监听缩放变化
|
||||||
@@ -503,6 +499,7 @@ export default defineComponent({
|
|||||||
message.error('当前决策树不存在');
|
message.error('当前决策树不存在');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// return;
|
||||||
const newTree: BehaviorTree = {
|
const newTree: BehaviorTree = {
|
||||||
...currentBehaviorTree.value,
|
...currentBehaviorTree.value,
|
||||||
graph: graphData,
|
graph: graphData,
|
||||||
@@ -553,7 +550,6 @@ export default defineComponent({
|
|||||||
handleSelectScenario,
|
handleSelectScenario,
|
||||||
currentTreeEditing,
|
currentTreeEditing,
|
||||||
currentBehaviorTree,
|
currentBehaviorTree,
|
||||||
currentGraph,
|
|
||||||
selectedNodeTaskElement,
|
selectedNodeTaskElement,
|
||||||
selectedModelNode,
|
selectedModelNode,
|
||||||
graph,
|
graph,
|
||||||
|
|||||||
Reference in New Issue
Block a user