style: Update FileBrowserView.vue to include storage property in operItem and itemstack

This commit is contained in:
jxxghp
2024-07-26 22:05:01 +08:00
parent e92a74a088
commit f043447e4f
5 changed files with 34 additions and 94 deletions

View File

@@ -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>

View File

@@ -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'
}

View File

@@ -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,