mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 23:56:42 +08:00
feat 图片显示&文件下载
This commit is contained in:
+3
-3
@@ -77,9 +77,9 @@ async function loadSystemSettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 页面加载时,加载当前用户数据
|
// 页面加载时,加载当前用户数据
|
||||||
onMounted(() => {
|
onBeforeMount(async () => {
|
||||||
loadAccountInfo()
|
await loadAccountInfo()
|
||||||
loadSystemSettings()
|
await loadSystemSettings()
|
||||||
startSSEMessager()
|
startSSEMessager()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -892,6 +892,7 @@ export interface EndPoints {
|
|||||||
mkdir: any
|
mkdir: any
|
||||||
delete: any
|
delete: any
|
||||||
download: any
|
download: any
|
||||||
|
image: any
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文件浏览项目
|
// 文件浏览项目
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ const fileIcons = {
|
|||||||
htm: 'mdi-language-html5',
|
htm: 'mdi-language-html5',
|
||||||
html: 'mdi-language-html5',
|
html: 'mdi-language-html5',
|
||||||
js: 'mdi-nodejs',
|
js: 'mdi-nodejs',
|
||||||
json: 'mdi-json',
|
json: 'mdi-file-document-outline',
|
||||||
md: 'mdi-markdown',
|
md: 'mdi-language-markdown-outline',
|
||||||
pdf: 'mdi-file-pdf',
|
pdf: 'mdi-file-pdf',
|
||||||
png: 'mdi-file-image',
|
png: 'mdi-file-image',
|
||||||
jpg: 'mdi-file-image',
|
jpg: 'mdi-file-image',
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useConfirm } from 'vuetify-use-dialog'
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { formatBytes } from '@core/utils/formatters'
|
import { formatBytes } from '@core/utils/formatters'
|
||||||
import type { EndPoints, FileItem } from '@/api/types'
|
import type { EndPoints, FileItem } from '@/api/types'
|
||||||
|
import store from '@/store'
|
||||||
|
|
||||||
// 输入参数
|
// 输入参数
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -50,6 +51,12 @@ const isDir = computed(() => props.path?.endsWith('/'))
|
|||||||
// 是否文件
|
// 是否文件
|
||||||
const isFile = computed(() => !isDir.value)
|
const isFile = computed(() => !isDir.value)
|
||||||
|
|
||||||
|
// 是否为图片文件
|
||||||
|
const isImage = computed(() => {
|
||||||
|
const ext = props.path?.split('.').pop()?.toLowerCase()
|
||||||
|
return ['png', 'jpg', 'jpeg', 'gif', 'bmp'].includes(ext ?? '')
|
||||||
|
})
|
||||||
|
|
||||||
// 调API加载内容
|
// 调API加载内容
|
||||||
async function load() {
|
async function load() {
|
||||||
emit('loading', true)
|
emit('loading', true)
|
||||||
@@ -110,13 +117,26 @@ function changePath(_path: string) {
|
|||||||
function download(path: string) {
|
function download(path: string) {
|
||||||
if (!path)
|
if (!path)
|
||||||
return
|
return
|
||||||
const url = props.endpoints?.download.url
|
const token = store.state.auth.token
|
||||||
|
const url_path = props.endpoints?.download.url
|
||||||
.replace(/{storage}/g, storage.value)
|
.replace(/{storage}/g, storage.value)
|
||||||
.replace(/{path}/g, path)
|
.replace(/{path}/g, path)
|
||||||
// FIXME 下载文件
|
const url = `${import.meta.env.VITE_API_BASE_URL}${url_path.slice(1)}&token=${token}`
|
||||||
|
// 下载文件
|
||||||
window.open(url, '_blank')
|
window.open(url, '_blank')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 显示图片
|
||||||
|
function getImgLink(path: string) {
|
||||||
|
if (!path)
|
||||||
|
return ''
|
||||||
|
const token = store.state.auth.token
|
||||||
|
const url_path = props.endpoints?.image.url
|
||||||
|
.replace(/{storage}/g, storage.value)
|
||||||
|
.replace(/{path}/g, path)
|
||||||
|
return `${import.meta.env.VITE_API_BASE_URL}${url_path.slice(1)}&token=${token}`
|
||||||
|
}
|
||||||
|
|
||||||
// 转移文件
|
// 转移文件
|
||||||
function transfer(item: FileItem) {
|
function transfer(item: FileItem) {
|
||||||
// TODO 转移文件
|
// TODO 转移文件
|
||||||
@@ -156,10 +176,16 @@ onMounted(() => {
|
|||||||
选择目录或文件
|
选择目录或文件
|
||||||
</VCardText>
|
</VCardText>
|
||||||
<VCardText
|
<VCardText
|
||||||
v-else-if="isFile"
|
v-else-if="isFile && !isImage"
|
||||||
class="grow d-flex justify-center align-center"
|
class="grow d-flex justify-center align-center"
|
||||||
>
|
>
|
||||||
文件: {{ path }}
|
文件: {{ path }}<br>
|
||||||
|
</VCardText>
|
||||||
|
<VCardText
|
||||||
|
v-else-if="isFile && isImage"
|
||||||
|
class="grow d-flex justify-center align-center"
|
||||||
|
>
|
||||||
|
<VImg :src="getImgLink(path)" cover max-width="100%" max-height="100%" />
|
||||||
</VCardText>
|
</VCardText>
|
||||||
<VCardText v-else-if="dirs.length || files.length" class="grow">
|
<VCardText v-else-if="dirs.length || files.length" class="grow">
|
||||||
<VList v-if="dirs.length" subheader max-height="300">
|
<VList v-if="dirs.length" subheader max-height="300">
|
||||||
|
|||||||
@@ -8,16 +8,20 @@ const endpoints = {
|
|||||||
mkdir: { url: '/filebrowser/mkdir?path={path}', method: 'get' },
|
mkdir: { url: '/filebrowser/mkdir?path={path}', method: 'get' },
|
||||||
delete: { url: '/filebrowser/delete?path={path}', method: 'get' },
|
delete: { url: '/filebrowser/delete?path={path}', method: 'get' },
|
||||||
download: { url: '/filebrowser/download?path={path}', method: 'get' },
|
download: { url: '/filebrowser/download?path={path}', method: 'get' },
|
||||||
|
image: { url: '/filebrowser/image?path={path}', method: 'get' },
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取下载目录
|
// 读取下载目录
|
||||||
const systemEnv: Setting = inject('systemEnv') ?? {
|
const systemEnv: Setting = inject('systemEnv') ?? {
|
||||||
DOWNLOAD_PATH: '/',
|
DOWNLOAD_PATH: '/',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (systemEnv?.DOWNLOAD_PATH && !systemEnv.DOWNLOAD_PATH?.endsWith('/'))
|
||||||
|
systemEnv.DOWNLOAD_PATH += '/'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<FileBrowser storages="local" :tree="false" :path="systemEnv.DOWNLOAD_PATH" :endpoints="endpoints" :axios="api" />
|
<FileBrowser storages="local" :tree="false" :path="systemEnv?.DOWNLOAD_PATH" :endpoints="endpoints" :axios="api" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user