diff --git a/modeler/src/views/decision/builder/index.ts b/modeler/src/views/decision/builder/index.ts deleted file mode 100644 index 2c375c6..0000000 --- a/modeler/src/views/decision/builder/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* - * This file is part of the kernelstudio package. - * - * (c) 2014-2025 zlin - * - * For the full copyright and license information, please view the LICENSE file - * that was distributed with this source code. - */ - -export { createGraphCanvas } from './graph'; -export * from './hooks'; \ No newline at end of file diff --git a/modeler/src/views/decision/communication/api.ts b/modeler/src/views/decision/communication/api.ts index 4db0889..8477293 100644 --- a/modeler/src/views/decision/communication/api.ts +++ b/modeler/src/views/decision/communication/api.ts @@ -8,7 +8,7 @@ */ import { HttpRequestClient } from '@/utils/request'; -import type { PlatformWithComponentsResponse, ScenarioPageableResponse, ScenarioRequest } from './types'; +import type { PlatformWithComponentsResponse, ScenarioPageableResponse, ScenarioRequest, Scenario } from './types'; import type { BasicResponse } from '@/types'; const req = HttpRequestClient.create({ @@ -24,5 +24,9 @@ export const deleteOneScenarioById = (id: number): Promise => { }; export const findPlatformWithComponents = (id: number): Promise => { - return req.get(`system/firerule/platforms/${id}`); + return req.get(`/system/firerule/platforms/${id}`); +}; + +export const saveScenario = (scenario: Scenario): Promise => { + return req.get(`/system/scene/saveSceneConfig`,scenario); }; \ No newline at end of file diff --git a/modeler/src/views/decision/communication/communication.vue b/modeler/src/views/decision/communication/communication.vue index eacb8a2..50e9e40 100644 --- a/modeler/src/views/decision/communication/communication.vue +++ b/modeler/src/views/decision/communication/communication.vue @@ -6,7 +6,7 @@
@@ -52,21 +52,19 @@ import { Wrapper } from '@/components/wrapper'; import { safePreventDefault, safeStopPropagation } from '@/utils/event'; import Header from '../header.vue'; -import type { Scenario } from './types'; -import { createLineOptions } from '../builder/line'; -import type { GraphTaskElement, NodeGraph } from '../builder/element'; -import { useGraphCanvas } from '../builder/hooks'; -import { registerNodeElement } from '../builder/register'; -import { createTree, findOneTreeById, updateTree } from '../designer/api'; -import { createGraphTaskElement, hasElements, hasRootElementNode, resolveNodeGraph } from '../builder/utils'; -import { createGraphTaskElementFromTemplate } from '../utils/node'; +import type { PlatformWithComponents, Scenario } from './types'; +import { createGraphTaskElement, createLineOptions, type GraphContainer, type GraphTaskElement, hasElements, hasRootElementNode, resolveGraph, useGraphCanvas } from '../graph'; + +import { registerScenarioElement } from './register'; +import { createGraphTaskElementFromScenario } from './utils'; import PlatformCard from './platform-card.vue'; import NodesCard from './nodes-card.vue'; +import { saveScenario } from '@/views/decision/communication/api.ts'; const TeleportContainer = defineComponent(getTeleport()); -registerNodeElement(); +registerScenarioElement(); export default defineComponent({ components: { @@ -84,15 +82,15 @@ export default defineComponent({ const canvas = ref(null); const graph = ref(null); const currentZoom = ref(1); - const draggedNodeData = ref(null); + const draggedNodeData = ref(null); const isDraggingOver = ref(false); - const currentTreeEditing = ref(false); + const currentScenarioEditing = ref(false); const currentScenario = ref(null); - const currentNodeGraph = ref(null); + const currentGraph = ref(null); const selectedModelNode = ref | null>(null); const selectedNodeTaskElement = ref(null); const changed = ref(false); - const treesCardRef = ref | null>(null); + const scenariosCardRef = ref | null>(null); const { handleGraphEvent, @@ -105,7 +103,7 @@ export default defineComponent({ } = useGraphCanvas(); // 处理拖动开始 - const handleDragStart = (nm: Scenario) => { + const handleDragStart = (nm: PlatformWithComponents) => { draggedNodeData.value = nm; }; @@ -142,10 +140,10 @@ export default defineComponent({ safePreventDefault(e); safeStopPropagation(e); isDraggingOver.value = false; - currentTreeEditing.value = false; + currentScenarioEditing.value = false; if (!currentScenario.value) { - message.error('请先选择或者创建行为树.'); + message.error('请先选择或者创建场景.'); return; } @@ -156,17 +154,17 @@ export default defineComponent({ try { // 获取拖动的数据 - const template = draggedNodeData.value as Scenario; + const pwc = draggedNodeData.value as PlatformWithComponents; - if (!hasElements(graph.value as Graph)) { - message.error('请先添加根节点.'); - return; - } + // if (!hasElements(graph.value as Graph)) { + // message.error('请先添加根节点.'); + // return; + // } - if (hasRootElementNode(graph.value as Graph)) { - message.error('根节点已经存在.'); - return; - } + // if (hasRootElementNode(graph.value as Graph)) { + // message.error('根节点已经存在.'); + // return; + // } // 计算相对于画布的位置(考虑缩放) const rect = canvas.value.getBoundingClientRect(); @@ -174,12 +172,12 @@ export default defineComponent({ const x = (e.clientX - rect.left) / scale; const y = (e.clientY - rect.top) / scale; - console.log('放置节点:', { ...template, x, y }); + console.log('放置节点:', { ...pwc, x, y }); // 创建节点数据 - const settingTaskElement: GraphTaskElement = createGraphTaskElementFromTemplate(template, { x, y }); + const settingTaskElement: GraphTaskElement = createGraphTaskElementFromScenario(pwc, { x, y }); // 创建节点 - const settingTaskNode = createGraphTaskElement(settingTaskElement); + const settingTaskNode = createGraphTaskElement(settingTaskElement, 250, 120, 'scenario'); console.info('create settingTaskNode: ', settingTaskElement, settingTaskNode); // 将节点添加到画布 @@ -193,32 +191,27 @@ export default defineComponent({ } }; - const handleSelect = (tree: Scenario) => { - console.info('handleSelect', tree); - findOneTreeById(tree.id).then(r => { - if (r.data) { - let nodeGraph: NodeGraph | null = null; - try { - nodeGraph = JSON.parse(r.data?.xmlContent as unknown as string) as unknown as NodeGraph; - } catch (e: any) { - console.error('parse error,cause:', e); - } - if (!nodeGraph) { - nodeGraph = { - nodes: [], - edges: [], - }; - } - currentScenario.value = { - ...r.data, - graph: nodeGraph, - }; - currentTreeEditing.value = true; - createElements(); - } else { - message.error(r.msg ?? '行为树不存在.'); - } - }); + const handleSelect = (scenario: Scenario) => { + console.info('handleSelect', scenario); + let nodeGraph: GraphContainer | null = null; + try { + nodeGraph = JSON.parse(scenario.communicationGraph as unknown as string) as unknown as GraphContainer; + } catch (e: any) { + console.error('parse error,cause:', e); + } + if (!nodeGraph) { + nodeGraph = { + nodes: [], + edges: [], + }; + } + currentScenario.value = { + ...scenario, + graph: nodeGraph, + }; + currentScenarioEditing.value = true; + createElements(); + }; const createElements = () => { @@ -257,18 +250,15 @@ export default defineComponent({ const handleCreate = () => { currentScenario.value = { id: 0, - name: '行为树', + name: null, description: null, - englishName: null, - xmlContent: null, - createdAt: null, + communicationGraph: null, graph: { edges: [], nodes: [], - }, - updatedAt: null, + } }; - currentNodeGraph.value = { + currentGraph.value = { edges: [], nodes: [], }; @@ -298,7 +288,7 @@ export default defineComponent({ handleGraphEvent('blank:click', () => { selectedModelNode.value = null; selectedNodeTaskElement.value = null; - currentTreeEditing.value = null !== currentScenario.value; + currentScenarioEditing.value = null !== currentScenario.value; }); handleGraphEvent('node:click', (args: any) => { @@ -348,34 +338,30 @@ export default defineComponent({ }; const handleSave = () => { - const graphData: NodeGraph = resolveNodeGraph(graph.value as Graph); + const graphData: GraphContainer = resolveGraph(graph.value as Graph); console.info('handleSave', graphData); if (!currentScenario.value) { message.error('当前决策树不存在'); return; } - const newTree: currentScenario = { + const newScenario: Scenario = { ...currentScenario.value, graph: graphData, - xmlContent: JSON.stringify(graphData), + communicationGraph: JSON.stringify(graphData), }; - if (!newTree.name) { - message.error('行为树名称不能为空.'); - return; - } - if (!newTree.englishName) { - message.error('行为树英文名称不能为空.'); + if (!newScenario.name) { + message.error('场景名称不能为空.'); return; } let res = null; if (currentScenario.value.id > 0) { - res = createTree(newTree); + res = saveScenario(newScenario); } else { - res = updateTree(newTree); + res = saveScenario(newScenario); } res.then(r => { if (r.code === 200) { - treesCardRef.value?.refresh(); + scenariosCardRef.value?.refresh(); message.success(r.msg ?? '操作成功.'); } else { message.error(r.msg ?? '操作失败.'); @@ -403,11 +389,11 @@ export default defineComponent({ }); return { - treesCardRef, + scenariosCardRef, handleCreate, - currentTreeEditing, + currentScenarioEditing, currentScenario, - currentNodeGraph, + currentGraph, selectedNodeTaskElement, selectedModelNode, graph, diff --git a/modeler/src/views/decision/communication/graph.ts b/modeler/src/views/decision/communication/graph.ts deleted file mode 100644 index a47cc82..0000000 --- a/modeler/src/views/decision/communication/graph.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * This file is part of the kernelstudio package. - * - * (c) 2014-2026 zlin - * - * For the full copyright and license information, please view the LICENSE file - * that was distributed with this source code. - */ diff --git a/modeler/src/views/decision/builder/node.vue b/modeler/src/views/decision/communication/node.vue similarity index 88% rename from modeler/src/views/decision/builder/node.vue rename to modeler/src/views/decision/communication/node.vue index b9738a4..211d1cc 100644 --- a/modeler/src/views/decision/builder/node.vue +++ b/modeler/src/views/decision/communication/node.vue @@ -2,28 +2,27 @@
-
+
-

+

{{ substring(element?.name ?? (element?.name ?? '-'), 40) }}

@@ -48,8 +47,8 @@