mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-05-21 08:10:16 +08:00
style: Update FileBrowserView.vue to include storage property in operItem and itemstack
This commit is contained in:
@@ -745,6 +745,8 @@ export interface EndPoints {
|
||||
|
||||
// 文件浏览项目
|
||||
export interface FileItem {
|
||||
// 存储
|
||||
storage: string
|
||||
// 类型 dir/file
|
||||
type: string
|
||||
// 文件名
|
||||
|
||||
@@ -3,10 +3,6 @@ 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 api from '@/api'
|
||||
import AliyunAuthDialog from './dialog/AliyunAuthDialog.vue'
|
||||
import U115AuthDialog from './dialog/U115AuthDialog.vue'
|
||||
import { isNullOrEmptyObject } from '@/@core/utils'
|
||||
|
||||
// 输入参数
|
||||
const props = defineProps({
|
||||
@@ -22,7 +18,10 @@ const props = defineProps({
|
||||
type: Object as PropType<FileItem>,
|
||||
required: true,
|
||||
},
|
||||
itemstack: Array as PropType<FileItem[]>,
|
||||
itemstack: {
|
||||
type: Array as PropType<FileItem[]>,
|
||||
default: () => [],
|
||||
},
|
||||
})
|
||||
|
||||
// 对外事件
|
||||
@@ -36,7 +35,7 @@ const availableStorages = [
|
||||
},
|
||||
{
|
||||
name: '阿里云盘',
|
||||
code: 'aliyun',
|
||||
code: 'alipan',
|
||||
icon: 'mdi-cloud-outline',
|
||||
},
|
||||
{
|
||||
@@ -44,6 +43,11 @@ const availableStorages = [
|
||||
code: 'u115',
|
||||
icon: 'mdi-cloud-outline',
|
||||
},
|
||||
{
|
||||
name: 'Rclone网盘',
|
||||
code: 'rclone',
|
||||
icon: 'mdi-cloud-outline',
|
||||
},
|
||||
]
|
||||
|
||||
const fileIcons = {
|
||||
@@ -76,14 +80,6 @@ const activeStorage = ref('local')
|
||||
const refreshPending = ref(false)
|
||||
// 排序
|
||||
const sort = ref('name')
|
||||
// 阿里云盘认证对话框
|
||||
const aliyunAuthDialog = ref(false)
|
||||
// 阿里云盘用户信息
|
||||
const aliyunUserInfo = ref<{ [key: string]: any }>({})
|
||||
// 115网盘认证对话框
|
||||
const u115AuthDialog = ref(false)
|
||||
// 115网盘用户信息
|
||||
const u115UserInfo = ref<{ [key: string]: any }>({})
|
||||
|
||||
// 计算属性
|
||||
const storagesArray = computed(() => {
|
||||
@@ -97,45 +93,8 @@ function loadingChanged(loading: number) {
|
||||
else if (loading > 0) loading--
|
||||
}
|
||||
|
||||
// 查询阿里云
|
||||
async function loadAliyunUserInfo() {
|
||||
try {
|
||||
const result: { [key: string]: any } = await api.get('aliyun/userinfo')
|
||||
if (result.success) {
|
||||
aliyunUserInfo.value = result
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
|
||||
// 查询115
|
||||
async function loadU115UserInfo() {
|
||||
try {
|
||||
const result: { [key: string]: any } = await api.get('u115/storage')
|
||||
if (result.success) {
|
||||
u115UserInfo.value = result
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
|
||||
// 存储切换
|
||||
async function storageChanged(storage: string) {
|
||||
if (storage == 'aliyun') {
|
||||
await loadAliyunUserInfo()
|
||||
if (isNullOrEmptyObject(aliyunUserInfo.value)) {
|
||||
aliyunAuthDialog.value = true
|
||||
return
|
||||
}
|
||||
} else if (storage == 'u115') {
|
||||
await loadU115UserInfo()
|
||||
if (isNullOrEmptyObject(u115UserInfo.value)) {
|
||||
u115AuthDialog.value = true
|
||||
return
|
||||
}
|
||||
}
|
||||
activeStorage.value = storage
|
||||
emit('pathchanged', { path: '/', fileid: 'root' })
|
||||
}
|
||||
@@ -150,18 +109,6 @@ function sortChanged(s: string) {
|
||||
sort.value = s
|
||||
refreshPending.value = true
|
||||
}
|
||||
|
||||
// aliyun认证完成
|
||||
function aliyunAuthDone() {
|
||||
aliyunAuthDialog.value = false
|
||||
activeStorage.value = 'aliyun'
|
||||
}
|
||||
|
||||
// u115认证完成
|
||||
function u115AuthDone() {
|
||||
u115AuthDialog.value = false
|
||||
activeStorage.value = 'u115'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -195,11 +142,4 @@ function u115AuthDone() {
|
||||
/>
|
||||
</div>
|
||||
</VCard>
|
||||
<AliyunAuthDialog
|
||||
v-if="aliyunAuthDialog"
|
||||
v-model="aliyunAuthDialog"
|
||||
@close="aliyunAuthDialog = false"
|
||||
@done="aliyunAuthDone"
|
||||
/>
|
||||
<U115AuthDialog v-if="u115AuthDialog" v-model="u115AuthDialog" @close="u115AuthDialog = false" @done="u115AuthDone" />
|
||||
</template>
|
||||
|
||||
@@ -139,9 +139,7 @@ async function list_files() {
|
||||
emit('loading', true)
|
||||
|
||||
// 参数
|
||||
const url = inProps.endpoints?.list.url
|
||||
.replace(/{storage}/g, inProps.storage)
|
||||
.replace(/{sort}/g, inProps.sort || 'name')
|
||||
const url = inProps.endpoints?.list.url.replace(/{sort}/g, inProps.sort || 'name')
|
||||
|
||||
const config: AxiosRequestConfig<FileItem> = {
|
||||
url,
|
||||
@@ -169,7 +167,7 @@ async function deleteItem(item: FileItem, confirm: boolean = true) {
|
||||
emit('loading', true)
|
||||
|
||||
// 请求API
|
||||
const url = inProps.endpoints?.delete.url.replace(/{storage}/g, inProps.storage)
|
||||
const url = inProps.endpoints?.delete.url
|
||||
const config: AxiosRequestConfig<FileItem> = {
|
||||
url,
|
||||
method: inProps.endpoints?.delete.method || 'post',
|
||||
@@ -234,7 +232,7 @@ function listItemClick(item: FileItem) {
|
||||
|
||||
// 新窗口中下载文件
|
||||
async function download(item: FileItem) {
|
||||
const url = inProps.endpoints?.download.url.replace(/{storage}/g, inProps.storage)
|
||||
const url = inProps.endpoints?.download.url
|
||||
const filterEntries = Object.entries(item).filter(([key, value]) => !['children', 'thumbnail'].includes(key) && value)
|
||||
const queryParams = filterEntries.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&')
|
||||
window.open(
|
||||
@@ -245,7 +243,7 @@ async function download(item: FileItem) {
|
||||
|
||||
// 获取图片地址
|
||||
function getImgLink(item: FileItem) {
|
||||
let url = inProps.endpoints?.image.url.replace(/{storage}/g, inProps.storage)
|
||||
let url = inProps.endpoints?.image.url
|
||||
const filterEntries = Object.entries(item).filter(([key, value]) => !['children', 'thumbnail'].includes(key) && value)
|
||||
const queryParams = filterEntries.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&')
|
||||
return `${import.meta.env.VITE_API_BASE_URL}${url.slice(1)}?${queryParams}&token=${store.state.auth.token}`
|
||||
@@ -300,9 +298,7 @@ async function rename() {
|
||||
}
|
||||
|
||||
// 调API
|
||||
let url = inProps.endpoints?.rename.url
|
||||
.replace(/{storage}/g, inProps.storage)
|
||||
.replace(/{newname}/g, encodeURIComponent(newName.value))
|
||||
let url = inProps.endpoints?.rename.url.replace(/{newname}/g, encodeURIComponent(newName.value))
|
||||
if (renameAll.value) {
|
||||
url += '&recursive=true'
|
||||
}
|
||||
|
||||
@@ -88,9 +88,7 @@ function goUp() {
|
||||
// 创建目录
|
||||
async function mkdir() {
|
||||
emit('loading', true)
|
||||
const url = inProps.endpoints?.mkdir.url
|
||||
.replace(/{storage}/g, inProps.storage)
|
||||
.replace(/{name}/g, newFolderName.value)
|
||||
const url = inProps.endpoints?.mkdir.url.replace(/{name}/g, newFolderName.value)
|
||||
|
||||
const config: AxiosRequestConfig<FileItem> = {
|
||||
url,
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
<script lang="ts" setup>
|
||||
import api from '@/api'
|
||||
import { FileItem, MediaDirectory } from '@/api/types'
|
||||
import { FileItem, TransferDirectoryConf } from '@/api/types'
|
||||
import FileBrowser from '@/components/FileBrowser.vue'
|
||||
import store from '@/store'
|
||||
|
||||
const endpoints = {
|
||||
list: {
|
||||
url: '/{storage}/list?sort={sort}',
|
||||
url: '/storage/list?sort={sort}',
|
||||
method: 'post',
|
||||
},
|
||||
mkdir: {
|
||||
url: '/{storage}/mkdir?name={name}',
|
||||
url: '/storage/mkdir?name={name}',
|
||||
method: 'post',
|
||||
},
|
||||
delete: {
|
||||
url: '/{storage}/delete',
|
||||
url: '/storage/delete',
|
||||
method: 'post',
|
||||
},
|
||||
download: {
|
||||
url: '/{storage}/download',
|
||||
method: 'get',
|
||||
url: '/storage/download',
|
||||
method: 'post',
|
||||
},
|
||||
image: {
|
||||
url: '/{storage}/image',
|
||||
method: 'get',
|
||||
url: '/storage/image',
|
||||
method: 'post',
|
||||
},
|
||||
rename: {
|
||||
url: '/{storage}/rename?new_name={newname}',
|
||||
url: '/storage/rename?new_name={newname}',
|
||||
method: 'post',
|
||||
},
|
||||
}
|
||||
@@ -38,6 +38,7 @@ const userStorage = user_level > 1 ? 'local,aliyun,u115' : 'local'
|
||||
|
||||
// 当前文件项
|
||||
const operItem = ref<FileItem>({
|
||||
storage: 'local',
|
||||
type: 'dir',
|
||||
name: '/',
|
||||
path: '/',
|
||||
@@ -47,6 +48,7 @@ const operItem = ref<FileItem>({
|
||||
// fileid的堆栈
|
||||
const itemstack = ref<FileItem[]>([
|
||||
{
|
||||
storage: 'local',
|
||||
type: 'dir',
|
||||
name: '/',
|
||||
path: '/',
|
||||
@@ -55,7 +57,7 @@ const itemstack = ref<FileItem[]>([
|
||||
])
|
||||
|
||||
// 下载目录列表
|
||||
const downloadDirectories = ref<MediaDirectory[]>([])
|
||||
const downloadDirectories = ref<TransferDirectoryConf[]>([])
|
||||
|
||||
// 计算公共路径
|
||||
function findCommonPath(paths: string[]): string {
|
||||
@@ -94,12 +96,13 @@ function findCommonPath(paths: string[]): string {
|
||||
// 查询下载目录
|
||||
async function loadDownloadDirectories() {
|
||||
try {
|
||||
const result: { [key: string]: any } = await api.get('system/setting/DownloadDirectories')
|
||||
const result: { [key: string]: any } = await api.get('system/setting/Directories')
|
||||
if (result.success && result.data?.value) {
|
||||
downloadDirectories.value = result.data.value
|
||||
const path = findCommonPath(downloadDirectories.value.map(item => item.path) as string[])
|
||||
const path = findCommonPath(downloadDirectories.value.map(item => item.download_path) as string[])
|
||||
const name = path.split('/').filter(Boolean).pop() ?? ''
|
||||
operItem.value = {
|
||||
storage: 'local',
|
||||
type: 'dir',
|
||||
name: name,
|
||||
path: path,
|
||||
@@ -109,6 +112,7 @@ async function loadDownloadDirectories() {
|
||||
paths.map((name, index) => {
|
||||
const path = '/' + paths.slice(0, index + 1).join('/') + '/'
|
||||
itemstack.value.push({
|
||||
storage: 'local',
|
||||
type: 'dir',
|
||||
name: name,
|
||||
path: path,
|
||||
|
||||
Reference in New Issue
Block a user