feat(settings-drawer): 为调试码输入框添加自动聚焦功能
更新了相关导入,添加输入框模板引用并在调试模态框打开时自动聚焦输入框
This commit is contained in:
@@ -13,9 +13,27 @@ import destr from 'destr';
|
|||||||
import { isFunction } from 'es-toolkit';
|
import { isFunction } from 'es-toolkit';
|
||||||
import localforage from 'localforage';
|
import localforage from 'localforage';
|
||||||
import { DownloadIcon, Trash2Icon, UploadIcon } from 'lucide-vue-next';
|
import { DownloadIcon, Trash2Icon, UploadIcon } from 'lucide-vue-next';
|
||||||
import { NButton, NButtonGroup, NDivider, NDrawer, NDrawerContent, NDropdown, NFlex, NFormItem, NIcon, NInput, NInputNumber, NModal, NSwitch, NText, NTooltip, type DropdownOption } from 'naive-ui';
|
import {
|
||||||
|
NButton,
|
||||||
|
NButtonGroup,
|
||||||
|
NDivider,
|
||||||
|
NDrawer,
|
||||||
|
NDrawerContent,
|
||||||
|
NDropdown,
|
||||||
|
NFlex,
|
||||||
|
NFormItem,
|
||||||
|
NIcon,
|
||||||
|
NInput,
|
||||||
|
NInputNumber,
|
||||||
|
NModal,
|
||||||
|
NSwitch,
|
||||||
|
NText,
|
||||||
|
NTooltip,
|
||||||
|
type DropdownOption,
|
||||||
|
type InputInst,
|
||||||
|
} from 'naive-ui';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, nextTick, ref, useTemplateRef, watch } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -149,8 +167,14 @@ useEventListener('keydown', (event) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const expectToShowDebugCodeInput = ref(false);
|
const expectToShowDebugCodeInput = ref(false);
|
||||||
|
const debugCodeInputRef = useTemplateRef<InputInst>('debug-code-input-ref');
|
||||||
const onModalAfterEnter = () => {
|
const onModalAfterEnter = () => {
|
||||||
expectToShowDebugCodeInput.value = !debugMode.value;
|
expectToShowDebugCodeInput.value = !debugMode.value;
|
||||||
|
if (expectToShowDebugCodeInput.value) {
|
||||||
|
nextTick(() => {
|
||||||
|
debugCodeInputRef.value?.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const onModalAfterLeave = () => {
|
const onModalAfterLeave = () => {
|
||||||
expectToShowDebugCodeInput.value = false;
|
expectToShowDebugCodeInput.value = false;
|
||||||
@@ -412,7 +436,7 @@ const onClickVersion = () => {
|
|||||||
<NText v-else>确认关闭调试模式</NText>
|
<NText v-else>确认关闭调试模式</NText>
|
||||||
</template>
|
</template>
|
||||||
<template #default>
|
<template #default>
|
||||||
<NInput v-if="expectToShowDebugCodeInput" v-model:value="debugCode" placeholder="输入调试码" @keyup.enter="enableDebugMode" />
|
<NInput ref="debug-code-input-ref" v-if="expectToShowDebugCodeInput" v-model:value="debugCode" placeholder="输入调试码" @keyup.enter="enableDebugMode" />
|
||||||
</template>
|
</template>
|
||||||
<template #action>
|
<template #action>
|
||||||
<NButton @click="showDebugCodeModal = false">取消</NButton>
|
<NButton @click="showDebugCodeModal = false">取消</NButton>
|
||||||
|
|||||||
Reference in New Issue
Block a user