mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-04 23:18:44 +08:00
fix DirectoryTreeInput
This commit is contained in:
@@ -1,57 +1,88 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
|
import { FileItem } from '@/api/types'
|
||||||
import { VTreeview } from 'vuetify/labs/VTreeview'
|
import { VTreeview } from 'vuetify/labs/VTreeview'
|
||||||
|
|
||||||
|
// 输入变量为默认路径
|
||||||
|
const props = defineProps({
|
||||||
|
root: {
|
||||||
|
type: String,
|
||||||
|
default: '/',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// update:modelValue 事件
|
||||||
|
const emit = defineEmits(['update:modelValue'])
|
||||||
|
|
||||||
// 激活的目录
|
// 激活的目录
|
||||||
const activedDirs = ref<string[]>([])
|
const activedDirs = ref<string[]>([])
|
||||||
|
|
||||||
// 打开的目录
|
// 打开的目录
|
||||||
const openedDirs = ref<string[]>([])
|
const openedDirs = ref<string[]>([])
|
||||||
|
|
||||||
|
// 当前选中的目录
|
||||||
|
const selectedDir = ref<string>('')
|
||||||
|
|
||||||
// 目录列表
|
// 目录列表
|
||||||
const items = ref([
|
const treeItems = ref<FileItem[]>([
|
||||||
{
|
{
|
||||||
name: '/',
|
name: props.root,
|
||||||
path: '/',
|
path: props.root,
|
||||||
children: [],
|
children: [],
|
||||||
|
type: '',
|
||||||
|
basename: props.root,
|
||||||
|
extension: '',
|
||||||
|
size: 0,
|
||||||
|
modify_time: 0,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
const itemList = computed(() => {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
name: '/',
|
|
||||||
path: '/',
|
|
||||||
children: items.value,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
// 拉取子目录
|
// 拉取子目录
|
||||||
async function fetchDirs(item: any) {
|
async function fetchDirs(item: any) {
|
||||||
return api
|
return api
|
||||||
.get('/filebrowser/listdir?path=' + item.path)
|
.get('/filebrowser/listdir?path=' + item.path)
|
||||||
.then(res => res)
|
|
||||||
.then((data: any) => {
|
.then((data: any) => {
|
||||||
item.children.push(...data)
|
item.children.push(...data)
|
||||||
})
|
})
|
||||||
.catch(err => console.warn(err))
|
.catch(err => console.warn(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 监听目录变化
|
||||||
|
watch(activedDirs, newVal => {
|
||||||
|
if (!newVal.length) return
|
||||||
|
selectedDir.value = newVal[0]
|
||||||
|
emit('update:modelValue', newVal[0])
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fetchDirs(treeItems.value[0])
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VTreeview
|
<VMenu>
|
||||||
v-model:activated="activedDirs"
|
<template v-slot:activator="{ props }">
|
||||||
v-model:opened="openedDirs"
|
<VTextField v-model="selectedDir" label="路径" variant="underlined" v-bind="props"></VTextField>
|
||||||
:items="items"
|
</template>
|
||||||
:load-children="fetchDirs"
|
<VTreeview
|
||||||
density="compact"
|
v-model:activated="activedDirs"
|
||||||
item-key="path"
|
v-model:opened="openedDirs"
|
||||||
item-title="name"
|
:items="treeItems"
|
||||||
item-value="path"
|
:load-children="fetchDirs"
|
||||||
activatable
|
density="compact"
|
||||||
open-on-click
|
item-key="path"
|
||||||
transition
|
item-title="name"
|
||||||
>
|
item-value="path"
|
||||||
</VTreeview>
|
item-type="unknown"
|
||||||
|
activatable
|
||||||
|
open-on-click
|
||||||
|
transition
|
||||||
|
return-object
|
||||||
|
max-height="20rem"
|
||||||
|
selectable
|
||||||
|
class="cursor-pointer"
|
||||||
|
>
|
||||||
|
</VTreeview>
|
||||||
|
</VMenu>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user