Initial commit
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { NullableString } from '@/types';
|
import type { NullableString } from '@/types';
|
||||||
import type { NodeSetting } from '@/views/decision/types';
|
|
||||||
|
|
||||||
export interface DraggableElement {
|
export interface DraggableElement {
|
||||||
id: number | null,
|
id: number | null,
|
||||||
@@ -24,6 +23,16 @@ export interface DraggableElement {
|
|||||||
|
|
||||||
export type ElementStatus = 'default' | 'success' | 'failed' | 'running' | string | null
|
export type ElementStatus = 'default' | 'success' | 'failed' | 'running' | string | null
|
||||||
|
|
||||||
|
export interface ElementParameter {
|
||||||
|
id: number,
|
||||||
|
templateId: number,
|
||||||
|
paramKey: NullableString,
|
||||||
|
dataType: NullableString,
|
||||||
|
defaultValue: NullableString,
|
||||||
|
description: NullableString,
|
||||||
|
templateType: NullableString,
|
||||||
|
}
|
||||||
|
|
||||||
export interface ElementPosition {
|
export interface ElementPosition {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
@@ -38,6 +47,7 @@ export interface ElementVariable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface BaseElement {
|
export interface BaseElement {
|
||||||
|
id: number;
|
||||||
key: string;
|
key: string;
|
||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
@@ -56,38 +66,35 @@ export interface TaskNodeRect {
|
|||||||
y?: number;
|
y?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TaskNodeElement extends BaseElement {
|
export interface GraphTaskElement extends BaseElement {
|
||||||
template: number;
|
template: number;
|
||||||
inputs: any;
|
inputs: any;
|
||||||
outputs: any;
|
outputs: any;
|
||||||
variables: ElementVariable[];
|
variables: ElementVariable[];
|
||||||
parameters: Record<any, any>;
|
parameters: ElementParameter[];
|
||||||
|
|
||||||
children?: TaskNodeElement[],
|
children?: GraphTaskElement[],
|
||||||
|
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SettingTaskNodeElement extends TaskNodeElement {
|
|
||||||
settings: NodeSetting[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ModelElement extends BaseElement {
|
export interface ModelElement extends BaseElement {
|
||||||
edges: EdgeNodeElement[];
|
edges: GraphEdgeElement[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EdgeNodeElement {
|
export interface GraphEdgeElement {
|
||||||
|
id: number;
|
||||||
key: NullableString;
|
key: NullableString;
|
||||||
source: NullableString;
|
source: NullableString;
|
||||||
sourceName: NullableString;
|
|
||||||
target: NullableString;
|
target: NullableString;
|
||||||
targetName: NullableString;
|
|
||||||
attrs: Record<any, any>;
|
attrs: Record<any, any>;
|
||||||
router: Record<any, any>;
|
router: Record<any, any>;
|
||||||
connector: any;
|
connector: any;
|
||||||
|
|
||||||
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NodeGraph {
|
export interface NodeGraph {
|
||||||
edges: EdgeNodeElement[];
|
edges: GraphEdgeElement[];
|
||||||
nodes: TaskNodeElement[];
|
nodes: GraphTaskElement[];
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ import ModelElement from './node.vue';
|
|||||||
export const registerNodeElement = () => {
|
export const registerNodeElement = () => {
|
||||||
console.info('registerNodeElement');
|
console.info('registerNodeElement');
|
||||||
register({
|
register({
|
||||||
shape: 'node',
|
shape: 'task',
|
||||||
component: ModelElement,
|
component: ModelElement,
|
||||||
width: 120,
|
width: 120,
|
||||||
attrs: {
|
attrs: {
|
||||||
|
|||||||
@@ -6,20 +6,20 @@
|
|||||||
* 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 { EdgeNodeElement, NodeGraph, TaskNodeElement } from './element';
|
import type { GraphEdgeElement, GraphTaskElement, NodeGraph } from './element';
|
||||||
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 createModelNode = (element: TaskNodeElement, width: number = 250, height: number = 120): any => {
|
export const createGraphTaskElement = (element: GraphTaskElement, width: number = 250, height: number = 120): any => {
|
||||||
let realHeight = defaultHeight[element.category as string];
|
let realHeight = defaultHeight[element.category as string];
|
||||||
if (!realHeight) {
|
if (!realHeight) {
|
||||||
realHeight = 120;
|
realHeight = 120;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
shape: 'node',
|
shape: 'task',
|
||||||
id: element.key,
|
id: element.key,
|
||||||
position: {
|
position: {
|
||||||
x: element.position?.x || 0,
|
x: element.position?.x || 0,
|
||||||
@@ -38,13 +38,13 @@ export const createModelNode = (element: TaskNodeElement, width: number = 250, h
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const resolveNodeTaskElements = (graph: Graph): TaskNodeElement[] => {
|
export const resolveGraphTaskElements = (graph: Graph): GraphTaskElement[] => {
|
||||||
const taskElements: TaskNodeElement[] = [];
|
const taskElements: GraphTaskElement[] = [];
|
||||||
if (graph) {
|
if (graph) {
|
||||||
const nodes = graph?.getNodes() as Node[];
|
const nodes = graph?.getNodes() as Node[];
|
||||||
if (nodes) {
|
if (nodes) {
|
||||||
nodes.forEach(node => {
|
nodes.forEach(node => {
|
||||||
const nodeData = node.getData() as TaskNodeElement;
|
const nodeData = node.getData() as GraphTaskElement;
|
||||||
const newElement = {
|
const newElement = {
|
||||||
...nodeData,
|
...nodeData,
|
||||||
key: node.id,
|
key: node.id,
|
||||||
@@ -59,13 +59,13 @@ export const resolveNodeTaskElements = (graph: Graph): TaskNodeElement[] => {
|
|||||||
return taskElements;
|
return taskElements;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const resolveNodeEdgeElements = (graph: Graph): EdgeNodeElement[] => {
|
export const resolveGraphEdgeElements = (graph: Graph): GraphEdgeElement[] => {
|
||||||
const edgeElements: EdgeNodeElement[] = [];
|
const edgeElements: GraphEdgeElement[] = [];
|
||||||
if (graph) {
|
if (graph) {
|
||||||
const graphEdges = graph?.getEdges() ?? [] as Edge[];
|
const graphEdges = graph?.getEdges() ?? [] as Edge[];
|
||||||
if (graphEdges) {
|
if (graphEdges) {
|
||||||
graphEdges.forEach(edge => {
|
graphEdges.forEach(edge => {
|
||||||
const nodeData = edge.getData() as TaskNodeElement;
|
const nodeData = edge.getData() as GraphTaskElement;
|
||||||
edgeElements.push({
|
edgeElements.push({
|
||||||
id: nodeData?.id ?? 0,
|
id: nodeData?.id ?? 0,
|
||||||
key: edge.id,
|
key: edge.id,
|
||||||
@@ -84,8 +84,8 @@ export const resolveNodeEdgeElements = (graph: Graph): EdgeNodeElement[] => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const resolveNodeGraph = (graph: Graph): NodeGraph => {
|
export const resolveNodeGraph = (graph: Graph): NodeGraph => {
|
||||||
const nodes: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
const nodes: GraphTaskElement[] = resolveGraphTaskElements(graph);
|
||||||
const edges: EdgeNodeElement[] = resolveNodeEdgeElements(graph);
|
const edges: GraphEdgeElement[] = resolveGraphEdgeElements(graph);
|
||||||
return {
|
return {
|
||||||
nodes,
|
nodes,
|
||||||
edges,
|
edges,
|
||||||
@@ -94,7 +94,7 @@ export const resolveNodeGraph = (graph: Graph): NodeGraph => {
|
|||||||
|
|
||||||
export const hasElements = (graph: Graph): boolean => {
|
export const hasElements = (graph: Graph): boolean => {
|
||||||
if (graph) {
|
if (graph) {
|
||||||
const taskElements: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
const taskElements: GraphTaskElement[] = resolveGraphTaskElements(graph);
|
||||||
return taskElements.length > 0;
|
return taskElements.length > 0;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -102,7 +102,7 @@ export const hasElements = (graph: Graph): boolean => {
|
|||||||
|
|
||||||
export const hasRootElementNode = (graph: Graph): boolean => {
|
export const hasRootElementNode = (graph: Graph): boolean => {
|
||||||
if (graph) {
|
if (graph) {
|
||||||
const taskElements: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
const taskElements: GraphTaskElement[] = resolveGraphTaskElements(graph);
|
||||||
return taskElements.filter(e => e.type === 'root').length === 1;
|
return taskElements.filter(e => e.type === 'root').length === 1;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -69,10 +69,10 @@ import Properties from './properties.vue';
|
|||||||
import { useGraphCanvas } from './builder/hooks';
|
import { useGraphCanvas } from './builder/hooks';
|
||||||
import { registerNodeElement } from './builder/register';
|
import { registerNodeElement } from './builder/register';
|
||||||
import type { BehaviorTree, NodeTemplate } from './types';
|
import type { BehaviorTree, NodeTemplate } from './types';
|
||||||
import type { NodeGraph, SettingTaskNodeElement, TaskNodeElement } from './builder/element';
|
import type { GraphTaskElement, NodeGraph } from './builder/element';
|
||||||
import { createTree, findOneTreeById, updateTree } from './api';
|
import { createTree, findOneTreeById, updateTree } from './api';
|
||||||
import { createModelNode, hasElements, hasRootElementNode, resolveNodeGraph } from './builder/utils';
|
import { createGraphTaskElement, hasElements, hasRootElementNode, resolveNodeGraph } from './builder/utils';
|
||||||
import { createTaskNodeElementFromTemplate } from './utils/node';
|
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';
|
||||||
import { createLineOptions } from '@/views/decision/builder/line.ts';
|
import { createLineOptions } from '@/views/decision/builder/line.ts';
|
||||||
@@ -103,7 +103,7 @@ export default defineComponent({
|
|||||||
const currentBehaviorTree = ref<BehaviorTree | null>(null);
|
const currentBehaviorTree = ref<BehaviorTree | null>(null);
|
||||||
const currentNodeGraph = ref<NodeGraph | null>(null);
|
const currentNodeGraph = ref<NodeGraph | null>(null);
|
||||||
const selectedModelNode = ref<Node<NodeProperties> | null>(null);
|
const selectedModelNode = ref<Node<NodeProperties> | null>(null);
|
||||||
const selectedNodeTaskElement = ref<SettingTaskNodeElement | null>(null);
|
const selectedNodeTaskElement = ref<GraphTaskElement | null>(null);
|
||||||
const changed = ref<boolean>(false)
|
const changed = ref<boolean>(false)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -188,9 +188,9 @@ export default defineComponent({
|
|||||||
console.log('放置节点:', { ...template, x, y });
|
console.log('放置节点:', { ...template, x, y });
|
||||||
|
|
||||||
// 创建节点数据
|
// 创建节点数据
|
||||||
const settingTaskElement: SettingTaskNodeElement = createTaskNodeElementFromTemplate(template, { x, y });
|
const settingTaskElement: GraphTaskElement = createGraphTaskElementFromTemplate(template, { x, y });
|
||||||
// 创建节点
|
// 创建节点
|
||||||
const settingTaskNode = createModelNode(settingTaskElement);
|
const settingTaskNode = createGraphTaskElement(settingTaskElement);
|
||||||
console.info('create settingTaskNode: ', settingTaskElement, settingTaskNode);
|
console.info('create settingTaskNode: ', settingTaskElement, settingTaskNode);
|
||||||
|
|
||||||
// 将节点添加到画布
|
// 将节点添加到画布
|
||||||
@@ -237,7 +237,7 @@ export default defineComponent({
|
|||||||
if (currentBehaviorTree.value?.graph && graph.value) {
|
if (currentBehaviorTree.value?.graph && graph.value) {
|
||||||
if (currentBehaviorTree.value?.graph.nodes) {
|
if (currentBehaviorTree.value?.graph.nodes) {
|
||||||
currentBehaviorTree.value?.graph.nodes.forEach(ele => {
|
currentBehaviorTree.value?.graph.nodes.forEach(ele => {
|
||||||
const node = createModelNode(ele as TaskNodeElement);
|
const node = createGraphTaskElement(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);
|
||||||
@@ -277,10 +277,10 @@ export default defineComponent({
|
|||||||
|
|
||||||
handleGraphEvent('node:click', (args: any) => {
|
handleGraphEvent('node:click', (args: any) => {
|
||||||
const node = args.node as Node<NodeProperties>;
|
const node = args.node as Node<NodeProperties>;
|
||||||
const newElement = node.getData() as SettingTaskNodeElement;
|
const newElement = node.getData() as GraphTaskElement;
|
||||||
|
|
||||||
selectedModelNode.value = node;
|
selectedModelNode.value = node;
|
||||||
selectedNodeTaskElement.value = JSON.parse(JSON.stringify(newElement || {})) as SettingTaskNodeElement;
|
selectedNodeTaskElement.value = JSON.parse(JSON.stringify(newElement || {})) as GraphTaskElement;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听节点鼠标事件,显示/隐藏连接点
|
// 监听节点鼠标事件,显示/隐藏连接点
|
||||||
@@ -310,7 +310,7 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpdateElement = (element: SettingTaskNodeElement) => {
|
const handleUpdateElement = (element: GraphTaskElement) => {
|
||||||
// 更新选中的节点数据
|
// 更新选中的节点数据
|
||||||
if (selectedModelNode.value) {
|
if (selectedModelNode.value) {
|
||||||
selectedModelNode.value.replaceData(element);
|
selectedModelNode.value.replaceData(element);
|
||||||
|
|||||||
@@ -111,9 +111,9 @@
|
|||||||
<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, SettingTaskNodeElement } from './builder/element';
|
import type { ElementVariable, GraphTaskElement } from './builder/element';
|
||||||
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';
|
||||||
|
|
||||||
const actionSpaceColumns = [
|
const actionSpaceColumns = [
|
||||||
{ title: '序号', dataIndex: 'index', key: 'index', width: 40 },
|
{ title: '序号', dataIndex: 'index', key: 'index', width: 40 },
|
||||||
@@ -136,7 +136,7 @@ export default defineComponent({
|
|||||||
const activeBottomTabs2Key = ref<string>('1');
|
const activeBottomTabs2Key = ref<string>('1');
|
||||||
|
|
||||||
const currentNode = ref<Node | null>(props.node ?? null);
|
const currentNode = ref<Node | null>(props.node ?? null);
|
||||||
const currentElement = ref<SettingTaskNodeElement | null>(null);
|
const currentElement = ref<GraphTaskElement | null>(null);
|
||||||
|
|
||||||
const load = () => {
|
const load = () => {
|
||||||
};
|
};
|
||||||
@@ -145,7 +145,7 @@ export default defineComponent({
|
|||||||
currentNode.value = n ?? null;
|
currentNode.value = n ?? null;
|
||||||
if (n) {
|
if (n) {
|
||||||
const data = n.getData();
|
const data = n.getData();
|
||||||
currentElement.value = JSON.parse(JSON.stringify(data || {})) as SettingTaskNodeElement;
|
currentElement.value = JSON.parse(JSON.stringify(data || {})) as GraphTaskElement;
|
||||||
} else {
|
} else {
|
||||||
currentElement.value = null;
|
currentElement.value = null;
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ export default defineComponent({
|
|||||||
const updateNode = () => {
|
const updateNode = () => {
|
||||||
if (currentNode.value && currentElement.value) {
|
if (currentNode.value && currentElement.value) {
|
||||||
// 深拷贝当前元素数据
|
// 深拷贝当前元素数据
|
||||||
const newElement = JSON.parse(JSON.stringify(currentElement.value)) as SettingTaskNodeElement;
|
const newElement = JSON.parse(JSON.stringify(currentElement.value)) as GraphTaskElement;
|
||||||
// 更新节点数据
|
// 更新节点数据
|
||||||
currentNode.value.replaceData(newElement);
|
currentNode.value.replaceData(newElement);
|
||||||
// 触发事件通知父组件
|
// 触发事件通知父组件
|
||||||
|
|||||||
@@ -8,16 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { ApiDataResponse, NullableString } from '@/types';
|
import type { ApiDataResponse, NullableString } from '@/types';
|
||||||
|
import type { ElementParameter } from '../builder/element';
|
||||||
export interface NodeTemplateParameter {
|
|
||||||
id: number,
|
|
||||||
templateId: number,
|
|
||||||
paramKey: NullableString,
|
|
||||||
dataType: NullableString,
|
|
||||||
defaultValue: NullableString,
|
|
||||||
description: NullableString,
|
|
||||||
templateType: NullableString,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NodeTemplate {
|
export interface NodeTemplate {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -27,7 +18,7 @@ export interface NodeTemplate {
|
|||||||
description: NullableString;
|
description: NullableString;
|
||||||
templeteType: NullableString;
|
templeteType: NullableString;
|
||||||
englishName: NullableString;
|
englishName: NullableString;
|
||||||
parameters: NodeTemplateParameter[],
|
parameters: ElementParameter[],
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NodeTemplatesResponse extends ApiDataResponse<NodeTemplate[]> {
|
export interface NodeTemplatesResponse extends ApiDataResponse<NodeTemplate[]> {
|
||||||
|
|||||||
@@ -8,13 +8,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { NodeTemplate } from '../types';
|
import type { NodeTemplate } from '../types';
|
||||||
import type { SettingTaskNodeElement, TaskNodeRect } from '../builder/element';
|
import type { GraphTaskElement, TaskNodeRect } from '../builder/element';
|
||||||
import { generateKey } from '@/utils/strings';
|
import { generateKey } from '@/utils/strings';
|
||||||
|
|
||||||
export const createTaskNodeElementFromTemplate = (
|
export const createGraphTaskElementFromTemplate = (
|
||||||
template: NodeTemplate,
|
template: NodeTemplate,
|
||||||
rect?: TaskNodeRect,
|
rect?: TaskNodeRect,
|
||||||
): SettingTaskNodeElement => {
|
): GraphTaskElement => {
|
||||||
let realRect = { width: 200, height: 100, x: 0, y: 0, ...rect || {} }
|
let realRect = { width: 200, height: 100, x: 0, y: 0, ...rect || {} }
|
||||||
console.info('rect',rect)
|
console.info('rect',rect)
|
||||||
return {
|
return {
|
||||||
@@ -51,5 +51,5 @@ export const createTaskNodeElementFromTemplate = (
|
|||||||
unit: '个'
|
unit: '个'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
} as SettingTaskNodeElement;
|
} as GraphTaskElement;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user