@@ -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 @@
@@ -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 @@
--
-
+