From fb1237b1d392a1fcd86dc91fcfdb202d49504f35 Mon Sep 17 00:00:00 2001 From: wenjinbo <599483010@qq.com> Date: Thu, 18 Sep 2025 15:50:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=8A=9F=E8=83=BD,=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=88=90=E5=8A=9F/=E5=A4=B1=E8=B4=A5=20?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8F=90=E7=A4=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/datasets/components/DocUpload.vue | 65 +++++-- .../datasets/components/DocumentList.vue | 162 +++++++++++++++++- .../controller/DatasetDocController.java | 12 +- 3 files changed, 218 insertions(+), 21 deletions(-) diff --git a/chat-client/src/views/datasets/components/DocUpload.vue b/chat-client/src/views/datasets/components/DocUpload.vue index d9a0455..72827b3 100644 --- a/chat-client/src/views/datasets/components/DocUpload.vue +++ b/chat-client/src/views/datasets/components/DocUpload.vue @@ -2,7 +2,7 @@
- + @@ -12,7 +12,7 @@
-

选择要上传的文件

+

{{ props.replaceFileId ? '选择要替换的文件' : '选择要上传的文件' }}

支持多种文档格式,拖拽或点击选择文件

@@ -22,7 +22,8 @@ drag :auto-upload="false" :on-change="handleFileChange" - :file-list="uploadFiles" + :file-list="[]" + :show-file-list="false" :limit="10" accept=".txt,.md,.markdown,.mdx,.pdf,.html,.htm,.xlsx,.xls,.doc,.docx,.csv,.vtt,.properties" class="upload-area" @@ -281,7 +282,7 @@
-

确认上传

+

{{ props.replaceFileId ? '确认替换' : '确认上传' }}

使用自适应模式,系统将自动选择最佳解析策略

@@ -321,7 +322,7 @@ :loading="uploading" :disabled="!canUpload()" > - 开始上传 + {{ props.replaceFileId ? '开始替换' : '开始上传' }} 取消
@@ -343,19 +344,21 @@ import { Tools, Check } from '@element-plus/icons-vue' -import { uploadDocument } from '@/api/dataset' +import { uploadDocument, deleteDocument } from '@/api/dataset' // Props interface Props { datasetId: string visible: boolean parentId?: number + replaceFileId?: string } const props = withDefaults(defineProps(), { datasetId: '', visible: false, - parentId: undefined + parentId: undefined, + replaceFileId: undefined }) // Emits @@ -435,7 +438,7 @@ const getStep3Title = () => { switch (uploadForm.analysisStrategyType) { case 'custom': return '参数设置' case 'deep': return '处理进度' - default: return '确认上传' + default: return props.replaceFileId ? '确认替换' : '确认上传' } } @@ -473,6 +476,14 @@ const handleDragLeave = () => { const removeFile = (index: number) => { uploadFiles.value.splice(index, 1) + // 同步更新 el-upload 组件的内部文件列表 + if (uploadRef.value) { + uploadRef.value.clearFiles() + // 重新添加剩余文件到 el-upload 组件 + uploadFiles.value.forEach(file => { + uploadRef.value.handleStart(file.raw) + }) + } } const formatFileSize = (size?: number) => { @@ -548,18 +559,42 @@ const handleUpload = async () => { const loading = ElLoading.service({ lock: true, - text: '正在上传文件...', + text: props.replaceFileId ? '正在替换文件...' : '正在上传文件...', background: 'rgba(0, 0, 0, 0.7)' }) try { uploading.value = true + // 如果是文件替换,先删除旧文件 + if (props.replaceFileId) { + // 关闭当前loading,显示删除进度 + loading.close() + const deleteLoading = ElLoading.service({ + lock: true, + text: '正在删除旧文件...', + background: 'rgba(0, 0, 0, 0.7)' + }) + + await deleteDocument(parseInt(props.replaceFileId)) + deleteLoading.close() + + // 重新显示上传进度 + const uploadLoading = ElLoading.service({ + lock: true, + text: '正在上传新文件...', + background: 'rgba(0, 0, 0, 0.7)' + }) + // 更新loading引用 + loading.close = uploadLoading.close + } + // 构造请求数据,符合后端DocUploadReq结构 const requestData: any = { datasetId: props.datasetId, analysisStrategyType: uploadForm.analysisStrategyType, - parentId: props.parentId // 添加parentId参数,根目录时为undefined/null + parentId: props.parentId, // 添加parentId参数,根目录时为undefined/null + // 注意:删除 replaceFileId,因为我们已经手动删除了旧文件 } // 如果是自定义模式,添加解析策略 @@ -599,16 +634,18 @@ const handleUpload = async () => { } ElNotification({ - title: '上传成功', - message: `成功上传 ${uploadFiles.value.length} 个文件`, + title: props.replaceFileId ? '替换成功' : '上传成功', + message: props.replaceFileId + ? `成功替换 ${uploadFiles.value.length} 个文件` + : `成功上传 ${uploadFiles.value.length} 个文件`, type: 'success' }) emit('success') handleCancel() } catch (error) { - console.error('上传失败:', error) - ElMessage.error('上传失败,请重试') + console.error(props.replaceFileId ? '替换失败:' : '上传失败:', error) + //ElMessage.error(props.replaceFileId ? '替换失败,请重试' : '上传失败,请重试') } finally { uploading.value = false loading.close() diff --git a/chat-client/src/views/datasets/components/DocumentList.vue b/chat-client/src/views/datasets/components/DocumentList.vue index 8e0677a..2d5668d 100644 --- a/chat-client/src/views/datasets/components/DocumentList.vue +++ b/chat-client/src/views/datasets/components/DocumentList.vue @@ -139,7 +139,7 @@ -- - +