Initial commit
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
import type { NullableString } from '@/types';
|
||||
import type { NodeSetting } from '@/views/decision/types';
|
||||
|
||||
export interface DraggableElement {
|
||||
id: number | null,
|
||||
@@ -24,6 +23,16 @@ export interface DraggableElement {
|
||||
|
||||
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 {
|
||||
x: number;
|
||||
y: number;
|
||||
@@ -38,6 +47,7 @@ export interface ElementVariable {
|
||||
}
|
||||
|
||||
export interface BaseElement {
|
||||
id: number;
|
||||
key: string;
|
||||
name: string;
|
||||
type: string;
|
||||
@@ -56,38 +66,35 @@ export interface TaskNodeRect {
|
||||
y?: number;
|
||||
}
|
||||
|
||||
export interface TaskNodeElement extends BaseElement {
|
||||
export interface GraphTaskElement extends BaseElement {
|
||||
template: number;
|
||||
inputs: any;
|
||||
outputs: any;
|
||||
variables: ElementVariable[];
|
||||
parameters: Record<any, any>;
|
||||
parameters: ElementParameter[];
|
||||
|
||||
children?: TaskNodeElement[],
|
||||
children?: GraphTaskElement[],
|
||||
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface SettingTaskNodeElement extends TaskNodeElement {
|
||||
settings: NodeSetting[];
|
||||
}
|
||||
|
||||
export interface ModelElement extends BaseElement {
|
||||
edges: EdgeNodeElement[];
|
||||
edges: GraphEdgeElement[];
|
||||
}
|
||||
|
||||
export interface EdgeNodeElement {
|
||||
export interface GraphEdgeElement {
|
||||
id: number;
|
||||
key: NullableString;
|
||||
source: NullableString;
|
||||
sourceName: NullableString;
|
||||
target: NullableString;
|
||||
targetName: NullableString;
|
||||
attrs: Record<any, any>;
|
||||
router: Record<any, any>;
|
||||
connector: any;
|
||||
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface NodeGraph {
|
||||
edges: EdgeNodeElement[];
|
||||
nodes: TaskNodeElement[];
|
||||
edges: GraphEdgeElement[];
|
||||
nodes: GraphTaskElement[];
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import ModelElement from './node.vue';
|
||||
export const registerNodeElement = () => {
|
||||
console.info('registerNodeElement');
|
||||
register({
|
||||
shape: 'node',
|
||||
shape: 'task',
|
||||
component: ModelElement,
|
||||
width: 120,
|
||||
attrs: {
|
||||
|
||||
@@ -6,20 +6,20 @@
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* 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';
|
||||
|
||||
export const defaultHeight: Record<string, number> = {
|
||||
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];
|
||||
if (!realHeight) {
|
||||
realHeight = 120;
|
||||
}
|
||||
return {
|
||||
shape: 'node',
|
||||
shape: 'task',
|
||||
id: element.key,
|
||||
position: {
|
||||
x: element.position?.x || 0,
|
||||
@@ -38,13 +38,13 @@ export const createModelNode = (element: TaskNodeElement, width: number = 250, h
|
||||
};
|
||||
};
|
||||
|
||||
export const resolveNodeTaskElements = (graph: Graph): TaskNodeElement[] => {
|
||||
const taskElements: TaskNodeElement[] = [];
|
||||
export const resolveGraphTaskElements = (graph: Graph): GraphTaskElement[] => {
|
||||
const taskElements: GraphTaskElement[] = [];
|
||||
if (graph) {
|
||||
const nodes = graph?.getNodes() as Node[];
|
||||
if (nodes) {
|
||||
nodes.forEach(node => {
|
||||
const nodeData = node.getData() as TaskNodeElement;
|
||||
const nodeData = node.getData() as GraphTaskElement;
|
||||
const newElement = {
|
||||
...nodeData,
|
||||
key: node.id,
|
||||
@@ -59,13 +59,13 @@ export const resolveNodeTaskElements = (graph: Graph): TaskNodeElement[] => {
|
||||
return taskElements;
|
||||
};
|
||||
|
||||
export const resolveNodeEdgeElements = (graph: Graph): EdgeNodeElement[] => {
|
||||
const edgeElements: EdgeNodeElement[] = [];
|
||||
export const resolveGraphEdgeElements = (graph: Graph): GraphEdgeElement[] => {
|
||||
const edgeElements: GraphEdgeElement[] = [];
|
||||
if (graph) {
|
||||
const graphEdges = graph?.getEdges() ?? [] as Edge[];
|
||||
if (graphEdges) {
|
||||
graphEdges.forEach(edge => {
|
||||
const nodeData = edge.getData() as TaskNodeElement;
|
||||
const nodeData = edge.getData() as GraphTaskElement;
|
||||
edgeElements.push({
|
||||
id: nodeData?.id ?? 0,
|
||||
key: edge.id,
|
||||
@@ -84,8 +84,8 @@ export const resolveNodeEdgeElements = (graph: Graph): EdgeNodeElement[] => {
|
||||
};
|
||||
|
||||
export const resolveNodeGraph = (graph: Graph): NodeGraph => {
|
||||
const nodes: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
||||
const edges: EdgeNodeElement[] = resolveNodeEdgeElements(graph);
|
||||
const nodes: GraphTaskElement[] = resolveGraphTaskElements(graph);
|
||||
const edges: GraphEdgeElement[] = resolveGraphEdgeElements(graph);
|
||||
return {
|
||||
nodes,
|
||||
edges,
|
||||
@@ -94,7 +94,7 @@ export const resolveNodeGraph = (graph: Graph): NodeGraph => {
|
||||
|
||||
export const hasElements = (graph: Graph): boolean => {
|
||||
if (graph) {
|
||||
const taskElements: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
||||
const taskElements: GraphTaskElement[] = resolveGraphTaskElements(graph);
|
||||
return taskElements.length > 0;
|
||||
}
|
||||
return false;
|
||||
@@ -102,7 +102,7 @@ export const hasElements = (graph: Graph): boolean => {
|
||||
|
||||
export const hasRootElementNode = (graph: Graph): boolean => {
|
||||
if (graph) {
|
||||
const taskElements: TaskNodeElement[] = resolveNodeTaskElements(graph);
|
||||
const taskElements: GraphTaskElement[] = resolveGraphTaskElements(graph);
|
||||
return taskElements.filter(e => e.type === 'root').length === 1;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -69,10 +69,10 @@ import Properties from './properties.vue';
|
||||
import { useGraphCanvas } from './builder/hooks';
|
||||
import { registerNodeElement } from './builder/register';
|
||||
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 { createModelNode, hasElements, hasRootElementNode, resolveNodeGraph } from './builder/utils';
|
||||
import { createTaskNodeElementFromTemplate } from './utils/node';
|
||||
import { createGraphTaskElement, hasElements, hasRootElementNode, resolveNodeGraph } from './builder/utils';
|
||||
import { createGraphTaskElementFromTemplate } from './utils/node';
|
||||
import TressCard from './trees-card.vue';
|
||||
import NodesCard from './nodes-card.vue';
|
||||
import { createLineOptions } from '@/views/decision/builder/line.ts';
|
||||
@@ -103,7 +103,7 @@ export default defineComponent({
|
||||
const currentBehaviorTree = ref<BehaviorTree | null>(null);
|
||||
const currentNodeGraph = ref<NodeGraph | 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 {
|
||||
@@ -188,9 +188,9 @@ export default defineComponent({
|
||||
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);
|
||||
|
||||
// 将节点添加到画布
|
||||
@@ -237,7 +237,7 @@ export default defineComponent({
|
||||
if (currentBehaviorTree.value?.graph && graph.value) {
|
||||
if (currentBehaviorTree.value?.graph.nodes) {
|
||||
currentBehaviorTree.value?.graph.nodes.forEach(ele => {
|
||||
const node = createModelNode(ele as TaskNodeElement);
|
||||
const node = createGraphTaskElement(ele as GraphTaskElement);
|
||||
console.info('create node: ', ele);
|
||||
// 将节点添加到画布
|
||||
graph.value?.addNode(node as Node);
|
||||
@@ -277,10 +277,10 @@ export default defineComponent({
|
||||
|
||||
handleGraphEvent('node:click', (args: any) => {
|
||||
const node = args.node as Node<NodeProperties>;
|
||||
const newElement = node.getData() as SettingTaskNodeElement;
|
||||
const newElement = node.getData() as GraphTaskElement;
|
||||
|
||||
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) {
|
||||
selectedModelNode.value.replaceData(element);
|
||||
|
||||
@@ -111,9 +111,9 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, onMounted, type PropType, ref, watch } from '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 {generateKey} from '@/utils/strings'
|
||||
import { generateKey } from '@/utils/strings';
|
||||
|
||||
const actionSpaceColumns = [
|
||||
{ title: '序号', dataIndex: 'index', key: 'index', width: 40 },
|
||||
@@ -136,7 +136,7 @@ export default defineComponent({
|
||||
const activeBottomTabs2Key = ref<string>('1');
|
||||
|
||||
const currentNode = ref<Node | null>(props.node ?? null);
|
||||
const currentElement = ref<SettingTaskNodeElement | null>(null);
|
||||
const currentElement = ref<GraphTaskElement | null>(null);
|
||||
|
||||
const load = () => {
|
||||
};
|
||||
@@ -145,7 +145,7 @@ export default defineComponent({
|
||||
currentNode.value = n ?? null;
|
||||
if (n) {
|
||||
const data = n.getData();
|
||||
currentElement.value = JSON.parse(JSON.stringify(data || {})) as SettingTaskNodeElement;
|
||||
currentElement.value = JSON.parse(JSON.stringify(data || {})) as GraphTaskElement;
|
||||
} else {
|
||||
currentElement.value = null;
|
||||
}
|
||||
@@ -178,7 +178,7 @@ export default defineComponent({
|
||||
const updateNode = () => {
|
||||
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);
|
||||
// 触发事件通知父组件
|
||||
|
||||
@@ -8,16 +8,7 @@
|
||||
*/
|
||||
|
||||
import type { ApiDataResponse, NullableString } from '@/types';
|
||||
|
||||
export interface NodeTemplateParameter {
|
||||
id: number,
|
||||
templateId: number,
|
||||
paramKey: NullableString,
|
||||
dataType: NullableString,
|
||||
defaultValue: NullableString,
|
||||
description: NullableString,
|
||||
templateType: NullableString,
|
||||
}
|
||||
import type { ElementParameter } from '../builder/element';
|
||||
|
||||
export interface NodeTemplate {
|
||||
id: number;
|
||||
@@ -27,7 +18,7 @@ export interface NodeTemplate {
|
||||
description: NullableString;
|
||||
templeteType: NullableString;
|
||||
englishName: NullableString;
|
||||
parameters: NodeTemplateParameter[],
|
||||
parameters: ElementParameter[],
|
||||
}
|
||||
|
||||
export interface NodeTemplatesResponse extends ApiDataResponse<NodeTemplate[]> {
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
*/
|
||||
|
||||
import type { NodeTemplate } from '../types';
|
||||
import type { SettingTaskNodeElement, TaskNodeRect } from '../builder/element';
|
||||
import type { GraphTaskElement, TaskNodeRect } from '../builder/element';
|
||||
import { generateKey } from '@/utils/strings';
|
||||
|
||||
export const createTaskNodeElementFromTemplate = (
|
||||
export const createGraphTaskElementFromTemplate = (
|
||||
template: NodeTemplate,
|
||||
rect?: TaskNodeRect,
|
||||
): SettingTaskNodeElement => {
|
||||
): GraphTaskElement => {
|
||||
let realRect = { width: 200, height: 100, x: 0, y: 0, ...rect || {} }
|
||||
console.info('rect',rect)
|
||||
return {
|
||||
@@ -51,5 +51,5 @@ export const createTaskNodeElementFromTemplate = (
|
||||
unit: '个'
|
||||
}
|
||||
],
|
||||
} as SettingTaskNodeElement;
|
||||
} as GraphTaskElement;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user