index.vue
3.28 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
<template>
<div class="container">
<div ref="container" class="flow-container"></div>
<div class="control-panel">
<el-button
@click="handleOpenSelectionSelectOnce"
:disabled="isSelectionSelectOpen"
>单次框选</el-button>
<el-button
@click="handleOpenSelectionSelect"
:disabled="isSelectionSelectOpen"
>开启框选</el-button>
<el-button
@click="handleCloseSelectionSelect"
:disabled="!isSelectionSelectOpen"
>关闭框选</el-button>
<el-checkbox v-model="isWholeEdge">边全选</el-checkbox>
<el-checkbox v-model="isWholeNode">节点全选</el-checkbox>
</div>
</div>
</template>
<script setup>
import LogicFlow from '@logicflow/core';
import { SelectionSelect } from "@logicflow/extension";
const container = ref(null);
let lf = null;
const isSelectionSelectOpen = ref(false);
const isWholeEdge = ref(true);
const isWholeNode = ref(true);
// 监听全选模式变化
watch([isWholeEdge, isWholeNode], () => {
if (lf) {
const selectionSelect = lf.extension.selectionSelect;
selectionSelect.setSelectionSense(isWholeEdge.value, isWholeNode.value);
}
});
// 单次框选
const handleOpenSelectionSelectOnce = () => {
if (lf) {
const selectionSelect = lf.extension.selectionSelect;
// 开启框选功能
selectionSelect.openSelectionSelect();
isSelectionSelectOpen.value = true;
// 添加全局样式
document.body.style.cursor = 'crosshair';
// 框选操作结束后关闭框选功能
lf.once('selection:selected', () => {
selectionSelect.closeSelectionSelect();
isSelectionSelectOpen.value = false;
// 移除全局样式
document.body.style.cursor = 'default';
});
}
};
// 开启框选
const handleOpenSelectionSelect = () => {
if (lf) {
const selectionSelect = lf.extension.selectionSelect;
selectionSelect.openSelectionSelect();
isSelectionSelectOpen.value = true;
// 添加全局样式
document.body.style.cursor = 'crosshair';
}
};
// 关闭框选
const handleCloseSelectionSelect = () => {
if (lf) {
const selectionSelect = lf.extension.selectionSelect;
selectionSelect.closeSelectionSelect();
isSelectionSelectOpen.value = false;
// 移除全局样式
document.body.style.cursor = 'default';
}
};
onMounted(() => {
lf = new LogicFlow({
container: container.value,
grid: true,
plugins: [SelectionSelect],
});
lf.on('selection:selected-area', ({ topLeft, bottomRight }) => {
console.log('get selection area:', topLeft, bottomRight);
});
lf.render({
nodes: [
{ id: 'node1', type: 'rect', x: 200, y: 200 },
{ id: 'node2', type: 'circle', x: 400, y: 200 },
],
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%;
}
.control-panel {
position: absolute;
top: 20px;
left: 20px;
display: flex;
gap: 10px;
}
/* 添加新的全局样式类 */
:global(.lf-selection-select) {
cursor: crosshair !important;
}
/* 确保框选区域也使用相同的鼠标样式 */
:global(.lf-selection-select-rect) {
cursor: crosshair !important;
}
</style>