refactor: Update FileBrowser.vue and FileBrowserView.vue to support multiple storage configurations

This commit is contained in:
jxxghp
2024-09-11 08:15:48 +08:00
parent 83e199c1ea
commit f795481895
2 changed files with 21 additions and 9 deletions

View File

@@ -2,11 +2,11 @@
import type { Axios } from 'axios'
import FileList from './filebrowser/FileList.vue'
import FileToolbar from './filebrowser/FileToolbar.vue'
import type { EndPoints, FileItem } from '@/api/types'
import type { EndPoints, FileItem, StorageConf } from '@/api/types'
// 输入参数
const props = defineProps({
storages: String,
storages: Array as PropType<StorageConf[]>,
tree: Boolean,
endpoints: Object as PropType<EndPoints>,
axios: {
@@ -83,7 +83,7 @@ const sort = ref('name')
// 计算属性
const storagesArray = computed(() => {
const storageCodes = props.storages?.split(',')
const storageCodes = props.storages?.map(item => item.type)
return availableStorages.filter(item => storageCodes?.includes(item.code))
})

View File

@@ -1,8 +1,7 @@
<script lang="ts" setup>
import api from '@/api'
import { FileItem, TransferDirectoryConf } from '@/api/types'
import { FileItem, StorageConf, TransferDirectoryConf } from '@/api/types'
import FileBrowser from '@/components/FileBrowser.vue'
import store from '@/store'
const endpoints = {
list: {
@@ -31,10 +30,19 @@ const endpoints = {
},
}
const user_level = store.state.auth.level
// 所有存储
const storages = ref<StorageConf[]>([])
// 用户存储
const userStorage = user_level > 1 ? 'local,alipan,u115' : 'local'
// 查询存储
async function loadStorages() {
try {
const result: { [key: string]: any } = await api.get('system/setting/Storages')
storages.value = result.data?.value ?? []
} catch (error) {
console.log(error)
}
}
// 当前文件项
const operItem = ref<FileItem>({
@@ -149,12 +157,16 @@ function pathChanged(item: FileItem) {
// 加载初始目录
onBeforeMount(loadDownloadDirectories)
onMounted(() => {
loadStorages()
})
</script>
<template>
<div>
<FileBrowser
:storages="userStorage"
:storages="storages"
:tree="false"
:itemstack="itemstack"
:endpoints="endpoints"