index.vue
1.95 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!--
* @Date: 2025-03-10 16:52:35
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-13 16:51:49
* @FilePath: /logic-flow2/src/views/adv-menu/index.vue
* @Description: 拖拽面板
-->
<template>
<div class="container">
<div ref="container" class="flow-container"></div>
</div>
</template>
<script setup>
import LogicFlow from "@logicflow/core";
import customNode from "./customNode";
import customEdge from "./customEdge";
const container = ref(null);
let lf = null;
onMounted(() => {
lf = new LogicFlow({
container: container.value,
grid: true,
});
lf.register(customNode);
lf.register(customEdge);
// 设置默认边的类型为自定义边类型
lf.setDefaultEdgeType("custom_edge");
lf.on("custom:event", (r) => {
console.log(r);
});
/**
* 根据菜单结构中的 class 覆盖原有样式,设置符合宿主风格的样式。
* 菜单:lf-menu
* 菜单项:lf-menu-item、用户自定义的 className
* 菜单项-文案:lf-menu-item-text
* 菜单项-图标:lf-menu-item-icon,需要将菜单项配置 icon 设置为 true 通过设置这些 class,可以覆盖默认样式,美化字体颜色,设置菜单项 icon 等。
*/
// TAG: 以上介绍的菜单配置必须在 lf.render()之前调用。
lf.render({
nodes: [
{ id: "node1", type: "rect", x: 200, y: 100 },
{ id: "node2", type: "circle", x: 400, y: 100 },
{ id: "node3", type: "custom-node", x: 600, y: 100 },
],
edges: [{ id: "edge1", sourceNodeId: "node1", targetNodeId: "node2" }],
});
});
</script>
<style scoped>
.container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
}
.flow-container {
flex: 1;
width: 100%;
height: 100%;
}
:deep(.lf-menu-delete .lf-menu-item-icon) {
display: inline-block;
width: 20px;
height: 20px;
background: url("https://pic.616pic.com/ys_img/00/05/00/YgOv6ujQ2V.jpg") no-repeat;
background-size: 20px;
}
</style>