画布隐藏关闭键盘事件

This commit is contained in:
李志鹏
2025-11-03 16:41:54 +08:00
parent ddb5371133
commit 33a4d9e398
3 changed files with 36 additions and 0 deletions

View File

@@ -114,6 +114,10 @@ const props = defineProps({
type: Boolean,
default: false,
},
hideCanvas: {
type: Boolean,
default: false, // 是否隐藏画布-隐藏关闭部分功能
},
});
// 引用和状态
@@ -171,6 +175,15 @@ function toggleShortcutHelp() {
showShortcutHelp.value = !showShortcutHelp.value;
}
watch(()=>props.hideCanvas, (newVal)=>{
console.log("==========是否隐藏画布",newVal)
if(newVal){
keyboardManager?.removeEvents()
}else {
keyboardManager?.init()
}
})
// 工具选择处理
function handleToolSelect(tool) {
activeTool.value = tool;

View File

@@ -215,6 +215,25 @@ export class KeyboardManager {
console.log(`键盘管理器已初始化,平台: ${this.platform}, 触摸设备: ${this.isTouchDevice}`);
}
/**
* hide模式下关闭快捷键
*/
removeEvents() {
// 移除键盘事件监听
this.container.removeEventListener("keydown", this._handleKeyDown);
this.container.removeEventListener("keyup", this._handleKeyUp);
// 如果是触摸设备,移除触摸事件监听
if (this.isTouchDevice) {
this.container.removeEventListener("touchstart", this._handleTouchStart);
this.container.removeEventListener("touchmove", this._handleTouchMove);
this.container.removeEventListener("touchend", this._handleTouchEnd);
this.container.removeEventListener("touchcancel", this._handleTouchEnd);
}
}
/**
* 处理键盘按下事件
* @param {KeyboardEvent} event 键盘事件

View File

@@ -56,6 +56,7 @@
@changeCanvas="changeCanvas"
@trigger-library="triggerLibrary"
:canvasJSON="canvasJSON"
:hideCanvas="hideCanvas"
ref="editCanvas">
<template #existsImageList>
<ExistsImageList :list="canvasSelectList" @select="handleImageSelect" />
@@ -100,6 +101,7 @@ import JSZip, { forEach } from "jszip";
import publish from "@/component/WorksPage/publish.vue";
import canvasAA from '@/component/Canvas/canvasExample.vue'
import SelectImages from '@/component/common/SelectImages.vue'
import { useRouter, useRoute } from 'vue-router'
export default defineComponent({
@@ -117,12 +119,14 @@ export default defineComponent({
const store = useStore();
let locale = null as any;
let t = null as any;
const route = useRoute()
const data = reactive({
designTools:false,
isShowMark:false,
openType:'',
selectObject:computed(()=>store.state.Workspace.probjects),//选择的项目
canvasJSON:computed(()=>store.state.HomeStoreModule.canvasData.canvas),
hideCanvas: computed(()=>store.state.Workspace.projectPath !== route.fullPath),
createProbject:inject('createProbject',()=>{}) as any,
likeDesignList:[],
canvasSelectList:[] as any,