hookehuyr

框选功能

...@@ -105,6 +105,11 @@ const router = createRouter({ ...@@ -105,6 +105,11 @@ const router = createRouter({
105 name: 'mini-map', 105 name: 'mini-map',
106 component: () => import('../views/mini-map/index.vue') 106 component: () => import('../views/mini-map/index.vue')
107 }, 107 },
108 + {
109 + path: '/selection-select',
110 + name: 'selection-select',
111 + component: () => import('../views/selection-select/index.vue')
112 + },
108 ] 113 ]
109 }) 114 })
110 115
......
1 <!-- 1 <!--
2 * @Date: 2025-03-10 14:37:31 2 * @Date: 2025-03-10 14:37:31
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-03-13 20:52:22 4 + * @LastEditTime: 2025-03-13 21:58:47
5 * @FilePath: /logic-flow2/src/views/home.vue 5 * @FilePath: /logic-flow2/src/views/home.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
25 <el-button type="primary" @click="goTo('adv-dnd-panel')">adv-dnd-panel</el-button> 25 <el-button type="primary" @click="goTo('adv-dnd-panel')">adv-dnd-panel</el-button>
26 <el-button type="primary" @click="goTo('adv-dnd-panel-custom')">adv-dnd-panel-custom</el-button> 26 <el-button type="primary" @click="goTo('adv-dnd-panel-custom')">adv-dnd-panel-custom</el-button>
27 <el-button type="primary" @click="goTo('mini-map')">mini-map</el-button> 27 <el-button type="primary" @click="goTo('mini-map')">mini-map</el-button>
28 + <el-button type="primary" @click="goTo('selection-select')">selection-select</el-button>
28 </template> 29 </template>
29 30
30 <script setup> 31 <script setup>
......
1 +<template>
2 + <div class="container">
3 + <div ref="container" class="flow-container"></div>
4 + <div class="control-panel">
5 + <el-button
6 + @click="handleOpenSelectionSelectOnce"
7 + :disabled="isSelectionSelectOpen"
8 + >单次框选</el-button>
9 + <el-button
10 + @click="handleOpenSelectionSelect"
11 + :disabled="isSelectionSelectOpen"
12 + >开启框选</el-button>
13 + <el-button
14 + @click="handleCloseSelectionSelect"
15 + :disabled="!isSelectionSelectOpen"
16 + >关闭框选</el-button>
17 + <el-checkbox v-model="isWholeEdge">边全选</el-checkbox>
18 + <el-checkbox v-model="isWholeNode">节点全选</el-checkbox>
19 + </div>
20 + </div>
21 +</template>
22 +
23 +<script setup>
24 +import LogicFlow from '@logicflow/core';
25 +import { SelectionSelect } from "@logicflow/extension";
26 +
27 +const container = ref(null);
28 +let lf = null;
29 +
30 +const isSelectionSelectOpen = ref(false);
31 +const isWholeEdge = ref(true);
32 +const isWholeNode = ref(true);
33 +
34 +// 监听全选模式变化
35 +watch([isWholeEdge, isWholeNode], () => {
36 + if (lf) {
37 + const selectionSelect = lf.extension.selectionSelect;
38 + selectionSelect.setSelectionSense(isWholeEdge.value, isWholeNode.value);
39 + }
40 +});
41 +
42 +// 单次框选
43 +const handleOpenSelectionSelectOnce = () => {
44 + if (lf) {
45 + const selectionSelect = lf.extension.selectionSelect;
46 + // 开启框选功能
47 + selectionSelect.openSelectionSelect();
48 + isSelectionSelectOpen.value = true;
49 + // 添加全局样式
50 + document.body.style.cursor = 'crosshair';
51 + // 框选操作结束后关闭框选功能
52 + lf.once('selection:selected', () => {
53 + selectionSelect.closeSelectionSelect();
54 + isSelectionSelectOpen.value = false;
55 + // 移除全局样式
56 + document.body.style.cursor = 'default';
57 + });
58 + }
59 +};
60 +
61 +// 开启框选
62 +const handleOpenSelectionSelect = () => {
63 + if (lf) {
64 + const selectionSelect = lf.extension.selectionSelect;
65 + selectionSelect.openSelectionSelect();
66 + isSelectionSelectOpen.value = true;
67 + // 添加全局样式
68 + document.body.style.cursor = 'crosshair';
69 + }
70 +};
71 +
72 +// 关闭框选
73 +const handleCloseSelectionSelect = () => {
74 + if (lf) {
75 + const selectionSelect = lf.extension.selectionSelect;
76 + selectionSelect.closeSelectionSelect();
77 + isSelectionSelectOpen.value = false;
78 + // 移除全局样式
79 + document.body.style.cursor = 'default';
80 + }
81 +};
82 +
83 +onMounted(() => {
84 + lf = new LogicFlow({
85 + container: container.value,
86 + grid: true,
87 + plugins: [SelectionSelect],
88 + });
89 +
90 + lf.on('selection:selected-area', ({ topLeft, bottomRight }) => {
91 + console.log('get selection area:', topLeft, bottomRight);
92 + });
93 +
94 + lf.render({
95 + nodes: [
96 + { id: 'node1', type: 'rect', x: 200, y: 200 },
97 + { id: 'node2', type: 'circle', x: 400, y: 200 },
98 + ],
99 + edges: [{ id: 'edge1', sourceNodeId: 'node1', targetNodeId: 'node2' }],
100 + });
101 +});
102 +</script>
103 +
104 +<style scoped>
105 +.container {
106 + width: 100vw;
107 + height: 100vh;
108 + display: flex;
109 + flex-direction: column;
110 +}
111 +
112 +.flow-container {
113 + flex: 1;
114 + width: 100%;
115 + height: 100%;
116 +}
117 +
118 +.control-panel {
119 + position: absolute;
120 + top: 20px;
121 + left: 20px;
122 + display: flex;
123 + gap: 10px;
124 +}
125 +
126 +/* 添加新的全局样式类 */
127 +:global(.lf-selection-select) {
128 + cursor: crosshair !important;
129 +}
130 +
131 +/* 确保框选区域也使用相同的鼠标样式 */
132 +:global(.lf-selection-select-rect) {
133 + cursor: crosshair !important;
134 +}
135 +</style>