UPDATE: VERSION-20260327

This commit is contained in:
libertyspy
2026-03-27 10:35:23 +08:00
parent 168ced6b27
commit cb1019b7d7
3 changed files with 68 additions and 25 deletions

View File

@@ -114,8 +114,16 @@ export default defineComponent({
fitToScreen,
centerContent,
resizeCanvas,
destroyGraph,
clearGraph,
} = useGraphCanvas();
const destroy = ()=> {
window.removeEventListener('resize', handleResize);
destroyGraph();
graph.value = null;
}
const loadPlatforms = () => {
platforms.value = [];
findAllBasicPlatforms().then(r => {
@@ -213,6 +221,8 @@ export default defineComponent({
};
const handleSelectTree = (tree: BehaviorTree) => {
destroyGraph();
console.info('handleSelectTree', tree);
findOneTreeById(tree.id).then(r => {
if (r.data) {
@@ -233,7 +243,9 @@ export default defineComponent({
graph: nodeGraph,
};
currentTreeEditing.value = true;
createElements();
nextTick(() => {
initGraph();
});
} else {
message.error(r.msg ?? '行为树不存在.');
}
@@ -241,12 +253,8 @@ export default defineComponent({
};
const createElements = () => {
clearGraph();
nextTick(() => {
try {
graph.value?.clearCells();
} catch (e: any) {
console.error('clear cells error, cause:', e);
}
setTimeout(() => {
if (currentBehaviorTree.value?.graph && graph.value) {
if (currentBehaviorTree.value?.graph.nodes) {
@@ -274,6 +282,8 @@ export default defineComponent({
};
const handleCreateTree = () => {
destroyGraph();
currentBehaviorTree.value = {
id: 0,
name: '行为树',
@@ -294,7 +304,9 @@ export default defineComponent({
selectedModelNode.value = null;
selectedNodeTaskElement.value = null;
createElements();
nextTick(() => {
initGraph();
});
};
// 初始化X6画布
@@ -417,18 +429,7 @@ export default defineComponent({
});
// 清理
onBeforeUnmount(() => {
window.removeEventListener('resize', handleResize);
if (graph.value) {
try {
graph.value.clearCells();
} catch (error) {
console.warn('销毁画布时出错:', error);
}
graph.value = null;
console.log('画布已销毁');
}
});
onBeforeUnmount(() => destroy());
return {
platforms,