diff --git a/frontend/src/components/file-list/index.vue b/frontend/src/components/file-list/index.vue index 1028903e7..037a53b9c 100644 --- a/frontend/src/components/file-list/index.vue +++ b/frontend/src/components/file-list/index.vue @@ -111,7 +111,7 @@ import { createFile, getFilesList } from '@/api/modules/files'; import { onUpdated, reactive, ref } from 'vue'; import i18n from '@/lang'; import { MsgSuccess, MsgWarning } from '@/utils/message'; -import { useSearchable } from '@/views/host/file-management/hooks/searchable'; +import { useSearchableForSelect } from '@/views/host/file-management/hooks/searchable'; const data = ref([]); const loading = ref(false); @@ -123,7 +123,7 @@ const open = ref(false); const newFolder = ref(); const disBtn = ref(false); -const { searchableStatus, searchablePath, searchableInputRef, searchableInputBlur } = useSearchable(paths); +const { searchableStatus, searchablePath, searchableInputRef, searchableInputBlur } = useSearchableForSelect(paths); const oldUrl = ref(''); const em = defineEmits(['choose']); @@ -197,11 +197,9 @@ const openDir = async (row: File.File) => { const jump = async (index: number) => { oldUrl.value = req.path; let path = ''; - if (index != -1) { - if (index !== -1) { - const jPaths = paths.value.slice(0, index + 1); - path = '/' + jPaths.join('/'); - } + if (index !== -1) { + const jPaths = paths.value.slice(0, index + 1); + path = '/' + jPaths.join('/'); } path = path || '/'; req.path = path; diff --git a/frontend/src/views/host/file-management/hooks/searchable.ts b/frontend/src/views/host/file-management/hooks/searchable.ts index b3f411f64..991b59f06 100644 --- a/frontend/src/views/host/file-management/hooks/searchable.ts +++ b/frontend/src/views/host/file-management/hooks/searchable.ts @@ -24,3 +24,32 @@ export function useSearchable(paths) { searchableInputBlur, }; } + +export function useSearchableForSelect(paths) { + const searchableStatus = ref(false); + const searchablePath = ref(''); + const searchableInputRef = ref(); + + watch(searchableStatus, (val) => { + if (val) { + if (paths.value.length === 0) { + searchablePath.value = '/'; + } else { + searchablePath.value = '/' + paths.value.join('/'); + } + nextTick(() => { + searchableInputRef.value?.focus(); + }); + } + }); + const searchableInputBlur = () => { + searchableStatus.value = false; + }; + + return { + searchableStatus, + searchablePath, + searchableInputRef, + searchableInputBlur, + }; +}