custom-node.js
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* @Date: 2025-03-10 16:20:35
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-10 16:33:34
* @FilePath: /logic-flow2/src/components/logicflow/custom-node.ts
* @Description: 文件描述
*/
// src/components/logicflow/CustomNode.ts
import { RectNode, RectNodeModel } from "@logicflow/core";
// 自定义模型
export class CustomModel extends RectNodeModel {
setAttributes() {
this.stroke = "#1E90FF";
this.fill = "#F0F8FF";
this.radius = 10;
const { isDisabledNode } = this.properties;
// 动态菜单配置
if (!isDisabledNode) {
this.menu = [
{
className: "lf-menu-delete",
icon: true,
callback: (node) => {
this.graphModel.deleteNode(node.id);
this.graphModel.eventCenter.emit("custom:event", node);
},
},
{
text: "Edit",
className: "lf-menu-item",
callback: (node) => {
this.graphModel.setElementStateById(node.id, 2);
},
},
{
text: "Copy",
className: "lf-menu-item",
callback: (node) => {
this.graphModel.cloneNode(node.id);
},
},
];
}
}
}
// 使用默认矩形视图
export const CustomNode = RectNode;