From 4115753f1f6155a9ae74946646bb87da0dbd624b Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Mon, 26 Oct 2026 20:29:46 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20Hotkey=20=E7=B3=BB=E7=BB=9F=E9=81=97?= =?UTF-8?q?=E7=95=99=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages-user/client-base/src/use/hotkey.ts | 4 +-- .../client-modules/src/render/use.ts | 25 ------------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/packages-user/client-base/src/use/hotkey.ts b/packages-user/client-base/src/use/hotkey.ts index 944323c..75e7f71 100644 --- a/packages-user/client-base/src/use/hotkey.ts +++ b/packages-user/client-base/src/use/hotkey.ts @@ -1,6 +1,6 @@ import { IHotkeyEmitInfo, IHotkeySystem } from '@motajs/system'; import { IHotkeyUsing } from './types'; -import { getCurrentInstance, onMounted, onUnmounted } from 'vue'; +import { getCurrentInstance, onBeforeMount, onUnmounted } from 'vue'; import { logger } from '@motajs/common'; class HotkeyUsing implements IHotkeyUsing { @@ -21,7 +21,7 @@ class HotkeyUsing implements IHotkeyUsing { const { promise, resolve } = Promise.withResolvers(); this.scopePromise = promise; - onMounted(() => { + onBeforeMount(() => { this.mounted = true; const scope = system.enterScope(clearImpl); this.keyScope = scope; diff --git a/packages-user/client-modules/src/render/use.ts b/packages-user/client-modules/src/render/use.ts index 55b6aaa..81d7644 100644 --- a/packages-user/client-modules/src/render/use.ts +++ b/packages-user/client-modules/src/render/use.ts @@ -8,7 +8,6 @@ import { } from '@motajs/animate'; import { logger } from '@motajs/common'; import { IRenderItem, IRenderTreeRoot } from '@motajs/render'; -import { Hotkey, gameKey } from '@motajs/system'; import { ComponentInternalInstance, getCurrentInstance, @@ -64,30 +63,6 @@ export function onOrientationChange(hook: OrientationHook) { }); } -type KeyUsing = [Hotkey, symbol]; - -/** - * 在组件中定义按键操作 - * @param noScope 是否不创建新作用域 - * @param scope 指定作用域,如果 `noScope` 为 `true`,则此项无效 - */ -export function useKey(noScope: boolean = false, scope?: symbol): KeyUsing { - if (noScope) { - return [gameKey, gameKey.scope]; - } else { - const sym = scope ?? Symbol(); - if (sym === gameKey.scope) { - return [gameKey, gameKey.scope]; - } else { - gameKey.use(sym); - onUnmounted(() => { - gameKey.dispose(); - }); - return [gameKey, sym]; - } - } -} - export interface ITransitionedController { readonly ref: Ref; readonly value: T;