diff --git a/web/src/components/DirTreeSelect.vue b/web/src/components/DirTreeSelect.vue index de8d777..eea53fa 100644 --- a/web/src/components/DirTreeSelect.vue +++ b/web/src/components/DirTreeSelect.vue @@ -6,7 +6,7 @@ import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover import { api, type FileNode } from '@/api' const props = defineProps<{ - modelValue: string + modelValue?: string placeholder?: string }>() @@ -19,17 +19,33 @@ const loading = ref(false) const fileTree = ref([]) const expandedDirs = ref>(new Set()) -// 只保留目录节点 -function filterDirs(nodes: FileNode[]): FileNode[] { - return nodes - .filter(n => n.isDir) - .map(n => ({ - ...n, - children: n.children ? filterDirs(n.children) : undefined - })) +interface FlatDir { + path: string + name: string + depth: number + hasChildren: boolean } -const dirTree = computed(() => filterDirs(fileTree.value)) +// 将树形结构扁平化,只保留目录 +function flattenDirs(nodes: FileNode[], depth = 0): FlatDir[] { + const result: FlatDir[] = [] + for (const node of nodes) { + if (!node.isDir) continue + const children = node.children?.filter(c => c.isDir) || [] + result.push({ + path: node.path, + name: node.name, + depth, + hasChildren: children.length > 0 + }) + if (expandedDirs.value.has(node.path) && node.children) { + result.push(...flattenDirs(node.children, depth + 1)) + } + } + return result +} + +const flatDirs = computed(() => flattenDirs(fileTree.value)) async function loadTree() { if (fileTree.value.length > 0) return @@ -43,7 +59,8 @@ async function loadTree() { } } -function toggleDir(path: string) { +function toggleDir(path: string, e: Event) { + e.stopPropagation() if (expandedDirs.value.has(path)) { expandedDirs.value.delete(path) } else { @@ -94,84 +111,37 @@ const displayValue = computed(() => { scripts (默认) - - + +
+ + + + + + + {{ dir.name }} +
加载中...
-
+
暂无子目录
- - diff --git a/web/src/views/tasks/Tasks.vue b/web/src/views/tasks/Tasks.vue index 4eefc7f..a1cef9c 100644 --- a/web/src/views/tasks/Tasks.vue +++ b/web/src/views/tasks/Tasks.vue @@ -295,7 +295,7 @@ onMounted(() => {
- +