feat: Add default value support for file selection component (#10055)

This commit is contained in:
ssongliu 2025-08-19 17:29:15 +08:00 committed by GitHub
parent 34b80373c7
commit fd1e0e72a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 7 deletions

View file

@ -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<string>('');
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;

View file

@ -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,
};
}