Skip to content

Commit 75cf44d

Browse files
authored
Merge pull request #44 from kkroid/fix-focus-issue
修复文件管理页面的输入窗口焦点问题
2 parents e352fd3 + 7c82bc8 commit 75cf44d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/components/Device/DeviceFileManagerDialog.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import {computed, ref} from "vue";
2+
import {computed, ref, nextTick} from "vue";
33
import {Dialog} from "../../lib/dialog";
44
import {t} from "../../lang";
55
import {DeviceRecord, EnumDeviceStatus} from "../../types/Device";
@@ -15,6 +15,7 @@ const isListView = ref(true) // 默认显示列表视图
1515
const sortOrderName = ref('asc'); // 默认按文件名升序
1616
const sortOrderModifiedTime = ref('asc'); // 默认按修改时间升序
1717
const currentSortField = ref('name'); // 当前排序字段
18+
const inputRef = ref<HTMLInputElement | null>(null); // 输入框引用
1819
1920
const show = (d: DeviceRecord) => {
2021
if (d.status !== EnumDeviceStatus.CONNECTED) {
@@ -86,9 +87,12 @@ const doUp = () => {
8687
}
8788
}
8889
89-
const doEditPath = () => {
90+
const doEditPath = async () => {
9091
isEditPath.value = true
9192
filePathEditing.value = filePath.value
93+
// 下一次tick后,输入框自动获取焦点
94+
await nextTick();
95+
inputRef.value?.focus();
9296
}
9397
9498
const doEditPathConfirm = () => {
@@ -211,8 +215,10 @@ const toggleSortByModifiedTime = () => {
211215
</a-breadcrumb>
212216
</div>
213217
<div v-else class="h-10 w-full flex items-center">
214-
<a-input v-model="filePathEditing"
215-
@pressEnter="doEditPathConfirm">
218+
<!-- 点击确认按钮、失去焦点都触发确认 -->
219+
<a-input ref="inputRef" v-model="filePathEditing"
220+
@pressEnter="doEditPathConfirm"
221+
@blur="doEditPathConfirm">
216222
<template #prepend>
217223
<div class="cursor-pointer" @click="isEditPath=false">
218224
<icon-close/>

0 commit comments

Comments
 (0)