From c3a6661d2a5eaad11c79c3bb5d96913f0ee27997 Mon Sep 17 00:00:00 2001 From: yitaikarma Date: Fri, 17 Apr 2026 21:43:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=96=E8=A1=8C=E4=B8=BA=E6=A0=91=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot --- .../src/views/decision/designer/designer.vue | 67 ++++++++++--------- .../views/decision/designer/trees-card.vue | 19 +----- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/modeler/src/views/decision/designer/designer.vue b/modeler/src/views/decision/designer/designer.vue index e91fb6c..05fd343 100644 --- a/modeler/src/views/decision/designer/designer.vue +++ b/modeler/src/views/decision/designer/designer.vue @@ -13,7 +13,7 @@ @@ -128,6 +128,7 @@ export default defineComponent({ const nodeCommands = ref([]) const currentScenarioId = ref(); const currentPlatformId = ref(null); + const currentTreeId = ref(null); const fromScenarioPage = ref(false); const { @@ -326,12 +327,35 @@ export default defineComponent({ selectedModelNode.value = null; selectedNodeTaskElement.value = null; loadSubPlatforms(currentPlatformId.value); - console.log('currentBehaviorTree.value: ', tree); nextTick(() => { initGraph(); - console.log('initGraphTree: ', tree); - + }); + }; + + const loadTargetTree = (tree: BehaviorTree) => { + currentTreeId.value = tree.id; + resolveBehaviorTreeGraph(tree.id, tree.xmlContent).then(nodeGraph => { + applyBehaviorTree({ + ...tree, + graph: nodeGraph, + }); + }).catch(error => { + console.error('resolve tree graph error:', error); + message.error('加载行为树图失败'); + }); + }; + + const handleCreateTree = () => { + destroyGraph(); + + selectedModelNode.value = null; + selectedNodeTaskElement.value = null; + subPlatforms.value = []; // 重置下属平台 + + initGraphConfig(); + nextTick(() => { + initGraph(); }); }; @@ -339,15 +363,7 @@ export default defineComponent({ console.info('handleSelectTree', tree); findOneTreeById(tree.id).then(r => { if (r.data) { - resolveBehaviorTreeGraph(r.data.id, r.data.xmlContent).then(nodeGraph => { - applyBehaviorTree({ - ...r.data, - graph: nodeGraph, - }); - }).catch(error => { - console.error('resolve tree graph error:', error); - message.error('加载行为树图失败'); - }); + loadTargetTree(r.data); } else { message.error(r.msg ?? '行为树不存在.'); } @@ -381,18 +397,7 @@ export default defineComponent({ currentScenarioId.value = scenario.id; }; - const handleCreateTree = () => { - destroyGraph(); - initGraphConfig(); - selectedModelNode.value = null; - selectedNodeTaskElement.value = null; - subPlatforms.value = []; // 重置下属平台 - - nextTick(() => { - initGraph(); - }); - }; // 初始化X6画布 const initGraph = () => { @@ -404,9 +409,7 @@ export default defineComponent({ try { graph.value = createCanvas(canvas.value); console.log('画布初始化成功'); - if (!currentBehaviorTree.value) { - initGraphConfig(); - } + createElements(); graph.value?.on('edge:click', (args: any) => { @@ -457,22 +460,23 @@ export default defineComponent({ console.info('init'); nextTick(() => { + initGraphConfig(); initGraph(); - window.addEventListener('resize', handleResize); console.log('节点挂载完成'); + window.addEventListener('resize', handleResize); + resolveQuery(); - if (currentPlatformId.value) { + if (currentPlatformId.value) { findOneTreeByPlatformId(currentPlatformId.value).then(r => { if (r.data) { - handleSelectTree(r.data); + loadTargetTree(r.data); } else { handleCreateTree(); } }); } else { - currentPlatformId.value = null; handleCreateTree(); } }); @@ -544,6 +548,7 @@ export default defineComponent({ nodeCommands, currentScenarioId, currentPlatformId, + currentTreeId, platforms, subPlatforms, scenariosCardRef, diff --git a/modeler/src/views/decision/designer/trees-card.vue b/modeler/src/views/decision/designer/trees-card.vue index 69988e8..e3e4c2a 100644 --- a/modeler/src/views/decision/designer/trees-card.vue +++ b/modeler/src/views/decision/designer/trees-card.vue @@ -18,7 +18,7 @@