fix 重命名

This commit is contained in:
jxxghp
2023-08-26 19:58:36 +08:00
parent 3a9e85c821
commit e5f7467d5b
4 changed files with 95 additions and 18 deletions
+1
View File
@@ -893,6 +893,7 @@ export interface EndPoints {
delete: any delete: any
download: any download: any
image: any image: any
rename: any
} }
// 文件浏览项目 // 文件浏览项目
+1
View File
@@ -129,6 +129,7 @@ onBeforeMount(() => {
@loading="loadingChanged" @loading="loadingChanged"
@refreshed="refreshPending = false" @refreshed="refreshPending = false"
@filedeleted="refreshPending = true" @filedeleted="refreshPending = true"
@renamed="refreshPending = true"
/> />
</VCol> </VCol>
</VRow> </VRow>
+92 -18
View File
@@ -8,7 +8,7 @@ import type { EndPoints, FileItem } from '@/api/types'
import store from '@/store' import store from '@/store'
// 输入参数 // 输入参数
const props = defineProps({ const inProps = defineProps({
icons: Object, icons: Object,
storage: String, storage: String,
path: String, path: String,
@@ -18,13 +18,13 @@ const props = defineProps({
}) })
// 对外事件 // 对外事件
const emit = defineEmits(['loading', 'pathchanged', 'refreshed', 'filedeleted']) const emit = defineEmits(['loading', 'pathchanged', 'refreshed', 'filedeleted', 'renamed'])
// 确认框 // 确认框
const createConfirm = useConfirm() const createConfirm = useConfirm()
// axios实例 // axios实例
const axiosInstance = ref<Axios>(props.axios ?? axios) const axiosInstance = ref<Axios>(inProps.axios ?? axios)
// 内容列表 // 内容列表
const items = ref<FileItem[]>([]) const items = ref<FileItem[]>([])
@@ -32,8 +32,17 @@ const items = ref<FileItem[]>([])
// 过滤条件 // 过滤条件
const filter = ref('') const filter = ref('')
// 重命名弹窗
const renamePopper = ref(false)
// 新名称
const newName = ref('')
// 当前名称
const currentItem = ref<FileItem>()
// 存储空间类型 // 存储空间类型
const storage = ref(props.storage ?? '') const storage = ref(inProps.storage ?? '')
// 目录过滤 // 目录过滤
const dirs = computed(() => const dirs = computed(() =>
@@ -46,14 +55,14 @@ const files = computed(() =>
) )
// 是否目录 // 是否目录
const isDir = computed(() => props.path?.endsWith('/')) const isDir = computed(() => inProps.path?.endsWith('/'))
// 是否文件 // 是否文件
const isFile = computed(() => !isDir.value) const isFile = computed(() => !isDir.value)
// 是否为图片文件 // 是否为图片文件
const isImage = computed(() => { const isImage = computed(() => {
const ext = props.path?.split('.').pop()?.toLowerCase() const ext = inProps.path?.split('.').pop()?.toLowerCase()
return ['png', 'jpg', 'jpeg', 'gif', 'bmp'].includes(ext ?? '') return ['png', 'jpg', 'jpeg', 'gif', 'bmp'].includes(ext ?? '')
}) })
@@ -61,13 +70,13 @@ const isImage = computed(() => {
async function load() { async function load() {
emit('loading', true) emit('loading', true)
if (isDir.value) { if (isDir.value) {
const url = props.endpoints?.list.url const url = inProps.endpoints?.list.url
.replace(/{storage}/g, storage.value) .replace(/{storage}/g, storage.value)
.replace(/{path}/g, props.path) .replace(/{path}/g, inProps.path)
const config = { const config = {
url, url,
method: props.endpoints?.list.method || 'get', method: inProps.endpoints?.list.method || 'get',
} }
// 加载数据 // 加载数据
items.value = await axiosInstance.value.request(config) ?? [] items.value = await axiosInstance.value.request(config) ?? []
@@ -91,13 +100,13 @@ async function deleteItem(item: FileItem) {
if (confirmed) { if (confirmed) {
emit('loading', true) emit('loading', true)
const url = props.endpoints?.delete.url const url = inProps.endpoints?.delete.url
.replace(/{storage}/g, storage.value) .replace(/{storage}/g, storage.value)
.replace(/{path}/g, item.path) .replace(/{path}/g, item.path)
const config = { const config = {
url, url,
method: props.endpoints?.delete.method || 'post', method: inProps.endpoints?.delete.method || 'post',
} }
await axiosInstance.value.request(config) await axiosInstance.value.request(config)
@@ -118,7 +127,7 @@ function download(path: string) {
if (!path) if (!path)
return return
const token = store.state.auth.token const token = store.state.auth.token
const url_path = props.endpoints?.download.url const url_path = inProps.endpoints?.download.url
.replace(/{storage}/g, storage.value) .replace(/{storage}/g, storage.value)
.replace(/{path}/g, path) .replace(/{path}/g, path)
const url = `${import.meta.env.VITE_API_BASE_URL}${url_path.slice(1)}&token=${token}` const url = `${import.meta.env.VITE_API_BASE_URL}${url_path.slice(1)}&token=${token}`
@@ -131,7 +140,7 @@ function getImgLink(path: string) {
if (!path) if (!path)
return '' return ''
const token = store.state.auth.token const token = store.state.auth.token
const url_path = props.endpoints?.image.url const url_path = inProps.endpoints?.image.url
.replace(/{storage}/g, storage.value) .replace(/{storage}/g, storage.value)
.replace(/{path}/g, path) .replace(/{path}/g, path)
return `${import.meta.env.VITE_API_BASE_URL}${url_path.slice(1)}&token=${token}` return `${import.meta.env.VITE_API_BASE_URL}${url_path.slice(1)}&token=${token}`
@@ -142,9 +151,40 @@ function transfer(item: FileItem) {
// TODO 转移文件 // TODO 转移文件
} }
// 显示重命名弹窗
function showRenmae(item: FileItem) {
currentItem.value = item
newName.value = item.name
renamePopper.value = true
}
// 重命名
async function rename() {
emit('loading', true)
const url = inProps.endpoints?.rename.url
.replace(/{storage}/g, inProps.storage)
.replace(/{path}/g, currentItem.value?.path)
.replace(/{newname}/g, newName.value)
const config = {
url,
method: inProps.endpoints?.mkdir.method || 'post',
}
// 调API
await inProps.axios?.request(config)
renamePopper.value = false
newName.value = ''
emit('loading', false)
// 通知重新加载
emit('renamed')
}
// 监听path变化 // 监听path变化
watch( watch(
() => props.path, () => inProps.path,
async () => { async () => {
items.value = [] items.value = []
await load() await load()
@@ -153,9 +193,9 @@ watch(
// 监听refreshPending变化 // 监听refreshPending变化
watch( watch(
() => props.refreshpending, () => inProps.refreshpending,
async () => { async () => {
if (props.refreshpending) { if (inProps.refreshpending) {
await load() await load()
emit('refreshed') emit('refreshed')
} }
@@ -201,6 +241,9 @@ onMounted(() => {
</template> </template>
<VListItemTitle v-text="item.name" /> <VListItemTitle v-text="item.name" />
<template #append> <template #append>
<IconBtn @click.stop="showRenmae(item)">
<VIcon icon="mdi-rename" />
</IconBtn>
<IconBtn @click.stop="transfer(item)"> <IconBtn @click.stop="transfer(item)">
<VIcon icon="mdi-folder-arrow-right" /> <VIcon icon="mdi-folder-arrow-right" />
</IconBtn> </IconBtn>
@@ -220,13 +263,16 @@ onMounted(() => {
@click="changePath(item.path)" @click="changePath(item.path)"
> >
<template #prepend> <template #prepend>
<VIcon v-if="props.icons" :icon="props.icons[item.extension.toLowerCase()] || props.icons?.other" /> <VIcon v-if="inProps.icons" :icon="inProps.icons[item.extension.toLowerCase()] || inProps.icons?.other" />
</template> </template>
<VListItemTitle v-text="item.name" /> <VListItemTitle v-text="item.name" />
<VListItemSubtitle> {{ formatBytes(item.size) }}</VListItemSubtitle> <VListItemSubtitle> {{ formatBytes(item.size) }}</VListItemSubtitle>
<template #append> <template #append>
<IconBtn @click.stop="showRenmae(item)">
<VIcon icon="mdi-rename" />
</IconBtn>
<IconBtn @click.stop="transfer(item)"> <IconBtn @click.stop="transfer(item)">
<VIcon icon="mdi-folder-arrow-right" /> <VIcon icon="mdi-folder-arrow-right" />
</IconBtn> </IconBtn>
@@ -263,7 +309,7 @@ onMounted(() => {
class="me-2" class="me-2"
/> />
<VSpacer v-if="isFile" /> <VSpacer v-if="isFile" />
<VBtn v-if="isFile" @click="download(props.path || '')"> <VBtn v-if="isFile" @click="download(inProps.path || '')">
<VIcon>mdi-download</VIcon> <VIcon>mdi-download</VIcon>
</VBtn> </VBtn>
<VBtn v-if="!isFile" @click="load"> <VBtn v-if="!isFile" @click="load">
@@ -271,6 +317,34 @@ onMounted(() => {
</VBtn> </VBtn>
</VToolbar> </VToolbar>
</VCard> </VCard>
<VDialog
v-model="renamePopper"
max-width="600"
>
<template #activator="{ props }">
<IconBtn title="重命名" v-bind="props">
<VIcon icon="mdi-rename-outline" />
</IconBtn>
</template>
<VCard title="重命名">
<VCardText>
<VTextField v-model="newName" label="名称" />
</VCardText>
<VCardActions>
<div class="flex-grow-1" />
<VBtn depressed @click="renamePopper = false">
取消
</VBtn>
<VBtn
:disabled="!newName"
depressed
@click="rename"
>
重命名
</VBtn>
</VCardActions>
</VCard>
</VDialog>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
+1
View File
@@ -9,6 +9,7 @@ const endpoints = {
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' }, image: { url: '/filebrowser/image?path={path}', method: 'get' },
rename: { url: '/filebrowser/rename?path={path}&new_name={newname}', method: 'get' },
} }
// 读取下载目录 // 读取下载目录