Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -34,7 +34,7 @@ public class SceneController extends BaseController {
|
|||||||
@Log(title = "行为树主", businessType = BusinessType.INSERT)
|
@Log(title = "行为树主", businessType = BusinessType.INSERT)
|
||||||
public AjaxResult saveSceneConfig(@RequestBody AfsimScenario afsimScenario)
|
public AjaxResult saveSceneConfig(@RequestBody AfsimScenario afsimScenario)
|
||||||
{
|
{
|
||||||
return toAjax(sceneService.insert(afsimScenario));
|
return toAjax(sceneService.saveOrUpdate(afsimScenario));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ public interface SceneMapper {
|
|||||||
*/
|
*/
|
||||||
int insert(AfsimScenario afsimScenario);
|
int insert(AfsimScenario afsimScenario);
|
||||||
|
|
||||||
|
int update(AfsimScenario afsimScenario);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取场景列表
|
* 获取场景列表
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ public interface SceneService {
|
|||||||
*/
|
*/
|
||||||
int insert(AfsimScenario afsimScenario);
|
int insert(AfsimScenario afsimScenario);
|
||||||
|
|
||||||
|
int update(AfsimScenario afsimScenario);
|
||||||
|
|
||||||
|
int saveOrUpdate(AfsimScenario afsimScenario);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取场景列表
|
* 获取场景列表
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
@@ -20,6 +20,19 @@ public class SceneServiceImpl implements SceneService {
|
|||||||
return sceneMapper.insert(afsimScenario);
|
return sceneMapper.insert(afsimScenario);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int update(AfsimScenario afsimScenario) {
|
||||||
|
return sceneMapper.update(afsimScenario);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int saveOrUpdate(AfsimScenario afsimScenario) {
|
||||||
|
if (null != afsimScenario.getId() && afsimScenario.getId() > 0) {
|
||||||
|
return sceneMapper.update(afsimScenario);
|
||||||
|
}
|
||||||
|
return insert(afsimScenario);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取场景列表
|
* 获取场景列表
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
@@ -4,13 +4,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.solution.scene.mapper.SceneMapper">
|
<mapper namespace="com.solution.scene.mapper.SceneMapper">
|
||||||
|
|
||||||
|
<resultMap id="SceneMap" type="com.solution.scene.domain.AfsimScenario">
|
||||||
|
<result property="id" column="id" />
|
||||||
|
<result property="name" column="name" />
|
||||||
|
<result property="description" column="description" />
|
||||||
|
<result property="scenarioPath" column="scenario_path" />
|
||||||
|
<result property="communicationGraph" column="communication_graph" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
<insert id="insert" parameterType="com.solution.scene.domain.AfsimScenario">
|
<insert id="insert" parameterType="com.solution.scene.domain.AfsimScenario">
|
||||||
INSERT INTO afsim_scenario (name, description, scenario_path, communication_graph)
|
INSERT INTO afsim_scenario (name, description, scenario_path, communication_graph)
|
||||||
VALUES (#{name}, #{description}, #{scenarioPath}, #{communicationGraph})
|
VALUES (#{name}, #{description}, #{scenarioPath}, #{communicationGraph})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<select id="selectSceneList" resultType="com.solution.scene.domain.AfsimScenario">
|
<select id="selectSceneList" resultMap="SceneMap">
|
||||||
SELECT id, name, description, scenario_path, communication_graph FROM afsim_scenario
|
SELECT id, name, description, scenario_path, communication_graph FROM afsim_scenario
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<insert id="update" parameterType="com.solution.scene.domain.AfsimScenario">
|
||||||
|
update afsim_scenario
|
||||||
|
set name=#{name},
|
||||||
|
description=#{description},
|
||||||
|
scenario_path=#{scenarioPath},
|
||||||
|
communication_graph=#{communicationGraph}
|
||||||
|
where id=#{id}
|
||||||
|
</insert>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
1
modeler/src/assets/icons/platform.svg
Normal file
1
modeler/src/assets/icons/platform.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1773577091908" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7408" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M285.952 623.616c-94.464 0-171.264-76.8-171.264-171.264s76.8-171.264 171.264-171.264c11.008 0 21.76 1.024 32.512 3.072 16.64 3.072 27.648 19.2 24.32 35.84-3.072 16.64-19.2 27.648-35.84 24.32-6.912-1.28-13.824-2.048-20.736-2.048-60.672 0-109.824 49.152-109.824 109.824s49.152 109.824 109.824 109.824c16.896 0 30.72 13.824 30.72 30.72s-14.08 30.976-30.976 30.976z" fill="#FFFFFF" p-id="7409"></path><path d="M313.088 343.296c-13.824 0-26.624-9.472-29.952-23.552-3.84-15.872-5.632-32.256-5.632-48.896 0-116.48 94.72-211.456 211.456-211.456 55.552 0 108.032 21.504 147.712 60.16 39.68 38.912 62.208 90.624 63.488 146.176 0.512 16.896-13.056 30.976-29.952 31.488h-0.768c-16.64 0-30.208-13.312-30.72-29.952-1.792-80.64-69.12-146.432-150.016-146.432-82.688 0-150.016 67.328-150.016 150.016 0 11.776 1.28 23.296 4.096 34.816 3.84 16.384-6.4 33.024-22.784 36.864-2.304 0.512-4.608 0.768-6.912 0.768z" fill="#FFFFFF" p-id="7410"></path><path d="M702.72 623.616c-16.896 0-30.72-13.824-30.72-30.72s13.824-30.72 30.72-30.72c73.472 0 133.12-59.648 133.12-133.12s-59.648-133.12-133.12-133.12c-8.96 0-18.176 1.024-26.88 2.816-16.64 3.328-32.768-7.424-36.352-24.064-3.328-16.64 7.424-32.768 23.808-36.352 12.8-2.56 26.112-3.84 39.168-3.84 107.264 0 194.56 87.296 194.56 194.56s-87.04 194.56-194.304 194.56z" fill="#FFFFFF" p-id="7411"></path><path d="M286.976 562.176h415.744v61.44H286.976z" fill="#FFFFFF" p-id="7412"></path><path d="M272.896 794.88H209.152v-61.44h63.744c4.608 0 8.448-3.84 8.448-8.448V599.04h61.44v125.952c0 38.656-31.232 69.888-69.888 69.888zM474.112 608.256h61.44v189.44h-61.44zM837.376 807.68H734.72c-38.4 0-69.888-31.232-69.888-69.888v-129.792h61.44v129.792c0 4.608 3.84 8.448 8.448 8.448h102.656v61.44z" fill="#FFFFFF" p-id="7413"></path><path d="M142.336 875.776c-59.392 0-107.52-48.128-107.52-107.52s48.128-107.52 107.52-107.52 107.52 48.128 107.52 107.52-48.128 107.52-107.52 107.52z m0-153.6c-25.344 0-46.08 20.736-46.08 46.08s20.736 46.08 46.08 46.08 46.08-20.736 46.08-46.08-20.736-46.08-46.08-46.08zM501.76 977.152c-59.392 0-107.52-48.128-107.52-107.52s48.128-107.52 107.52-107.52 107.52 48.128 107.52 107.52-48.384 107.52-107.52 107.52z m0-153.6c-25.344 0-46.08 20.736-46.08 46.08s20.736 46.08 46.08 46.08 46.08-20.736 46.08-46.08-20.736-46.08-46.08-46.08zM888.576 881.664c-59.392 0-107.52-48.128-107.52-107.52s48.128-107.52 107.52-107.52 107.52 48.128 107.52 107.52-48.384 107.52-107.52 107.52z m0-153.6c-25.344 0-46.08 20.736-46.08 46.08s20.736 46.08 46.08 46.08 46.08-20.736 46.08-46.08-20.736-46.08-46.08-46.08z" fill="#FFFFFF" p-id="7414"></path></svg>
|
||||||
|
After Width: | Height: | Size: 2.8 KiB |
@@ -1,11 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the kernelstudio package.
|
|
||||||
*
|
|
||||||
* (c) 2014-2025 zlin <admin@kernelstudio.com>
|
|
||||||
*
|
|
||||||
* 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';
|
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { HttpRequestClient } from '@/utils/request';
|
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';
|
import type { BasicResponse } from '@/types';
|
||||||
|
|
||||||
const req = HttpRequestClient.create<BasicResponse>({
|
const req = HttpRequestClient.create<BasicResponse>({
|
||||||
@@ -16,20 +16,7 @@ const req = HttpRequestClient.create<BasicResponse>({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const findScenarioByQuery = (_query: Partial<ScenarioRequest> = {}): Promise<ScenarioPageableResponse> => {
|
export const findScenarioByQuery = (_query: Partial<ScenarioRequest> = {}): Promise<ScenarioPageableResponse> => {
|
||||||
return new Promise((resolve) => {
|
return req.get('/system/scene/list', _query);
|
||||||
resolve({
|
|
||||||
code: 200,
|
|
||||||
msg: null,
|
|
||||||
total: 1,
|
|
||||||
rows: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: '空战场景',
|
|
||||||
description: null,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteOneScenarioById = (id: number): Promise<BasicResponse> => {
|
export const deleteOneScenarioById = (id: number): Promise<BasicResponse> => {
|
||||||
@@ -37,5 +24,9 @@ export const deleteOneScenarioById = (id: number): Promise<BasicResponse> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const findPlatformWithComponents = (id: number): Promise<PlatformWithComponentsResponse> => {
|
export const findPlatformWithComponents = (id: number): Promise<PlatformWithComponentsResponse> => {
|
||||||
return req.get(`system/firerule/platforms/${id}`);
|
return req.get(`/system/firerule/platforms/${id}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const saveScenario = (scenario: Scenario): Promise<BasicResponse> => {
|
||||||
|
return req.postJson(`/system/scene/saveSceneConfig`,scenario);
|
||||||
};
|
};
|
||||||
@@ -6,11 +6,13 @@
|
|||||||
<div class="ks-model-builder-body">
|
<div class="ks-model-builder-body">
|
||||||
<div class="ks-model-builder-left">
|
<div class="ks-model-builder-left">
|
||||||
<PlatformCard
|
<PlatformCard
|
||||||
ref="treesCardRef"
|
ref="scenariosCardRef"
|
||||||
@create-tree="handleCreateTree"
|
@create="handleCreate"
|
||||||
@select-tree="handleSelectTree"
|
@select="handleSelect"
|
||||||
/>
|
/>
|
||||||
<NodesCard
|
<NodesCard
|
||||||
|
v-if="currentScenario && currentScenario.id >0"
|
||||||
|
:scenario="currentScenario"
|
||||||
@drag-item-start="handleDragStart"
|
@drag-item-start="handleDragStart"
|
||||||
@drag-item-end="handleDragEnd"
|
@drag-item-end="handleDragEnd"
|
||||||
/>
|
/>
|
||||||
@@ -52,21 +54,19 @@ import { Wrapper } from '@/components/wrapper';
|
|||||||
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
||||||
import Header from '../header.vue';
|
import Header from '../header.vue';
|
||||||
|
|
||||||
import type { currentScenario, NodeDragTemplate, NodeTemplate } from '../types';
|
import type { PlatformWithComponents, Scenario } from './types';
|
||||||
import type { GraphTaskElement, NodeGraph } from '../builder/element';
|
import { createGraphTaskElement, createLineOptions, type GraphContainer, type GraphTaskElement, resolveGraph, useGraphCanvas } from '../graph';
|
||||||
import { useGraphCanvas } from '../builder/hooks';
|
|
||||||
import { registerNodeElement } from '../builder/register';
|
import { registerScenarioElement } from './register';
|
||||||
import { createLineOptions } from '../builder/line';
|
import { createGraphScenarioElement, createGraphTaskElementFromScenario } from './utils';
|
||||||
import { createTree, findOneTreeById, updateTree } from '../designer/api';
|
|
||||||
import { createGraphTaskElement, hasElements, hasRootElementNode, resolveNodeGraph } from '../builder/utils';
|
|
||||||
import { createGraphTaskElementFromTemplate } from '../utils/node';
|
|
||||||
|
|
||||||
import PlatformCard from './platform-card.vue';
|
import PlatformCard from './platform-card.vue';
|
||||||
import NodesCard from './nodes-card.vue';
|
import NodesCard from './nodes-card.vue';
|
||||||
|
import { saveScenario } from './api';
|
||||||
|
|
||||||
const TeleportContainer = defineComponent(getTeleport());
|
const TeleportContainer = defineComponent(getTeleport());
|
||||||
|
|
||||||
registerNodeElement();
|
registerScenarioElement();
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
@@ -84,15 +84,15 @@ export default defineComponent({
|
|||||||
const canvas = ref<HTMLDivElement | null>(null);
|
const canvas = ref<HTMLDivElement | null>(null);
|
||||||
const graph = ref<Graph | null>(null);
|
const graph = ref<Graph | null>(null);
|
||||||
const currentZoom = ref<number>(1);
|
const currentZoom = ref<number>(1);
|
||||||
const draggedNodeData = ref<NodeDragTemplate | null>(null);
|
const draggedNodeData = ref<PlatformWithComponents | null>(null);
|
||||||
const isDraggingOver = ref(false);
|
const isDraggingOver = ref(false);
|
||||||
const currentTreeEditing = ref<boolean>(false);
|
const currentScenarioEditing = ref<boolean>(false);
|
||||||
const currentScenario = ref<currentScenario | null>(null);
|
const currentScenario = ref<Scenario | null>(null);
|
||||||
const currentNodeGraph = ref<NodeGraph | 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);
|
||||||
const treesCardRef = ref<InstanceType<typeof PlatformCard> | null>(null);
|
const scenariosCardRef = ref<InstanceType<typeof PlatformCard> | null>(null);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
handleGraphEvent,
|
handleGraphEvent,
|
||||||
@@ -105,7 +105,7 @@ export default defineComponent({
|
|||||||
} = useGraphCanvas();
|
} = useGraphCanvas();
|
||||||
|
|
||||||
// 处理拖动开始
|
// 处理拖动开始
|
||||||
const handleDragStart = (nm: NodeDragTemplate) => {
|
const handleDragStart = (nm: PlatformWithComponents) => {
|
||||||
draggedNodeData.value = nm;
|
draggedNodeData.value = nm;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -142,10 +142,10 @@ export default defineComponent({
|
|||||||
safePreventDefault(e);
|
safePreventDefault(e);
|
||||||
safeStopPropagation(e);
|
safeStopPropagation(e);
|
||||||
isDraggingOver.value = false;
|
isDraggingOver.value = false;
|
||||||
currentTreeEditing.value = false;
|
currentScenarioEditing.value = false;
|
||||||
|
|
||||||
if (!currentScenario.value) {
|
if (!currentScenario.value) {
|
||||||
message.error('请先选择或者创建行为树.');
|
message.error('请先选择场景.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,17 +156,17 @@ export default defineComponent({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// 获取拖动的数据
|
// 获取拖动的数据
|
||||||
const template = draggedNodeData.value as NodeDragTemplate;
|
const pwc = draggedNodeData.value as PlatformWithComponents;
|
||||||
|
|
||||||
if (!hasElements(graph.value as Graph) && template.type !== 'root') {
|
// if (!hasElements(graph.value as Graph)) {
|
||||||
message.error('请先添加根节点.');
|
// message.error('请先添加根节点.');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (hasRootElementNode(graph.value as Graph) && template.type === 'root') {
|
// if (hasRootElementNode(graph.value as Graph)) {
|
||||||
message.error('根节点已经存在.');
|
// message.error('根节点已经存在.');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 计算相对于画布的位置(考虑缩放)
|
// 计算相对于画布的位置(考虑缩放)
|
||||||
const rect = canvas.value.getBoundingClientRect();
|
const rect = canvas.value.getBoundingClientRect();
|
||||||
@@ -174,12 +174,12 @@ export default defineComponent({
|
|||||||
const x = (e.clientX - rect.left) / scale;
|
const x = (e.clientX - rect.left) / scale;
|
||||||
const y = (e.clientY - rect.top) / 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);
|
console.info('create settingTaskNode: ', settingTaskElement, settingTaskNode);
|
||||||
|
|
||||||
// 将节点添加到画布
|
// 将节点添加到画布
|
||||||
@@ -193,32 +193,27 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectTree = (tree: currentScenario) => {
|
const handleSelect = (scenario: Scenario) => {
|
||||||
console.info('handleSelectTree', tree);
|
console.info('handleSelect', scenario);
|
||||||
findOneTreeById(tree.id).then(r => {
|
let nodeGraph: GraphContainer | null = null;
|
||||||
if (r.data) {
|
try {
|
||||||
let nodeGraph: NodeGraph | null = null;
|
nodeGraph = JSON.parse(scenario.communicationGraph as unknown as string) as unknown as GraphContainer;
|
||||||
try {
|
} catch (e: any) {
|
||||||
nodeGraph = JSON.parse(r.data?.xmlContent as unknown as string) as unknown as NodeGraph;
|
console.error('parse error,cause:', e);
|
||||||
} catch (e: any) {
|
}
|
||||||
console.error('parse error,cause:', e);
|
if (!nodeGraph) {
|
||||||
}
|
nodeGraph = {
|
||||||
if (!nodeGraph) {
|
nodes: [],
|
||||||
nodeGraph = {
|
edges: [],
|
||||||
nodes: [],
|
};
|
||||||
edges: [],
|
}
|
||||||
};
|
currentScenario.value = {
|
||||||
}
|
...scenario,
|
||||||
currentScenario.value = {
|
graph: nodeGraph,
|
||||||
...r.data,
|
};
|
||||||
graph: nodeGraph,
|
currentScenarioEditing.value = true;
|
||||||
};
|
createElements();
|
||||||
currentTreeEditing.value = true;
|
|
||||||
createElements();
|
|
||||||
} else {
|
|
||||||
message.error(r.msg ?? '行为树不存在.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const createElements = () => {
|
const createElements = () => {
|
||||||
@@ -232,7 +227,7 @@ export default defineComponent({
|
|||||||
if (currentScenario.value?.graph && graph.value) {
|
if (currentScenario.value?.graph && graph.value) {
|
||||||
if (currentScenario.value?.graph.nodes) {
|
if (currentScenario.value?.graph.nodes) {
|
||||||
currentScenario.value?.graph.nodes.forEach(ele => {
|
currentScenario.value?.graph.nodes.forEach(ele => {
|
||||||
const node = createGraphTaskElement(ele as GraphTaskElement);
|
const node = createGraphScenarioElement(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);
|
||||||
@@ -254,21 +249,18 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCreateTree = () => {
|
const handleCreate = () => {
|
||||||
currentScenario.value = {
|
currentScenario.value = {
|
||||||
id: 0,
|
id: 0,
|
||||||
name: '行为树',
|
name: null,
|
||||||
description: null,
|
description: null,
|
||||||
englishName: null,
|
communicationGraph: null,
|
||||||
xmlContent: null,
|
|
||||||
createdAt: null,
|
|
||||||
graph: {
|
graph: {
|
||||||
edges: [],
|
edges: [],
|
||||||
nodes: [],
|
nodes: [],
|
||||||
},
|
}
|
||||||
updatedAt: null,
|
|
||||||
};
|
};
|
||||||
currentNodeGraph.value = {
|
currentGraph.value = {
|
||||||
edges: [],
|
edges: [],
|
||||||
nodes: [],
|
nodes: [],
|
||||||
};
|
};
|
||||||
@@ -298,7 +290,7 @@ export default defineComponent({
|
|||||||
handleGraphEvent('blank:click', () => {
|
handleGraphEvent('blank:click', () => {
|
||||||
selectedModelNode.value = null;
|
selectedModelNode.value = null;
|
||||||
selectedNodeTaskElement.value = null;
|
selectedNodeTaskElement.value = null;
|
||||||
currentTreeEditing.value = null !== currentScenario.value;
|
currentScenarioEditing.value = null !== currentScenario.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
handleGraphEvent('node:click', (args: any) => {
|
handleGraphEvent('node:click', (args: any) => {
|
||||||
@@ -348,34 +340,30 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
const graphData: NodeGraph = resolveNodeGraph(graph.value as Graph);
|
const graphData: GraphContainer = resolveGraph(graph.value as Graph);
|
||||||
console.info('handleSave', graphData);
|
console.info('handleSave', graphData);
|
||||||
if (!currentScenario.value) {
|
if (!currentScenario.value) {
|
||||||
message.error('当前决策树不存在');
|
message.error('当前决策树不存在');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const newTree: currentScenario = {
|
const newScenario: Scenario = {
|
||||||
...currentScenario.value,
|
...currentScenario.value,
|
||||||
graph: graphData,
|
graph: graphData,
|
||||||
xmlContent: JSON.stringify(graphData),
|
communicationGraph: JSON.stringify(graphData),
|
||||||
};
|
};
|
||||||
if (!newTree.name) {
|
if (!newScenario.name) {
|
||||||
message.error('行为树名称不能为空.');
|
message.error('场景名称不能为空.');
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!newTree.englishName) {
|
|
||||||
message.error('行为树英文名称不能为空.');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let res = null;
|
let res = null;
|
||||||
if (currentScenario.value.id > 0) {
|
if (currentScenario.value.id > 0) {
|
||||||
res = createTree(newTree);
|
res = saveScenario(newScenario);
|
||||||
} else {
|
} else {
|
||||||
res = updateTree(newTree);
|
res = saveScenario(newScenario);
|
||||||
}
|
}
|
||||||
res.then(r => {
|
res.then(r => {
|
||||||
if (r.code === 200) {
|
if (r.code === 200) {
|
||||||
treesCardRef.value?.refresh();
|
scenariosCardRef.value?.refresh();
|
||||||
message.success(r.msg ?? '操作成功.');
|
message.success(r.msg ?? '操作成功.');
|
||||||
} else {
|
} else {
|
||||||
message.error(r.msg ?? '操作失败.');
|
message.error(r.msg ?? '操作失败.');
|
||||||
@@ -403,11 +391,11 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
treesCardRef,
|
scenariosCardRef,
|
||||||
handleCreateTree,
|
handleCreate,
|
||||||
currentTreeEditing,
|
currentScenarioEditing,
|
||||||
currentScenario,
|
currentScenario,
|
||||||
currentNodeGraph,
|
currentGraph,
|
||||||
selectedNodeTaskElement,
|
selectedNodeTaskElement,
|
||||||
selectedModelNode,
|
selectedModelNode,
|
||||||
graph,
|
graph,
|
||||||
@@ -424,7 +412,7 @@ export default defineComponent({
|
|||||||
isDraggingOver,
|
isDraggingOver,
|
||||||
handleSave,
|
handleSave,
|
||||||
handleUpdateElement,
|
handleUpdateElement,
|
||||||
handleSelectTree,
|
handleSelect,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
319
modeler/src/views/decision/communication/node.vue
Normal file
319
modeler/src/views/decision/communication/node.vue
Normal file
@@ -0,0 +1,319 @@
|
|||||||
|
<template>
|
||||||
|
<a-dropdown :trigger="['contextmenu']" @openChange="handleVisibleChange">
|
||||||
|
<a-card
|
||||||
|
:class="[
|
||||||
|
'ks-scenario-node',
|
||||||
|
`ks-scenario-${element?.category ?? 'model'}-node`
|
||||||
|
]"
|
||||||
|
hoverable
|
||||||
|
>
|
||||||
|
<template #title>
|
||||||
|
<a-space>
|
||||||
|
<span class="ks-scenario-node-title">{{ element?.description ?? element?.name ?? '-' }}</span>
|
||||||
|
</a-space>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- 节点内容区域 -->
|
||||||
|
<div class="w-full">
|
||||||
|
<div class="ks-scenario-node-content">
|
||||||
|
<div
|
||||||
|
v-for="(item, index) in element?.components || []"
|
||||||
|
:key="item.id || index"
|
||||||
|
class="ks-scenario-node-row"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
:data-port="`in-${item.id || index}`"
|
||||||
|
:title="`入桩: ${item.name}`"
|
||||||
|
class="port port-in"
|
||||||
|
magnet="passive"
|
||||||
|
>
|
||||||
|
<div class="triangle-left"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- child名称 -->
|
||||||
|
<div class="ks-scenario-node-name">
|
||||||
|
{{ substring(item.description ?? item.name, 20) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 右侧出桩:只能作为连线源 -->
|
||||||
|
<div
|
||||||
|
:data-port="`out-${item.id || index}`"
|
||||||
|
:title="`出桩: ${item.name}`"
|
||||||
|
class="port port-out"
|
||||||
|
magnet="active"
|
||||||
|
>
|
||||||
|
<div class="triangle-right" ></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a-card>
|
||||||
|
|
||||||
|
<template #overlay>
|
||||||
|
<a-menu @click="handleMenuClick">
|
||||||
|
<a-menu-item key="delete">
|
||||||
|
<template #icon>
|
||||||
|
<DeleteOutlined />
|
||||||
|
</template>
|
||||||
|
删除
|
||||||
|
</a-menu-item>
|
||||||
|
</a-menu>
|
||||||
|
</template>
|
||||||
|
</a-dropdown>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent, onMounted, onUnmounted, ref } from 'vue';
|
||||||
|
import { elementProps, type ModelElement } from '../graph';
|
||||||
|
|
||||||
|
import { DeleteOutlined, SettingOutlined } from '@ant-design/icons-vue';
|
||||||
|
import type { Graph } from '@antv/x6';
|
||||||
|
import { substring } from '@/utils/strings';
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'ModelElement',
|
||||||
|
components: {
|
||||||
|
SettingOutlined,
|
||||||
|
DeleteOutlined,
|
||||||
|
},
|
||||||
|
props: elementProps,
|
||||||
|
setup(_props) {
|
||||||
|
const element = ref<ModelElement | null>(
|
||||||
|
_props.node ? (_props.node.getData() as ModelElement) : null,
|
||||||
|
);
|
||||||
|
const updateKey = ref(0);
|
||||||
|
const isMenuVisible = ref(false);
|
||||||
|
|
||||||
|
// 获取画布实例
|
||||||
|
const getGraph = (): Graph | null => {
|
||||||
|
return _props.graph as Graph || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 监听节点数据变化
|
||||||
|
const handleDataChange = () => {
|
||||||
|
if (_props.node) {
|
||||||
|
element.value = _props.node.getData() as ModelElement;
|
||||||
|
} else {
|
||||||
|
element.value = null;
|
||||||
|
}
|
||||||
|
updateKey.value++;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleVisibleChange = (visible: boolean) => {
|
||||||
|
isMenuVisible.value = visible;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMenuClick = ({ key }: { key: string }) => {
|
||||||
|
if (key === 'delete') {
|
||||||
|
handleDelete();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = () => {
|
||||||
|
if (!_props.node) return;
|
||||||
|
|
||||||
|
const graph = getGraph();
|
||||||
|
if (graph) {
|
||||||
|
try {
|
||||||
|
// 先删除关联边
|
||||||
|
const connectedEdges = graph.getConnectedEdges(_props.node);
|
||||||
|
connectedEdges.forEach(edge => graph.removeEdge(edge));
|
||||||
|
// 再删除节点
|
||||||
|
graph.removeNode(_props.node);
|
||||||
|
console.info(`节点 ${_props.node.id} 已删除`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('删除节点失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isMenuVisible.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
_props.node?.on('change:data', handleDataChange);
|
||||||
|
console.error('element',element.value)
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
_props.node?.off('change:data', handleDataChange);
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
element,
|
||||||
|
substring,
|
||||||
|
handleMenuClick,
|
||||||
|
handleVisibleChange,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less">
|
||||||
|
.ks-scenario-node {
|
||||||
|
background: linear-gradient(150deg, rgba(108, 99, 255) 1%, rgba(108, 99, 255) 100%);
|
||||||
|
border-radius: 8px;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
cursor: pointer;
|
||||||
|
position: relative;
|
||||||
|
background: #1e2533;
|
||||||
|
border: 1px solid #4a7aff;
|
||||||
|
|
||||||
|
border: 2px solid #000000;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border: 2px solid #4a7aff;
|
||||||
|
box-shadow: 0 0 10px rgba(74, 122, 255, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-card-head {
|
||||||
|
border: 0;
|
||||||
|
height: 28px;
|
||||||
|
min-height: 25px;
|
||||||
|
border-radius: 0;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: normal;
|
||||||
|
padding: 0 20px;
|
||||||
|
//background: linear-gradient(to bottom, #3a4c70, #2d3a56);
|
||||||
|
border-top-left-radius: 8px;
|
||||||
|
border-top-right-radius: 8px;
|
||||||
|
background: linear-gradient(to bottom, rgba(108, 99, 255, 0.15), rgba(108, 99, 255, 0.05));
|
||||||
|
//background: url('@/assets/icons/bg-node-head.png') center / 100% 100%;
|
||||||
|
//background: linear-gradient(to bottom, rgb(234 234 234 / 20%), rgb(191 191 191 / 58%));
|
||||||
|
background: url('@/assets/icons/card-head-red.png') center / 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ks-scenario-node-icon {
|
||||||
|
width: 15px;
|
||||||
|
height: 15px;
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
left: 8px;
|
||||||
|
top: 6px;
|
||||||
|
background: url('@/assets/icons/icon-node.svg') center / 100% 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ks-scenario-node-title {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #fff;
|
||||||
|
margin-top: -7px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-card-body {
|
||||||
|
color: #f5f5f5;
|
||||||
|
height: calc(100% - 25px);
|
||||||
|
border-radius: 0;
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 10px 30px !important;
|
||||||
|
//border-top: 1px solid rgba(108, 99, 255, 0.5);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
box-shadow: 0 0 10px rgba(74, 122, 255, 0.3);
|
||||||
|
|
||||||
|
white-space: normal; // 恢复默认的换行行为
|
||||||
|
word-wrap: break-word; // 允许长单词换行
|
||||||
|
word-break: break-all; // 允许在任意字符处换行
|
||||||
|
line-height: 1.4; // 增加行高提升可读性
|
||||||
|
box-shadow: 0 0 10px rgba(74, 122, 255, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 连接桩容器样式
|
||||||
|
.ks-scenario-node-content {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ks-scenario-node-row {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
min-height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.port {
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
border-radius: 50%;
|
||||||
|
cursor: crosshair;
|
||||||
|
flex-shrink: 0;
|
||||||
|
box-shadow: 0 0 0 2px rgb(108, 99, 255, 0.8);
|
||||||
|
z-index: 10;
|
||||||
|
magnet: true;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.triangle-left {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
border-top: 4px solid transparent;
|
||||||
|
border-right: 5px solid #5da1df;
|
||||||
|
border-bottom: 4px solid transparent;
|
||||||
|
position: absolute;
|
||||||
|
left: -8px;
|
||||||
|
top: 0.5px;
|
||||||
|
magnet: passive;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 右三角形 */
|
||||||
|
.triangle-right {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
border-top: 4px solid transparent;
|
||||||
|
border-left: 5px solid #5da1df;
|
||||||
|
border-bottom: 4px solid transparent;
|
||||||
|
position: absolute;
|
||||||
|
right: -8px;
|
||||||
|
top: 0.5px;
|
||||||
|
magnet: passive;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 左侧入桩样式
|
||||||
|
.port-in {
|
||||||
|
//background-color: #3c82f6;
|
||||||
|
margin-right: 8px;
|
||||||
|
//border: 1px solid #093866;
|
||||||
|
magnet: passive;
|
||||||
|
box-shadow: none;
|
||||||
|
width: 13px;
|
||||||
|
height: 13px;
|
||||||
|
display: block;
|
||||||
|
//background: url('@/assets/icons/point.svg') center / 100% 100%;
|
||||||
|
border: 2px solid #5da1df;
|
||||||
|
|
||||||
|
position: absolute;
|
||||||
|
//top: 7px;
|
||||||
|
left: -17px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.port-out {
|
||||||
|
margin-left: 8px;
|
||||||
|
margin-right: 5px;
|
||||||
|
magnet: active;
|
||||||
|
box-shadow: none;
|
||||||
|
width: 13px;
|
||||||
|
height: 13px;
|
||||||
|
display: block;
|
||||||
|
border: 2px solid #5da1df;
|
||||||
|
background:#5da1df;
|
||||||
|
|
||||||
|
position: absolute;
|
||||||
|
right: -17px;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 节点文本样式
|
||||||
|
.ks-scenario-node-name {
|
||||||
|
flex: 1;
|
||||||
|
line-height: 24px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
@dragend="handleDragEnd"
|
@dragend="handleDragEnd"
|
||||||
@dragstart="handleDragStart($event, nm)"
|
@dragstart="handleDragStart($event, nm)"
|
||||||
>
|
>
|
||||||
<img :alt="nm.description ?? nm.name ?? ''" class="icon" src="@/assets/icons/model-4.svg" />
|
<img :alt="nm.description ?? nm.name ?? ''" class="icon" src="@/assets/icons/model.svg" />
|
||||||
<span class="desc">{{ nm.description ?? nm.name }}</span>
|
<span class="desc">{{ nm.description ?? nm.name }}</span>
|
||||||
</div>
|
</div>
|
||||||
</a-col>
|
</a-col>
|
||||||
@@ -27,23 +27,30 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, onMounted, ref } from 'vue';
|
import { defineComponent, onMounted, type PropType, ref } from 'vue';
|
||||||
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
||||||
import {findPlatformWithComponents} from './api'
|
import {findPlatformWithComponents} from './api'
|
||||||
import {type PlatformWithComponents} from './types'
|
import { type PlatformWithComponents, type Scenario } from './types';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
emits: ['drag-item-start', 'drag-item-end'],
|
emits: ['drag-item-start', 'drag-item-end'],
|
||||||
|
props: {
|
||||||
|
scenario: {
|
||||||
|
type: Object as PropType<Scenario>,
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
setup(_props, { emit }) {
|
setup(_props, { emit }) {
|
||||||
|
|
||||||
const activeKey = ref<number>(1);
|
const activeKey = ref<number>(1);
|
||||||
const templateData = ref<PlatformWithComponents[]>([]);
|
const templateData = ref<PlatformWithComponents[]>([]);
|
||||||
const isDraggingOver = ref<boolean>(false);
|
const isDraggingOver = ref<boolean>(false);
|
||||||
const draggedNodeData = ref<PlatformWithComponents | null>(null);
|
const draggedNodeData = ref<PlatformWithComponents | null>(null);
|
||||||
|
const currentScenario = ref<Scenario|null>(_props.scenario)
|
||||||
|
|
||||||
const loadTress = () => {
|
const loadTress = () => {
|
||||||
templateData.value = []
|
templateData.value = []
|
||||||
findPlatformWithComponents(1).then(r => {
|
findPlatformWithComponents(_props.scenario?.id).then(r => {
|
||||||
templateData.value = r.data ?? []
|
templateData.value = r.data ?? []
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -70,7 +77,7 @@ export default defineComponent({
|
|||||||
`;
|
`;
|
||||||
document.body.appendChild(dragPreview);
|
document.body.appendChild(dragPreview);
|
||||||
e.dataTransfer.setDragImage(dragPreview, dragPreview.offsetWidth / 2, dragPreview.offsetHeight / 2);
|
e.dataTransfer.setDragImage(dragPreview, dragPreview.offsetWidth / 2, dragPreview.offsetHeight / 2);
|
||||||
emit('drag-item-start', dragNode, group, isDraggingOver.value, e);
|
emit('drag-item-start', dragNode, isDraggingOver.value, e);
|
||||||
console.log('开始拖动:', dragNode);
|
console.log('开始拖动:', dragNode);
|
||||||
setTimeout(() => document.body.removeChild(dragPreview), 0);
|
setTimeout(() => document.body.removeChild(dragPreview), 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
<div class="w-full" style="padding: 5px;">
|
<div class="w-full" style="padding: 5px;">
|
||||||
<a-flex>
|
<a-flex>
|
||||||
<a-input-search v-model:value="scenarioQuery.name" allowClear placeholder="场景名称" size="small" @search="loadTress" />
|
<a-input-search v-model:value="scenarioQuery.name" allowClear placeholder="场景名称" size="small" @search="loadTress" />
|
||||||
<!-- <a-button size="small" style="margin-left: 10px;">-->
|
<!-- <a-button size="small" style="margin-left: 10px;">-->
|
||||||
<!-- <PlusOutlined style="margin-top: 0px;display: block;" @click="$emit('create-tree')" />-->
|
<!-- <PlusOutlined style="margin-top: 0px;display: block;" @click="$emit('create-tree')" />-->
|
||||||
<!-- </a-button>-->
|
<!-- </a-button>-->
|
||||||
</a-flex>
|
</a-flex>
|
||||||
</div>
|
</div>
|
||||||
<a-list :data-source="scenario || []" size="small" style="min-height: 25vh">
|
<a-list :data-source="scenario || []" size="small" style="min-height: 25vh">
|
||||||
@@ -29,18 +29,19 @@
|
|||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
<a-flex class="ks-tree-actions">
|
<a-flex class="ks-tree-actions">
|
||||||
<span style="margin-right: 10px" @click="()=> handleSelect(item)"><EditFilled /></span>
|
<span style="margin-right: 10px" @click="()=> handleSelect(item)"><EditFilled /></span>
|
||||||
<a-popconfirm
|
<!-- <a-popconfirm-->
|
||||||
title="确定删除?"
|
<!-- title="确定删除?"-->
|
||||||
@confirm="()=> handleDelete(item)"
|
<!-- @confirm="()=> handleDelete(item)"-->
|
||||||
>
|
<!-- >-->
|
||||||
<span class="ks-tree-action ks-tree-action-delete"><DeleteOutlined /></span>
|
<!-- <span class="ks-tree-action ks-tree-action-delete"><DeleteOutlined /></span>-->
|
||||||
</a-popconfirm>
|
<!-- </a-popconfirm>-->
|
||||||
</a-flex>
|
</a-flex>
|
||||||
</a-flex>
|
</a-flex>
|
||||||
</a-list-item>
|
</a-list-item>
|
||||||
</template>
|
</template>
|
||||||
</a-list>
|
</a-list>
|
||||||
<a-pagination
|
<a-pagination
|
||||||
|
v-if="totalTress > Number(scenarioQuery?.pageSize ?? 0)"
|
||||||
v-model:current="scenarioQuery.pageNum"
|
v-model:current="scenarioQuery.pageNum"
|
||||||
:page-size="scenarioQuery.pageSize"
|
:page-size="scenarioQuery.pageSize"
|
||||||
:total="totalTress"
|
:total="totalTress"
|
||||||
@@ -57,7 +58,7 @@ import { deleteOneScenarioById, findScenarioByQuery } from './api';
|
|||||||
import { substring } from '@/utils/strings';
|
import { substring } from '@/utils/strings';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
emits: ['select-tree', 'create-tree'],
|
emits: ['select', 'create'],
|
||||||
components: {
|
components: {
|
||||||
CheckOutlined,
|
CheckOutlined,
|
||||||
PlusOutlined,
|
PlusOutlined,
|
||||||
|
|||||||
@@ -18,10 +18,10 @@
|
|||||||
import { register } from '@antv/x6-vue-shape';
|
import { register } from '@antv/x6-vue-shape';
|
||||||
import ModelElement from './node.vue';
|
import ModelElement from './node.vue';
|
||||||
|
|
||||||
export const registerNodeElement = () => {
|
export const registerScenarioElement = () => {
|
||||||
console.info('registerNodeElement');
|
console.info('registerScenarioElement');
|
||||||
register({
|
register({
|
||||||
shape: 'task',
|
shape: 'scenario',
|
||||||
component: ModelElement,
|
component: ModelElement,
|
||||||
width: 120,
|
width: 120,
|
||||||
attrs: {
|
attrs: {
|
||||||
@@ -9,11 +9,15 @@
|
|||||||
|
|
||||||
|
|
||||||
import type { ApiDataResponse, NullableString, PageableResponse } from '@/types';
|
import type { ApiDataResponse, NullableString, PageableResponse } from '@/types';
|
||||||
|
import type { GraphContainer } from '../graph';
|
||||||
|
|
||||||
export interface Scenario {
|
export interface Scenario {
|
||||||
id: number,
|
id: number,
|
||||||
name: NullableString,
|
name: NullableString,
|
||||||
description: NullableString,
|
description: NullableString,
|
||||||
|
// 用于存储场景中的通讯关系
|
||||||
|
communicationGraph: NullableString,
|
||||||
|
graph: GraphContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ScenarioRequest extends Scenario {
|
export interface ScenarioRequest extends Scenario {
|
||||||
|
|||||||
79
modeler/src/views/decision/communication/utils.ts
Normal file
79
modeler/src/views/decision/communication/utils.ts
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the kernelstudio package.
|
||||||
|
*
|
||||||
|
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE file
|
||||||
|
* that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { GraphRect, GraphTaskElement } from '../graph';
|
||||||
|
import { generateKey } from '@/utils/strings';
|
||||||
|
import type { PlatformWithComponents } from './types';
|
||||||
|
|
||||||
|
export const createGraphTaskElementFromScenario = (
|
||||||
|
platform: PlatformWithComponents,
|
||||||
|
rect?: GraphRect,
|
||||||
|
): GraphTaskElement => {
|
||||||
|
let realRect = { width: 120, height: 80, x: 0, y: 0, ...rect || {} };
|
||||||
|
console.info('rect', rect);
|
||||||
|
return {
|
||||||
|
id: 0,
|
||||||
|
key: generateKey(),
|
||||||
|
type: 'scenario',
|
||||||
|
name: platform.name,
|
||||||
|
platformId: platform.id,
|
||||||
|
scenarioId: platform.scenarioId,
|
||||||
|
components: platform.components ?? [],
|
||||||
|
template: 0,
|
||||||
|
templateType: null,
|
||||||
|
category: null,
|
||||||
|
group: null,
|
||||||
|
description: platform.description,
|
||||||
|
order: 0,
|
||||||
|
position: {
|
||||||
|
x: realRect.x ?? 0,
|
||||||
|
y: realRect.y ?? 0,
|
||||||
|
},
|
||||||
|
width: realRect.width,
|
||||||
|
height: realRect.height,
|
||||||
|
inputs: null,
|
||||||
|
outputs: null,
|
||||||
|
parameters: [],
|
||||||
|
variables: [],
|
||||||
|
} as GraphTaskElement;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createGraphScenarioElement = (element: GraphTaskElement): any => {
|
||||||
|
let realHeight = 120;
|
||||||
|
let width: number = 250;
|
||||||
|
if (!realHeight) {
|
||||||
|
realHeight = 120;
|
||||||
|
}
|
||||||
|
if(element?.components){
|
||||||
|
if(element?.components?.length > 2){
|
||||||
|
realHeight = 90 + element?.components?.length * 25
|
||||||
|
} else if(element?.components?.length <=1){
|
||||||
|
realHeight = 120
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
shape: 'scenario',
|
||||||
|
id: element.key,
|
||||||
|
position: {
|
||||||
|
x: element.position?.x || 0,
|
||||||
|
y: element.position?.y || 0,
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
width: width,
|
||||||
|
height: realHeight,
|
||||||
|
},
|
||||||
|
attrs: {
|
||||||
|
label: {
|
||||||
|
text: element.name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: element,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { HttpRequestClient } from '@/utils/request';
|
import { HttpRequestClient } from '@/utils/request';
|
||||||
import type { BehaviorTree, BehaviorTreeDetailsResponse, BehaviorTreePageResponse, BehaviorTreeRequest, NodeTemplatesResponse } from '../types';
|
import type { NodeTemplatesResponse } from './template';
|
||||||
|
import type { BehaviorTree, BehaviorTreeDetailsResponse, BehaviorTreePageResponse, BehaviorTreeRequest } from './tree';
|
||||||
import type { BasicResponse } from '@/types';
|
import type { BasicResponse } from '@/types';
|
||||||
|
|
||||||
const req = HttpRequestClient.create<BasicResponse>({
|
const req = HttpRequestClient.create<BasicResponse>({
|
||||||
|
|||||||
@@ -19,27 +19,12 @@
|
|||||||
<div class="ks-model-builder-content">
|
<div class="ks-model-builder-content">
|
||||||
<div class="ks-model-builder-actions">
|
<div class="ks-model-builder-actions">
|
||||||
<a-space>
|
<a-space>
|
||||||
<!-- <a-tooltip v-if="graph && currentBehaviorTree" placement="top">-->
|
|
||||||
<!-- <template #title>-->
|
|
||||||
<!-- 保存-->
|
|
||||||
<!-- </template>-->
|
|
||||||
<!-- <a-popconfirm-->
|
|
||||||
<!-- title="确定保存?"-->
|
|
||||||
<!-- @confirm="handleSave"-->
|
|
||||||
<!-- >-->
|
|
||||||
<!-- <a-button class="ks-model-builder-save" size="small">-->
|
|
||||||
<!-- <CheckOutlined />-->
|
|
||||||
<!-- <span>保存</span>-->
|
|
||||||
<!-- </a-button>-->
|
|
||||||
<!-- </a-popconfirm>-->
|
|
||||||
<!-- </a-tooltip>-->
|
|
||||||
<a-button v-if="graph && currentBehaviorTree" class="ks-model-builder-save" size="small" @click="handleSave">
|
<a-button v-if="graph && currentBehaviorTree" class="ks-model-builder-save" size="small" @click="handleSave">
|
||||||
<CheckOutlined />
|
<CheckOutlined />
|
||||||
<span>保存</span>
|
<span>保存</span>
|
||||||
</a-button>
|
</a-button>
|
||||||
</a-space>
|
</a-space>
|
||||||
</div>
|
</div>
|
||||||
<!-- 画布容器,添加拖放事件 -->
|
|
||||||
<div
|
<div
|
||||||
ref="canvas"
|
ref="canvas"
|
||||||
class="ks-model-builder-canvas"
|
class="ks-model-builder-canvas"
|
||||||
@@ -74,14 +59,14 @@ import { Wrapper } from '@/components/wrapper';
|
|||||||
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
||||||
import Header from '../header.vue';
|
import Header from '../header.vue';
|
||||||
import Properties from './properties.vue';
|
import Properties from './properties.vue';
|
||||||
import type { BehaviorTree, NodeDragTemplate, NodeTemplate } from '../types';
|
import type { NodeDragTemplate } from './template';
|
||||||
import type { GraphTaskElement, NodeGraph } from '../builder/element';
|
import type { BehaviorTree } from './tree';
|
||||||
import { useGraphCanvas } from '../builder/hooks';
|
import { createGraphTaskElementFromTemplate } from './utils';
|
||||||
import { registerNodeElement } from '../builder/register';
|
|
||||||
import { createLineOptions } from '../builder/line';
|
import { createGraphTaskElement, createLineOptions, type GraphContainer, type GraphTaskElement, hasElements, hasRootElementNode, resolveGraph, useGraphCanvas } from '../graph';
|
||||||
|
import { registerNodeElement } from './register';
|
||||||
|
|
||||||
import { createTree, findOneTreeById, updateTree } from './api';
|
import { createTree, findOneTreeById, updateTree } from './api';
|
||||||
import { createGraphTaskElement, hasElements, hasRootElementNode, resolveNodeGraph } from '../builder/utils';
|
|
||||||
import { createGraphTaskElementFromTemplate } from '../utils/node';
|
|
||||||
import TressCard from './trees-card.vue';
|
import TressCard from './trees-card.vue';
|
||||||
import NodesCard from './nodes-card.vue';
|
import NodesCard from './nodes-card.vue';
|
||||||
|
|
||||||
@@ -110,7 +95,7 @@ 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 currentNodeGraph = ref<NodeGraph | 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);
|
||||||
@@ -219,9 +204,9 @@ export default defineComponent({
|
|||||||
console.info('handleSelectTree', tree);
|
console.info('handleSelectTree', tree);
|
||||||
findOneTreeById(tree.id).then(r => {
|
findOneTreeById(tree.id).then(r => {
|
||||||
if (r.data) {
|
if (r.data) {
|
||||||
let nodeGraph: NodeGraph | null = null;
|
let nodeGraph: GraphContainer | null = null;
|
||||||
try {
|
try {
|
||||||
nodeGraph = JSON.parse(r.data?.xmlContent as unknown as string) as unknown as NodeGraph;
|
nodeGraph = JSON.parse(r.data?.xmlContent as unknown as string) as unknown as GraphContainer;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error('parse error,cause:', e);
|
console.error('parse error,cause:', e);
|
||||||
}
|
}
|
||||||
@@ -290,7 +275,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
updatedAt: null,
|
updatedAt: null,
|
||||||
};
|
};
|
||||||
currentNodeGraph.value = {
|
currentGraph.value = {
|
||||||
edges: [],
|
edges: [],
|
||||||
nodes: [],
|
nodes: [],
|
||||||
};
|
};
|
||||||
@@ -370,7 +355,7 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
const graphData: NodeGraph = resolveNodeGraph(graph.value as Graph);
|
const graphData: GraphContainer = resolveGraph(graph.value as Graph);
|
||||||
console.info('handleSave', graphData);
|
console.info('handleSave', graphData);
|
||||||
if (!currentBehaviorTree.value) {
|
if (!currentBehaviorTree.value) {
|
||||||
message.error('当前决策树不存在');
|
message.error('当前决策树不存在');
|
||||||
@@ -429,7 +414,7 @@ export default defineComponent({
|
|||||||
handleCreateTree,
|
handleCreateTree,
|
||||||
currentTreeEditing,
|
currentTreeEditing,
|
||||||
currentBehaviorTree,
|
currentBehaviorTree,
|
||||||
currentNodeGraph,
|
currentGraph,
|
||||||
selectedNodeTaskElement,
|
selectedNodeTaskElement,
|
||||||
selectedModelNode,
|
selectedModelNode,
|
||||||
graph,
|
graph,
|
||||||
|
|||||||
@@ -48,8 +48,8 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, onMounted, onUnmounted, ref } from 'vue';
|
import { defineComponent, onMounted, onUnmounted, ref } from 'vue';
|
||||||
import { elementProps } from './props';
|
import { elementProps, type ModelElement } from '../graph';
|
||||||
import type { ModelElement } from './element';
|
|
||||||
import { DeleteOutlined, SettingOutlined } from '@ant-design/icons-vue';
|
import { DeleteOutlined, SettingOutlined } from '@ant-design/icons-vue';
|
||||||
import type { Graph } from '@antv/x6';
|
import type { Graph } from '@antv/x6';
|
||||||
import { substring } from '@/utils/strings';
|
import { substring } from '@/utils/strings';
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, onMounted, ref } from 'vue';
|
import { defineComponent, onMounted, ref } from 'vue';
|
||||||
import type { NodeDragTemplate, NodeTemplate } from '../types';
|
import type { NodeDragTemplate, NodeTemplate } from './template';
|
||||||
import { findNodeTemplates } from './api';
|
import { findNodeTemplates } from './api';
|
||||||
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
||||||
|
|
||||||
|
|||||||
@@ -147,8 +147,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, onMounted, type PropType, ref, watch } from 'vue';
|
import { defineComponent, onMounted, type PropType, ref, watch } from 'vue';
|
||||||
import { CheckOutlined } from '@ant-design/icons-vue';
|
import { CheckOutlined } from '@ant-design/icons-vue';
|
||||||
import type { ElementVariable, GraphTaskElement } from '../builder/element';
|
import type { ElementVariable, GraphTaskElement } from '../graph';
|
||||||
import type { BehaviorTree } from '../types';
|
import type { BehaviorTree } from './tree';
|
||||||
import type { Graph, Node, NodeProperties } from '@antv/x6';
|
import type { Graph, Node, NodeProperties } from '@antv/x6';
|
||||||
import { generateKey } from '@/utils/strings';
|
import { generateKey } from '@/utils/strings';
|
||||||
|
|
||||||
|
|||||||
41
modeler/src/views/decision/designer/register.ts
Normal file
41
modeler/src/views/decision/designer/register.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the kernelstudio package.
|
||||||
|
*
|
||||||
|
* (c) 2014-2025 zlin <admin@kernelstudio.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE file
|
||||||
|
* that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { register } from '@antv/x6-vue-shape';
|
||||||
|
import ModelElement from './node.vue';
|
||||||
|
|
||||||
|
export const registerNodeElement = () => {
|
||||||
|
console.info('registerNodeElement');
|
||||||
|
register({
|
||||||
|
shape: 'task',
|
||||||
|
component: ModelElement,
|
||||||
|
width: 120,
|
||||||
|
attrs: {
|
||||||
|
body: {
|
||||||
|
stroke: 'transparent',
|
||||||
|
strokeWidth: 0,
|
||||||
|
fill: 'transparent',
|
||||||
|
rx: 4,
|
||||||
|
ry: 4,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dragging: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
// 配置端口识别规则,
|
||||||
|
portMarkup: [
|
||||||
|
{
|
||||||
|
tagName: 'div',
|
||||||
|
selector: 'port-body',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// 告诉 X6 如何识别 Vue 组件内的端口
|
||||||
|
portAttribute: 'data-port',
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { ApiDataResponse, NullableString } from '@/types';
|
import type { ApiDataResponse, NullableString } from '@/types';
|
||||||
import type { ElementParameter } from '../builder/element';
|
import type { ElementParameter } from '../graph';
|
||||||
|
|
||||||
export interface NodeTemplate {
|
export interface NodeTemplate {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { ApiDataResponse, NullableString, PageableResponse } from '@/types';
|
import type { ApiDataResponse, NullableString, PageableResponse } from '@/types';
|
||||||
import type { NodeGraph } from '../builder/element';
|
import type { GraphContainer } from '../graph';
|
||||||
|
|
||||||
export interface BehaviorTree {
|
export interface BehaviorTree {
|
||||||
id: number,
|
id: number,
|
||||||
@@ -18,7 +18,7 @@ export interface BehaviorTree {
|
|||||||
updatedAt: NullableString,
|
updatedAt: NullableString,
|
||||||
englishName: NullableString,
|
englishName: NullableString,
|
||||||
xmlContent: NullableString,
|
xmlContent: NullableString,
|
||||||
graph: NodeGraph
|
graph: GraphContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BehaviorTreeRequest extends BehaviorTree {
|
export interface BehaviorTreeRequest extends BehaviorTree {
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, onMounted, ref } from 'vue';
|
import { defineComponent, onMounted, ref } from 'vue';
|
||||||
import { CheckOutlined, DeleteOutlined, EditFilled, PlusOutlined } from '@ant-design/icons-vue';
|
import { CheckOutlined, DeleteOutlined, EditFilled, PlusOutlined } from '@ant-design/icons-vue';
|
||||||
import type { BehaviorTree, BehaviorTreeRequest } from '../types';
|
import type { BehaviorTree, BehaviorTreeRequest } from './tree';
|
||||||
import { deleteOneTreeById, findTreesByQuery } from './api';
|
import { deleteOneTreeById, findTreesByQuery } from './api';
|
||||||
import { substring } from '@/utils/strings';
|
import { substring } from '@/utils/strings';
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
* that was distributed with this source code.
|
* that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { NodeDragTemplate } from '../types';
|
import type { NodeDragTemplate } from './template';
|
||||||
import type { GraphTaskElement, GraphTaskRect } from '../builder/element';
|
import type { GraphRect, GraphTaskElement } from '../graph';
|
||||||
import { generateKey } from '@/utils/strings';
|
import { generateKey } from '@/utils/strings';
|
||||||
|
|
||||||
export const createGraphTaskElementFromTemplate = (
|
export const createGraphTaskElementFromTemplate = (
|
||||||
template: NodeDragTemplate,
|
template: NodeDragTemplate,
|
||||||
rect?: GraphTaskRect,
|
rect?: GraphRect,
|
||||||
): GraphTaskElement => {
|
): GraphTaskElement => {
|
||||||
let realRect = { width: 120, height: 80, x: 0, y: 0, ...rect || {} };
|
let realRect = { width: 120, height: 80, x: 0, y: 0, ...rect || {} };
|
||||||
console.info('rect', rect);
|
console.info('rect', rect);
|
||||||
@@ -8,9 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Edge, Graph, Path, Selection } from '@antv/x6';
|
import { Edge, Graph, Path, Selection } from '@antv/x6';
|
||||||
import type { ModelElement } from './element';
|
import { createLineOptions, type ModelElement } from '../graph';
|
||||||
import type { Connecting } from '@antv/x6/lib/graph/options';
|
import type { Connecting } from '@antv/x6/lib/graph/options';
|
||||||
import { createLineOptions } from './line';
|
|
||||||
|
|
||||||
Graph.registerConnector(
|
Graph.registerConnector(
|
||||||
'sequenceFlowConnector',
|
'sequenceFlowConnector',
|
||||||
@@ -7,22 +7,57 @@
|
|||||||
* that was distributed with this source code.
|
* that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import type { NullableString } from '@/types';
|
import type { NullableString } from '@/types';
|
||||||
|
|
||||||
export interface DraggableElement {
|
export interface GraphComponentElement {
|
||||||
|
id: number,
|
||||||
|
name: NullableString,
|
||||||
|
type: NullableString,
|
||||||
|
description: NullableString,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GraphPosition {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GraphRect {
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
x?: number;
|
||||||
|
y?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GraphDraggableElement {
|
||||||
id: number | null,
|
id: number | null,
|
||||||
key?: NullableString,
|
key?: NullableString,
|
||||||
name: NullableString,
|
name: NullableString,
|
||||||
description: NullableString,
|
description: NullableString,
|
||||||
category: NullableString,
|
category: NullableString,
|
||||||
draggable: boolean,
|
draggable: boolean,
|
||||||
parent?: DraggableElement,
|
parent?: GraphDraggableElement,
|
||||||
children: DraggableElement[]
|
children: GraphDraggableElement[]
|
||||||
|
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GraphBaseElement {
|
||||||
|
id: number;
|
||||||
|
key: NullableString;
|
||||||
|
name: NullableString;
|
||||||
|
description: NullableString;
|
||||||
|
type: NullableString;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
position: GraphPosition;
|
||||||
|
category: NullableString;
|
||||||
|
element?: GraphDraggableElement;
|
||||||
|
components?: GraphComponentElement[]
|
||||||
|
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ElementStatus = 'default' | 'success' | 'failed' | 'running' | string | null
|
|
||||||
|
|
||||||
export interface ElementParameter {
|
export interface ElementParameter {
|
||||||
id: number,
|
id: number,
|
||||||
@@ -34,10 +69,6 @@ export interface ElementParameter {
|
|||||||
templateType: NullableString,
|
templateType: NullableString,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GraphPosition {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ElementVariable {
|
export interface ElementVariable {
|
||||||
key: NullableString;
|
key: NullableString;
|
||||||
@@ -47,29 +78,7 @@ export interface ElementVariable {
|
|||||||
unit: NullableString;
|
unit: NullableString;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GraphTaskRect {
|
export interface GraphTaskElement extends GraphBaseElement {
|
||||||
width?: number;
|
|
||||||
height?: number;
|
|
||||||
x?: number;
|
|
||||||
y?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BaseElement {
|
|
||||||
id: number;
|
|
||||||
key: NullableString;
|
|
||||||
name: NullableString;
|
|
||||||
description: NullableString;
|
|
||||||
type: NullableString;
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
position: GraphPosition;
|
|
||||||
category: NullableString;
|
|
||||||
element?: DraggableElement;
|
|
||||||
|
|
||||||
[key: string]: unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GraphTaskElement extends BaseElement {
|
|
||||||
template: number;
|
template: number;
|
||||||
templateType: NullableString,
|
templateType: NullableString,
|
||||||
inputs: any;
|
inputs: any;
|
||||||
@@ -82,7 +91,7 @@ export interface GraphTaskElement extends BaseElement {
|
|||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ModelElement extends BaseElement {
|
export interface ModelElement extends GraphBaseElement {
|
||||||
edges: GraphEdgeElement[];
|
edges: GraphEdgeElement[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +107,7 @@ export interface GraphEdgeElement {
|
|||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NodeGraph {
|
export interface GraphContainer {
|
||||||
edges: GraphEdgeElement[];
|
edges: GraphEdgeElement[];
|
||||||
nodes: GraphTaskElement[];
|
nodes: GraphTaskElement[];
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
import { computed, type ComputedRef, ref, type Ref } from 'vue';
|
import { computed, type ComputedRef, ref, type Ref } from 'vue';
|
||||||
import { type Dom, Graph, Node } from '@antv/x6';
|
import { type Dom, Graph, Node } from '@antv/x6';
|
||||||
import type { NodeViewPositionEventArgs } from '@antv/x6/es/view/node/type';
|
import type { NodeViewPositionEventArgs } from '@antv/x6/es/view/node/type';
|
||||||
import { createGraphCanvas } from './graph';
|
import { createGraphCanvas } from './canvas';
|
||||||
import { EventListener } from '@/utils/event';
|
import { EventListener } from '@/utils/event';
|
||||||
import type { ModelElement } from './element';
|
import type { ModelElement } from './element';
|
||||||
|
|
||||||
@@ -7,5 +7,10 @@
|
|||||||
* that was distributed with this source code.
|
* that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './tree';
|
export * from './line'
|
||||||
export * from './template';
|
export * from './ports'
|
||||||
|
export * from './element'
|
||||||
|
export * from './canvas'
|
||||||
|
export * from './hooks'
|
||||||
|
export * from './props'
|
||||||
|
export * from './utils'
|
||||||
@@ -6,14 +6,14 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE file
|
* For the full copyright and license information, please view the LICENSE file
|
||||||
* that was distributed with this source code.
|
* that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
import type { GraphEdgeElement, GraphTaskElement, NodeGraph } from './element';
|
import type { GraphContainer, GraphEdgeElement, GraphTaskElement } from '../graph';
|
||||||
import { Edge, Graph, Node } from '@antv/x6';
|
import { Edge, Graph, Node } from '@antv/x6';
|
||||||
|
|
||||||
export const defaultHeight: Record<string, number> = {
|
export const defaultHeight: Record<string, number> = {
|
||||||
component: 110,
|
component: 110,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createGraphTaskElement = (element: GraphTaskElement, width: number = 250, height: number = 120): any => {
|
export const createGraphTaskElement = (element: GraphTaskElement, width: number = 250, height: number = 120, shape: string = 'task'): any => {
|
||||||
let realHeight = defaultHeight[element.category as string];
|
let realHeight = defaultHeight[element.category as string];
|
||||||
if (!realHeight) {
|
if (!realHeight) {
|
||||||
realHeight = 120;
|
realHeight = 120;
|
||||||
@@ -22,7 +22,7 @@ export const createGraphTaskElement = (element: GraphTaskElement, width: number
|
|||||||
realHeight = 60;
|
realHeight = 60;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
shape: 'task',
|
shape: shape ?? 'task',
|
||||||
id: element.key,
|
id: element.key,
|
||||||
position: {
|
position: {
|
||||||
x: element.position?.x || 0,
|
x: element.position?.x || 0,
|
||||||
@@ -86,7 +86,7 @@ export const resolveGraphEdgeElements = (graph: Graph): GraphEdgeElement[] => {
|
|||||||
return edgeElements;
|
return edgeElements;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const resolveNodeGraph = (graph: Graph): NodeGraph => {
|
export const resolveGraph = (graph: Graph): GraphContainer => {
|
||||||
const nodes: GraphTaskElement[] = resolveGraphTaskElements(graph);
|
const nodes: GraphTaskElement[] = resolveGraphTaskElements(graph);
|
||||||
const edges: GraphEdgeElement[] = resolveGraphEdgeElements(graph);
|
const edges: GraphEdgeElement[] = resolveGraphEdgeElements(graph);
|
||||||
return {
|
return {
|
||||||
Reference in New Issue
Block a user