fix: 文件管理初始化两次的bug

This commit is contained in:
thofx
2023-12-28 20:05:50 +08:00
parent b200ed242d
commit 6904fc7da3
2 changed files with 110 additions and 69 deletions
+52 -48
View File
@@ -1,10 +1,10 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { Axios } from 'axios' import type { Axios } from 'axios'
import axios from 'axios' import axios from 'axios'
import List from './filebrowser/List.vue'
import Toolbar from './filebrowser/Toolbar.vue' import Toolbar from './filebrowser/Toolbar.vue'
import Tree from './filebrowser/Tree.vue' import Tree from './filebrowser/Tree.vue'
import List from './filebrowser/List.vue'
import type { EndPoints } from '@/api/types' import type { EndPoints } from '@/api/types'
// 输入参数 // 输入参数
@@ -70,10 +70,12 @@ const storagesArray = computed(() => {
// 方法 // 方法
function loadingChanged(loading: number) { function loadingChanged(loading: number) {
if (loading) if (loading) {
loading++ loading++
else if (loading > 0) }
else if (loading > 0) {
loading-- loading--
}
} }
function storageChanged(storage: string) { function storageChanged(storage: string) {
@@ -92,56 +94,58 @@ function sortChanged(s: string) {
} }
// 初始化 // 初始化
onBeforeMount(() => { onMounted(() => {
activeStorage.value = props.storage ?? 'local' activeStorage.value = props.storage ?? 'local'
axiosInstance.value = props.axios ?? axios.create(props.axiosconfig) axiosInstance.value = props.axios ?? axios.create(props.axiosconfig)
}) })
</script> </script>
<template> <template>
<VCard class="mx-auto" :loading="loading > 0"> <VCard class="mx-auto" :loading="loading > 0 || !path">
<Toolbar <div v-if="path">
:path="props.path" <Toolbar
:storages="storagesArray" :path="path"
:storage="activeStorage" :storages="storagesArray"
:endpoints="props.endpoints" :storage="activeStorage"
:axios="axiosInstance" :endpoints="endpoints"
@storagechanged="storageChanged" :axios="axiosInstance"
@pathchanged="pathChanged" @storagechanged="storageChanged"
@foldercreated="refreshPending = true" @pathchanged="pathChanged"
@sortchanged="sortChanged" @foldercreated="refreshPending = true"
/> @sortchanged="sortChanged"
<VRow no-gutters> />
<VCol v-if="tree" sm="auto" class="d-none d-md-block"> <VRow no-gutters>
<Tree <VCol v-if="tree" sm="auto" class="d-none d-md-block">
:path="props.path" <Tree
:storage="activeStorage" :path="path"
:icons="fileIcons" :storage="activeStorage"
:endpoints="endpoints" :icons="fileIcons"
:axios="axiosInstance" :endpoints="endpoints"
:refreshpending="refreshPending" :axios="axiosInstance"
@pathchanged="pathChanged" :refreshpending="refreshPending"
@loading="loadingChanged" @pathchanged="pathChanged"
@refreshed="refreshPending = false" @loading="loadingChanged"
/> @refreshed="refreshPending = false"
</VCol> />
<VDivider v-if="tree" vertical /> </VCol>
<VCol> <VDivider v-if="tree" vertical />
<List <VCol>
:path="props.path" <List
:storage="activeStorage" :path="path"
:icons="fileIcons" :storage="activeStorage"
:endpoints="endpoints" :icons="fileIcons"
:axios="axiosInstance" :endpoints="endpoints"
:refreshpending="refreshPending" :axios="axiosInstance"
:sort="sort" :refreshpending="refreshPending"
@pathchanged="pathChanged" :sort="sort"
@loading="loadingChanged" @pathchanged="pathChanged"
@refreshed="refreshPending = false" @loading="loadingChanged"
@filedeleted="refreshPending = true" @refreshed="refreshPending = false"
@renamed="refreshPending = true" @filedeleted="refreshPending = true"
/> @renamed="refreshPending = true"
</VCol> />
</VRow> </VCol>
</VRow>
</div>
</VCard> </VCard>
</template> </template>
+58 -21
View File
@@ -3,42 +3,79 @@ import api from '@/api'
import FileBrowser from '@/components/FileBrowser.vue' import FileBrowser from '@/components/FileBrowser.vue'
const endpoints = { const endpoints = {
list: { url: '/filebrowser/list?path={path}&sort={sort}', method: 'get' }, list: {
mkdir: { url: '/filebrowser/mkdir?path={path}', method: 'get' }, url: '/filebrowser/list?path={path}&sort={sort}',
delete: { url: '/filebrowser/delete?path={path}', method: 'get' }, method: 'get',
download: { url: '/filebrowser/download?path={path}', method: 'get' }, },
image: { url: '/filebrowser/image?path={path}', method: 'get' }, mkdir: {
rename: { url: '/filebrowser/rename?path={path}&new_name={newname}', method: 'get' }, url: '/filebrowser/mkdir?path={path}',
method: 'get',
},
delete: {
url: '/filebrowser/delete?path={path}',
method: 'get',
},
download: {
url: '/filebrowser/download?path={path}',
method: 'get',
},
image: {
url: '/filebrowser/image?path={path}',
method: 'get',
},
rename: {
url: '/filebrowser/rename?path={path}&new_name={newname}',
method: 'get',
},
} }
// 读取下载目录 // 读取下载目录
const path = ref('/') const path: Ref<string | undefined> = ref()
// 调用API,加载当前系统环境设置 // 调用API,加载当前系统环境设置
async function loadSystemSettings() { function loadSystemSettings(): Promise<string> {
try { return new Promise((resolve, reject) => {
const result: { [key: string]: any } = await api.get('system/env') api
if (result.success) .get('system/env')
path.value = result.data?.DOWNLOAD_PATH || '/' .then((result: any) => {
if (path.value && !path.value.endsWith('/')) let path = '/'
path.value += '/' if (result.success)
} path = result.data?.DOWNLOAD_PATH || '/'
catch (error) {
console.log(error) if (!path.endsWith('/'))
} path += '/'
resolve(path)
})
.catch(error => reject(error))
})
} }
function pathChanged(_path: string) { function pathChanged(_path: string) {
path.value = _path path.value = _path
} }
onBeforeMount(async () => { onMounted(() => {
await loadSystemSettings() loadSystemSettings()
.then((res) => {
path.value = res
})
.catch((error) => {
console.error(error)
path.value = '/'
})
}) })
</script> </script>
<template> <template>
<div> <div>
<FileBrowser storages="local" :tree="false" :path="path" :endpoints="endpoints" :axios="api" @pathchanged="pathChanged" /> <FileBrowser
storages="local"
:tree="false"
:path="path"
:endpoints="endpoints"
:axios="api"
@pathchanged="pathChanged"
/>
</div> </div>
</template> </template>