index.vue
3.39 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<template>
<div class="container">
<div ref="container" class="flow-container"></div>
<div class="control-panel">
<el-button @click="openSelectionSelect">选区</el-button>
<div v-for="item in dndConfig" :key="item.type" class="dnd-item">
<img :src="item.icon" :alt="item.label" />
<span>{{ item.label }}</span>
</div>
</div>
</div>
</template>
<script setup>
import LogicFlow from "@logicflow/core";
import { DynamicGroup } from "@logicflow/extension";
const container = ref(null);
let lf = null;
// 拖拽面板配置
const dndConfig = [
{
type: 'dynamic-group',
label: '内置动态分组',
text: 'DynamicGroup',
icon: 'https://cdn.jsdelivr.net/gh/Logic-Flow/static@latest/docs/examples/extension/group/group.png',
},
{
type: 'circle',
label: '圆形',
text: 'Circle',
icon: 'https://cdn.jsdelivr.net/gh/Logic-Flow/static@latest/docs/examples/extension/group/circle.png',
},
{
type: 'rect',
label: '矩形',
text: 'Rect',
icon: 'https://cdn.jsdelivr.net/gh/Logic-Flow/static@latest/docs/examples/extension/group/rect.png',
},
];
// 选区功能
const openSelectionSelect = () => {
if (lf) {
lf.openSelectionSelect();
lf.once('selection:selected', () => {
lf.closeSelectionSelect();
});
}
};
onMounted(() => {
lf = new LogicFlow({
container: container.value,
grid: true,
multipleSelectKey: "alt",
autoExpand: false,
allowResize: true,
allowRotate: true,
nodeTextDraggable: false,
keyboard: {
enabled: true,
},
plugins: [DynamicGroup],
});
// 设置拖拽面板
const dndPanelConfig = [
{
label: '选区',
icon: 'https://cdn.jsdelivr.net/gh/Logic-Flow/static@latest/docs/examples/extension/bpmn/select.png',
callback: openSelectionSelect,
},
...dndConfig,
];
lf.setPatternItems(dndPanelConfig);
// 渲染数据
const graphData = {
nodes: [
{
id: 'circle_2',
type: 'circle',
x: 800,
y: 140,
text: {
value: 'circle_2',
x: 800,
y: 140,
editable: false,
draggable: true,
},
},
{
id: 'dynamic-group_1',
type: 'dynamic-group',
x: 500,
y: 140,
text: 'dynamic-group_1',
resizable: true,
properties: {
collapsible: true,
width: 420,
height: 250,
radius: 5,
isCollapsed: true,
},
},
{
id: 'dynamic-group_2',
type: 'dynamic-group',
x: 500,
y: 220,
text: 'dynamic-group_2',
resizable: true,
properties: {
width: 420,
height: 250,
radius: 5,
collapsible: false,
isCollapsed: false,
},
},
],
edges: [],
};
lf.render(graphData);
});
</script>
<style scoped>
.container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
}
.flow-container {
flex: 1;
width: 100%;
height: 100%;
}
.control-panel {
position: absolute;
top: 20px;
left: 20px;
display: flex;
gap: 10px;
align-items: center;
}
.dnd-item {
display: flex;
flex-direction: column;
align-items: center;
cursor: pointer;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
.dnd-item img {
width: 24px;
height: 24px;
margin-bottom: 4px;
}
</style>