Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
logic-flow2
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-03-13 22:49:23 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0db9685166159d5a6a1f71ea5fabb3cb1b55a9e1
0db96851
1 parent
a9b149dd
框选功能
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
142 additions
and
1 deletions
src/router/index.js
src/views/home.vue
src/views/selection-select/index.vue
src/router/index.js
View file @
0db9685
...
...
@@ -105,6 +105,11 @@ const router = createRouter({
name
:
'mini-map'
,
component
:
()
=>
import
(
'../views/mini-map/index.vue'
)
},
{
path
:
'/selection-select'
,
name
:
'selection-select'
,
component
:
()
=>
import
(
'../views/selection-select/index.vue'
)
},
]
})
...
...
src/views/home.vue
View file @
0db9685
<!--
* @Date: 2025-03-10 14:37:31
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-13 2
0:52:22
* @LastEditTime: 2025-03-13 2
1:58:47
* @FilePath: /logic-flow2/src/views/home.vue
* @Description: 文件描述
-->
...
...
@@ -25,6 +25,7 @@
<el-button type="primary" @click="goTo('adv-dnd-panel')">adv-dnd-panel</el-button>
<el-button type="primary" @click="goTo('adv-dnd-panel-custom')">adv-dnd-panel-custom</el-button>
<el-button type="primary" @click="goTo('mini-map')">mini-map</el-button>
<el-button type="primary" @click="goTo('selection-select')">selection-select</el-button>
</template>
<script setup>
...
...
src/views/selection-select/index.vue
0 → 100644
View file @
0db9685
<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>
Please
register
or
login
to post a comment