From fbab5f4e8d1a9d1d926184402755076724e13818 Mon Sep 17 00:00:00 2001 From: lzp Date: Tue, 17 Mar 2026 09:56:58 +0800 Subject: [PATCH] 11 --- src/components/Canvas/DepthCanvas/depth-canvas.vue | 5 +++-- src/components/Canvas/DepthCanvas/index.vue | 14 ++++++++++++-- .../DepthCanvas/manager/events/KeyEventManager.ts | 7 ++++--- src/components/Canvas/FlowCanvas/flow-canvas.vue | 4 ++-- .../Canvas/FlowCanvas/manager/EventManager.ts | 6 ++++-- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/components/Canvas/DepthCanvas/depth-canvas.vue b/src/components/Canvas/DepthCanvas/depth-canvas.vue index c526a6d..7c4a13b 100644 --- a/src/components/Canvas/DepthCanvas/depth-canvas.vue +++ b/src/components/Canvas/DepthCanvas/depth-canvas.vue @@ -88,12 +88,13 @@ const observer = ref(null) onMounted(() => { + keyEventManager.registerEvents() canvasManager.initCanvas({ canvasRef, canvasViewWidth: canvasContainerRef.value.clientWidth, canvasViewHeight: canvasContainerRef.value.clientHeight, - canvasWidth: 750, - canvasHeight: 600 + canvasWidth: props.config.width || 750, + canvasHeight: props.config.height || 600 }) stateManager.onMounted() canvasManager.onMounted() diff --git a/src/components/Canvas/DepthCanvas/index.vue b/src/components/Canvas/DepthCanvas/index.vue index 862dca5..e00f624 100644 --- a/src/components/Canvas/DepthCanvas/index.vue +++ b/src/components/Canvas/DepthCanvas/index.vue @@ -11,10 +11,20 @@ import depthCanvas from './depth-canvas.vue' import { ref } from 'vue' const dialogVisible = ref(false) - const config = ref({}) + const config = ref({ + width: 750, + height: 600, + }) const open = (options) => { dialogVisible.value = true - config.value = options || {} + // config.value = options || {} + const defaultConfig = { + canvasWidth: 750, + canvasHeight: 600, + canvasViewWidth: 750, + canvasViewHeight: 600, + } + config.value = { ...defaultConfig, ...options || {} } } const close = () => { dialogVisible.value = false diff --git a/src/components/Canvas/DepthCanvas/manager/events/KeyEventManager.ts b/src/components/Canvas/DepthCanvas/manager/events/KeyEventManager.ts index dd27ac4..eb347d3 100644 --- a/src/components/Canvas/DepthCanvas/manager/events/KeyEventManager.ts +++ b/src/components/Canvas/DepthCanvas/manager/events/KeyEventManager.ts @@ -2,11 +2,12 @@ export class KeyEventManager { stateManager: any constructor(options) { this.stateManager = options.stateManager; - this.registerEvents() + this._handleKeyDown = this.handleKeyDown.bind(this) } onMounted() { } /** 处理键盘事件 */ + _handleKeyDown: any handleKeyDown(event: any) { const ctrl = event.ctrlKey ? 'ctrl-' : ""; const shift = event.shiftKey ? 'shift-' : ""; @@ -24,11 +25,11 @@ export class KeyEventManager { } /** 注册事件 */ registerEvents() { - document.addEventListener('keydown', this.handleKeyDown.bind(this)) + document.addEventListener('keydown', this._handleKeyDown) } /** 删除事件 */ removeEvents() { - document.removeEventListener('keydown', this.handleKeyDown.bind(this)) + document.removeEventListener('keydown', this._handleKeyDown) } dispose() { this.removeEvents() diff --git a/src/components/Canvas/FlowCanvas/flow-canvas.vue b/src/components/Canvas/FlowCanvas/flow-canvas.vue index 91226ce..3888b3a 100644 --- a/src/components/Canvas/FlowCanvas/flow-canvas.vue +++ b/src/components/Canvas/FlowCanvas/flow-canvas.vue @@ -64,7 +64,7 @@