11<script setup lang="ts">
2- import {computed , ref } from " vue" ;
2+ import {computed , ref , nextTick } from " vue" ;
33import {Dialog } from " ../../lib/dialog" ;
44import {t } from " ../../lang" ;
55import {DeviceRecord , EnumDeviceStatus } from " ../../types/Device" ;
@@ -15,6 +15,7 @@ const isListView = ref(true) // 默认显示列表视图
1515const sortOrderName = ref (' asc' ); // 默认按文件名升序
1616const sortOrderModifiedTime = ref (' asc' ); // 默认按修改时间升序
1717const currentSortField = ref (' name' ); // 当前排序字段
18+ const inputRef = ref <HTMLInputElement | null >(null ); // 输入框引用
1819
1920const 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
9498const 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