Phase 2.7.3完成:文件上传功能实现
功能: - Tauri dialog API集成(文件选择对话框) - upload_file命令完整实现(文件复制 + 数据库注册) - 上传按钮UI(带loading状态) - 上传完成后自动刷新文件树 技术: - 添加uuid依赖(UUID v4生成) - Rust: std::fs文件复制 + rusqlite数据库注册 - Vue: @tauri-apps/api/dialog集成 - Vite: 修复dialog API外部化配置 状态:Phase 2完成100%
This commit is contained in:
@@ -4,7 +4,8 @@ import { useRouter } from 'vue-router'
|
||||
import { useAppStore } from '../stores/app'
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Folder, Document } from '@element-plus/icons-vue'
|
||||
import { Folder, Document, Upload } from '@element-plus/icons-vue'
|
||||
import { open } from '@tauri-apps/api/dialog'
|
||||
|
||||
const router = useRouter()
|
||||
const appStore = useAppStore()
|
||||
@@ -17,6 +18,8 @@ const treeProps = {
|
||||
}
|
||||
|
||||
const currentTreeType = ref('demo_library_zh')
|
||||
const uploading = ref(false)
|
||||
const uploadProgress = ref(0)
|
||||
|
||||
const navigateTo = (path) => {
|
||||
router.push(path)
|
||||
@@ -58,6 +61,52 @@ const handleNodeClick = async (data) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleUpload = async () => {
|
||||
try {
|
||||
const selected = await open({
|
||||
multiple: false,
|
||||
filters: [{
|
||||
name: 'All Files',
|
||||
extensions: ['*']
|
||||
}]
|
||||
})
|
||||
|
||||
if (!selected) {
|
||||
return
|
||||
}
|
||||
|
||||
uploading.value = true
|
||||
uploadProgress.value = 0
|
||||
|
||||
const sourcePath = selected
|
||||
const fileName = sourcePath.split('/').pop()
|
||||
const targetPath = `uploads/${fileName}`
|
||||
|
||||
ElMessage.info(`Uploading ${fileName}...`)
|
||||
|
||||
const result = await invoke('upload_file', {
|
||||
userId: 'demo',
|
||||
sourcePath: sourcePath,
|
||||
targetPath: targetPath,
|
||||
treeType: currentTreeType.value
|
||||
})
|
||||
|
||||
uploadProgress.value = 100
|
||||
|
||||
if (result.success) {
|
||||
ElMessage.success(result.message)
|
||||
await loadTree()
|
||||
} else {
|
||||
ElMessage.error(result.message)
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage.error(`Upload failed: ${error}`)
|
||||
} finally {
|
||||
uploading.value = false
|
||||
uploadProgress.value = 0
|
||||
}
|
||||
}
|
||||
|
||||
watch(currentTreeType, () => {
|
||||
loadTree()
|
||||
})
|
||||
@@ -76,10 +125,21 @@ onMounted(async () => {
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>File Browser</span>
|
||||
<el-radio-group v-model="appStore.currentTreeType" size="small">
|
||||
<el-radio-button label="demo_library_zh">中文版</el-radio-button>
|
||||
<el-radio-button label="demo_library_en">English</el-radio-button>
|
||||
</el-radio-group>
|
||||
<div class="header-actions">
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
:icon="Upload"
|
||||
:loading="uploading"
|
||||
@click="handleUpload"
|
||||
>
|
||||
Upload File
|
||||
</el-button>
|
||||
<el-radio-group v-model="appStore.currentTreeType" size="small">
|
||||
<el-radio-button label="demo_library_zh">中文版</el-radio-button>
|
||||
<el-radio-button label="demo_library_en">English</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div class="tree-container">
|
||||
@@ -178,6 +238,12 @@ onMounted(async () => {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.tree-container {
|
||||
height: calc(100% - 60px);
|
||||
overflow-y: auto;
|
||||
|
||||
@@ -5,7 +5,7 @@ export default defineConfig({
|
||||
plugins: [vue()],
|
||||
build: {
|
||||
rolldownOptions: {
|
||||
external: ['@tauri-apps/api', '@tauri-apps/api/tauri']
|
||||
external: ['@tauri-apps/api', '@tauri-apps/api/tauri', '@tauri-apps/api/dialog']
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user