Spaces:
Sleeping
Sleeping
Aye10032 commited on
Commit ·
11397cf
1
Parent(s): 5194233
feat: Add nodes at last clicked canvas position
Browse files
front/src/components/NodeEditor.vue
CHANGED
|
@@ -285,6 +285,7 @@
|
|
| 285 |
@connect="onConnect"
|
| 286 |
@node-click="onNodeClick"
|
| 287 |
@nodes-change="onNodesChange"
|
|
|
|
| 288 |
@ready="onVueFlowReady"
|
| 289 |
@init="onVueFlowInit"
|
| 290 |
>
|
|
@@ -318,7 +319,7 @@ import { useI18n } from 'vue-i18n'
|
|
| 318 |
import { useRoute, useRouter } from 'vue-router'
|
| 319 |
import LanguageSwitcher from './LanguageSwitcher.vue'
|
| 320 |
import { i18n } from '../i18n'
|
| 321 |
-
import { VueFlow } from '@vue-flow/core'
|
| 322 |
import type { Connection } from '@vue-flow/core'
|
| 323 |
import { Background } from '@vue-flow/background'
|
| 324 |
import { Controls } from '@vue-flow/controls'
|
|
@@ -441,6 +442,14 @@ const nodes = ref<WorkflowNode[]>([])
|
|
| 441 |
const edges = ref<WorkflowEdge[]>([])
|
| 442 |
const vueFlowReady = ref(false)
|
| 443 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
// 监听nodes变化,用于调试
|
| 445 |
watch(nodes, (newNodes) => {
|
| 446 |
console.log('Nodes changed, count:', newNodes.length)
|
|
@@ -1029,7 +1038,7 @@ const addNodeFromLibrary = (nodeType: string, position?: { x: number; y: number
|
|
| 1029 |
const newNode: WorkflowNode = {
|
| 1030 |
id: `node-${++nodeIdCounter.value}`,
|
| 1031 |
type: 'default',
|
| 1032 |
-
position: position ?? { x: 420 + (nodes.value.length % 3) * 40, y: 220 + (nodes.value.length % 5) * 40 },
|
| 1033 |
data: {
|
| 1034 |
label: config.label || `节点 ${nodeIdCounter.value}`,
|
| 1035 |
nodeType: config.nodeType || nodeType,
|
|
|
|
| 285 |
@connect="onConnect"
|
| 286 |
@node-click="onNodeClick"
|
| 287 |
@nodes-change="onNodesChange"
|
| 288 |
+
@pane-click="onPaneClick"
|
| 289 |
@ready="onVueFlowReady"
|
| 290 |
@init="onVueFlowInit"
|
| 291 |
>
|
|
|
|
| 319 |
import { useRoute, useRouter } from 'vue-router'
|
| 320 |
import LanguageSwitcher from './LanguageSwitcher.vue'
|
| 321 |
import { i18n } from '../i18n'
|
| 322 |
+
import { VueFlow, useVueFlow } from '@vue-flow/core'
|
| 323 |
import type { Connection } from '@vue-flow/core'
|
| 324 |
import { Background } from '@vue-flow/background'
|
| 325 |
import { Controls } from '@vue-flow/controls'
|
|
|
|
| 442 |
const edges = ref<WorkflowEdge[]>([])
|
| 443 |
const vueFlowReady = ref(false)
|
| 444 |
|
| 445 |
+
const { screenToFlowCoordinate } = useVueFlow()
|
| 446 |
+
// 记录用户上一次在画布空白处点击的位置,新节点将添加到此处
|
| 447 |
+
const lastClickPosition = ref<{ x: number; y: number } | null>(null)
|
| 448 |
+
|
| 449 |
+
const onPaneClick = (event: MouseEvent) => {
|
| 450 |
+
lastClickPosition.value = screenToFlowCoordinate({ x: event.clientX, y: event.clientY })
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
// 监听nodes变化,用于调试
|
| 454 |
watch(nodes, (newNodes) => {
|
| 455 |
console.log('Nodes changed, count:', newNodes.length)
|
|
|
|
| 1038 |
const newNode: WorkflowNode = {
|
| 1039 |
id: `node-${++nodeIdCounter.value}`,
|
| 1040 |
type: 'default',
|
| 1041 |
+
position: position ?? lastClickPosition.value ?? { x: 420 + (nodes.value.length % 3) * 40, y: 220 + (nodes.value.length % 5) * 40 },
|
| 1042 |
data: {
|
| 1043 |
label: config.label || `节点 ${nodeIdCounter.value}`,
|
| 1044 |
nodeType: config.nodeType || nodeType,
|