Files
FiDA_Front/src/components/Canvas/FlowCanvas/manager/EventManager.ts

41 lines
1.0 KiB
TypeScript
Raw Normal View History

2026-03-04 15:06:22 +08:00
import { TOOLS } from "./ToolManager"
2026-02-26 11:45:32 +08:00
export class EventManager {
stateManager: any
vueFlow: any
zoom: any
constructor(options) {
this.stateManager = options.stateManager;
this.vueFlow = options.vueFlow
this.zoom = this.stateManager.zoom
}
2026-03-04 15:06:22 +08:00
/** 处理视口变化 */
2026-02-26 11:45:32 +08:00
handleViewportChange(e: any) {
const { zoom } = e
this.zoom.value = zoom
}
2026-03-04 15:06:22 +08:00
/** 处理节点拖动停止 */
2026-02-26 11:45:32 +08:00
handleNodeDragStop(e: any) {
const { node } = e
const { id, position } = node
this.stateManager.nodes.value.forEach((item) => {
if (item.id === id) {
item.position.x = position.x
item.position.y = position.y
}
})
}
2026-03-04 15:06:22 +08:00
/** 处理点击 */
handleClick(event: any) {
const tool = this.stateManager.tool.value
if (tool === TOOLS.TEXT) {
const { x, y, zoom } = this.vueFlow.value.viewport
const position = {
x: (event.offsetX - x) / zoom,
y: (event.offsetY - y) / zoom
}
this.stateManager.nodeManager.createTextNode({ position })
this.stateManager.toolManager.setTool(TOOLS.SELECT)
}
}
2026-02-26 11:45:32 +08:00
}