feat: add zip download for folders in file manager

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Van Horn
2026-06-03 01:27:35 -07:00
parent 6c81c2a32f
commit 9a2ca526a7
8 changed files with 184 additions and 4 deletions
+10
View File
@@ -297,6 +297,15 @@ async function handleDownload(path: string) {
toast.success('下载中')
}
async function handleDownloadZip(path: string) {
const url = api.files.downloadZip(path)
const a = document.createElement('a')
a.href = url
a.download = (path.split('/').pop() || 'archive') + '.zip'
a.click()
toast.success('下载中')
}
async function handleCopyFile(path: string) {
try {
const parts = path.split('/')
@@ -466,6 +475,7 @@ onUnmounted(() => {
@delete="(path: string) => dialogsRef?.openDelete(path)"
@create="(parent: string) => dialogsRef?.openCreate(parent)"
@download="handleDownload"
@download-zip="handleDownloadZip"
@move="handleMove"
@rename="(path: string) => dialogsRef?.openRename(path)"
@duplicate="handleCopyFile"
@@ -19,6 +19,7 @@ const emit = defineEmits<{
select: [node: FileNode]
delete: [path: string]
download: [path: string]
downloadZip: [path: string]
move: [oldPath: string, newPath: string]
rename: [path: string]
duplicate: [path: string]
@@ -158,6 +159,7 @@ function handleFilesUpload(e: Event) {
@delete="p => emit('delete', p)"
@create="p => emit('create', p)"
@download-file="p => emit('download', p)"
@download-zip="p => emit('downloadZip', p)"
@move="(o, n) => emit('move', o, n)"
@rename="p => emit('rename', p)"
@duplicate="p => emit('duplicate', p)" />
+16 -1
View File
@@ -267,6 +267,21 @@ async function handleDownload(path: string) {
}
}
async function handleDownloadZip(path: string) {
try {
const url = api.files.downloadZip(path)
const a = document.createElement('a')
a.href = url
a.download = (path.split('/').pop() || 'archive') + '.zip'
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
toast.success('已发起下载')
} catch (error: any) {
toast.error('下载出错: ' + (error.message || '未知错误'))
}
}
async function handleCopyFile(path: string) {
console.log('Copy file requested:', path)
try {
@@ -320,7 +335,7 @@ onMounted(loadTree)
</div>
<FileTreeNode v-for="node in fileTree" :key="node.path" :node="node" :expanded-dirs="expandedDirs"
:selected-path="selectedFile || selectedDir" @select="handleSelect" @delete="confirmDeleteFile"
@download-file="handleDownload" @duplicate="handleCopyFile" />
@download-file="handleDownload" @download-zip="handleDownloadZip" @duplicate="handleCopyFile" />
</div>
</div>