import { TOOLS } from "./ToolManager" export class EventManager { stateManager: any vueFlow: any zoom: any constructor(options) { this.stateManager = options.stateManager; this.vueFlow = options.vueFlow this.zoom = this.stateManager.zoom } /** 处理视口变化 */ handleViewportChange(e: any) { const { zoom } = e this.zoom.value = zoom } /** 处理节点拖动停止 */ 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 } }) } /** 处理点击 */ handleClick(event: any) { this.stateManager.setActiveNodeID("") 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) } } }