@@ -52,21 +54,19 @@ import { Wrapper } from '@/components/wrapper';
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
import Header from '../header.vue';
-import type { currentScenario, NodeDragTemplate, NodeTemplate } from '../types';
-import type { GraphTaskElement, NodeGraph } from '../builder/element';
-import { useGraphCanvas } from '../builder/hooks';
-import { registerNodeElement } from '../builder/register';
-import { createLineOptions } from '../builder/line';
-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, resolveGraph, useGraphCanvas } from '../graph';
+
+import { registerScenarioElement } from './register';
+import { createGraphScenarioElement, createGraphTaskElementFromScenario } from './utils';
import PlatformCard from './platform-card.vue';
import NodesCard from './nodes-card.vue';
+import { saveScenario } from './api';
const TeleportContainer = defineComponent(getTeleport());
-registerNodeElement();
+registerScenarioElement();
export default defineComponent({
components: {
@@ -84,15 +84,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 currentScenario = ref(null);
- const currentNodeGraph = ref(null);
+ const currentScenarioEditing = ref(false);
+ const currentScenario = 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 +105,7 @@ export default defineComponent({
} = useGraphCanvas();
// 处理拖动开始
- const handleDragStart = (nm: NodeDragTemplate) => {
+ const handleDragStart = (nm: PlatformWithComponents) => {
draggedNodeData.value = nm;
};
@@ -142,10 +142,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 +156,17 @@ export default defineComponent({
try {
// 获取拖动的数据
- const template = draggedNodeData.value as NodeDragTemplate;
+ const pwc = draggedNodeData.value as PlatformWithComponents;
- if (!hasElements(graph.value as Graph) && template.type !== 'root') {
- message.error('请先添加根节点.');
- return;
- }
+ // if (!hasElements(graph.value as Graph)) {
+ // message.error('请先添加根节点.');
+ // return;
+ // }
- if (hasRootElementNode(graph.value as Graph) && template.type === 'root') {
- message.error('根节点已经存在.');
- return;
- }
+ // if (hasRootElementNode(graph.value as Graph)) {
+ // message.error('根节点已经存在.');
+ // return;
+ // }
// 计算相对于画布的位置(考虑缩放)
const rect = canvas.value.getBoundingClientRect();
@@ -174,12 +174,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 = createGraphScenarioElement(settingTaskElement);
console.info('create settingTaskNode: ', settingTaskElement, settingTaskNode);
// 将节点添加到画布
@@ -193,32 +193,27 @@ export default defineComponent({
}
};
- const handleSelectTree = (tree: currentScenario) => {
- console.info('handleSelectTree', 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 = () => {
@@ -232,7 +227,7 @@ export default defineComponent({
if (currentScenario.value?.graph && graph.value) {
if (currentScenario.value?.graph.nodes) {
currentScenario.value?.graph.nodes.forEach(ele => {
- const node = createGraphTaskElement(ele as GraphTaskElement);
+ const node = createGraphScenarioElement(ele as GraphTaskElement);
console.info('create node: ', ele);
// 将节点添加到画布
graph.value?.addNode(node as Node);
@@ -254,21 +249,18 @@ export default defineComponent({
});
};
- const handleCreateTree = () => {
+ 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 +290,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 +340,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 +391,11 @@ export default defineComponent({
});
return {
- treesCardRef,
- handleCreateTree,
- currentTreeEditing,
+ scenariosCardRef,
+ handleCreate,
+ currentScenarioEditing,
currentScenario,
- currentNodeGraph,
+ currentGraph,
selectedNodeTaskElement,
selectedModelNode,
graph,
@@ -424,7 +412,7 @@ export default defineComponent({
isDraggingOver,
handleSave,
handleUpdateElement,
- handleSelectTree,
+ handleSelect,
};
},
});
diff --git a/modeler/src/views/decision/communication/node.vue b/modeler/src/views/decision/communication/node.vue
new file mode 100644
index 0000000..edd3b0f
--- /dev/null
+++ b/modeler/src/views/decision/communication/node.vue
@@ -0,0 +1,319 @@
+
+
+
+
+
+ {{ element?.description ?? element?.name ?? '-' }}
+
+
+
+
+
+
+
+
+
+
+
+ {{ substring(item.description ?? item.name, 20) }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 删除
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/modeler/src/views/decision/communication/nodes-card.vue b/modeler/src/views/decision/communication/nodes-card.vue
index 60605c7..da38e98 100644
--- a/modeler/src/views/decision/communication/nodes-card.vue
+++ b/modeler/src/views/decision/communication/nodes-card.vue
@@ -14,7 +14,7 @@
@dragend="handleDragEnd"
@dragstart="handleDragStart($event, nm)"
>
-
+
{{ nm.description ?? nm.name }}
@@ -27,23 +27,30 @@