index.vue
2.68 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!--
* @Date: 2025-03-10 16:52:35
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-12 18:00:09
* @FilePath: /logic-flow2/src/views/theme/index.vue
* @Description: 主题 Theme
-->
<template>
<div class="container">
<div ref="container" class="flow-container"></div>
</div>
</template>
<script setup>
import LogicFlow from "@logicflow/core";
import CustomEdge from "./CustomEdge";
const container = ref(null);
let lf = null;
onMounted(() => {
// 方法1:new LogicFlow时作为配置传入
const config = {
domId: "app",
width: 1000,
height: 800,
style: {
// 设置默认主题样式
// rect: { ... }, // 矩形样式
// circle: { ... }, // 圆形样式
// nodeText: { ... }, // 节点文本样式
// edgeText: { ... }, // 边文本样式
// anchor: { ... }, // 锚点样式
// ...,
},
};
// 方法2: 调用LogicFlow的setTheme方法
// lf.setTheme({ // 设置默认主题样式
// rect: {...}, // 矩形样式
// circle: {...}, // 圆形样式
// nodeText: {...}, // 节点文本样式
// edgeText: {...}, // 边文本样式
// anchor: {...}, // 锚点样式
// ...
// })
lf = new LogicFlow({
container: container.value,
grid: true,
});
lf.setTheme({
rect: {
fill: "#FFFFFF",
stroke: "rgba(68, 83, 130, 0.25)",
strokeWidth: 1,
anchorShow: true, // 强制显示锚点
anchorHoverShow: true, // 保持 hover 效果
},
circle: {
// 新增圆形节点配置
anchorShow: true, // 强制显示锚点
anchorHoverShow: true,
},
anchor: {
stroke: "#4d53e8",
fill: "#4d53e8",
r: 3,
show: true, // 新增:全局显示锚点
hover: {
fill: "#949494",
fillOpacity: 0.5,
stroke: "#949494",
r: 10,
},
},
});
lf.register(CustomEdge);
// 使用自定义连线类型
lf.setDefaultEdgeType("custom-edge");
lf.render({
nodes: [
{ id: "node1", type: "rect", x: 200, y: 100 },
{ id: "node2", type: "circle", x: 400, y: 100 },
{ id: '7', type: 'html', x: 600, y: 320 },
],
edges: [
{ id: "edge1", sourceNodeId: "node1", targetNodeId: "node2", type: "custom-edge" },
],
});
lf.on("node:render", (node) => {
const { nodeConfig } = node;
// 设定锚点
nodeConfig.anchors = [
{ x: 0.5, y: 0 }, // 上部中间
{ x: 0.5, y: 1 }, // 下部中间
];
// 也可以设置其他锚点
});
});
</script>
<style scoped>
.container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
}
.flow-container {
flex: 1;
width: 100%;
height: 100%;
}
</style>