diff --git a/frontend/src/pages/KnowledgeBase/components/AddDataDialog.tsx b/frontend/src/pages/KnowledgeBase/components/AddDataDialog.tsx index 863b1f2..cf23b7d 100644 --- a/frontend/src/pages/KnowledgeBase/components/AddDataDialog.tsx +++ b/frontend/src/pages/KnowledgeBase/components/AddDataDialog.tsx @@ -21,15 +21,16 @@ export default function AddDataDialog({ knowledgeBase, onDataAdded }) { const { message } = App.useApp(); const [form] = Form.useForm(); const [currentStep, setCurrentStep] = useState(0); + const [isSubmitting, setIsSubmitting] = useState(false); const [selectedFilesMap, setSelectedFilesMap] = useState({}); // 定义分块选项 const sliceOptions = [ { label: "默认分块", value: "DEFAULT_CHUNK" }, - { label: "按章节分块", value: "CHAPTER_CHUNK" }, + { label: "按句子分块", value: "SENTENCE_CHUNK" }, { label: "按段落分块", value: "PARAGRAPH_CHUNK" }, - { label: "固定长度分块", value: "FIXED_LENGTH_CHUNK" }, + { label: "固定长度分块", value: "LENGTH_CHUNK" }, { label: "自定义分隔符分块", value: "CUSTOM_SEPARATOR_CHUNK" }, ]; @@ -57,12 +58,7 @@ export default function AddDataDialog({ knowledgeBase, onDataAdded }) { ]; // 获取已选择文件总数 - const getSelectedFilesCount = () => { - return Object.values(selectedFilesMap).reduce( - (total, ids) => total + ids.length, - 0 - ); - }; + const getSelectedFilesCount = () => Object.keys(selectedFilesMap).length; const handleNext = () => { // 验证当前步骤 @@ -112,15 +108,29 @@ export default function AddDataDialog({ knowledgeBase, onDataAdded }) { }; const handleAddData = async () => { + if (isSubmitting) { + return; + } if (getSelectedFilesCount() === 0) { message.warning("请至少选择一个文件"); return; } try { + setIsSubmitting(true); + const uploadMessageKey = "kb-add-files"; + message.open({ + type: "loading", + content: "正在上传,请稍候...", + key: uploadMessageKey, + duration: 0, + }); // 构造符合API要求的请求数据 const requestData = { - files: Object.values(selectedFilesMap), + files: Object.values(selectedFilesMap).map((file) => ({ + id: String(file.id), + fileName: file.fileName, + })), processType: newKB.processType, chunkSize: Number(newKB.chunkSize), // 确保是数字类型 overlapSize: Number(newKB.overlapSize), // 确保是数字类型 @@ -132,12 +142,20 @@ export default function AddDataDialog({ knowledgeBase, onDataAdded }) { // 先通知父组件刷新数据(确保刷新发生在重置前) onDataAdded?.(); - message.success("数据添加成功"); + message.success({ + content: "数据添加成功", + key: uploadMessageKey, + }); // 重置状态 setOpen(false); } catch (error) { - message.error("数据添加失败,请重试"); + message.error({ + content: "数据添加失败,请重试", + key: "kb-add-files", + }); console.error("添加文件失败:", error); + } finally { + setIsSubmitting(false); } }; @@ -221,10 +239,12 @@ export default function AddDataDialog({ knowledgeBase, onDataAdded }) { footer={
{currentStep === 0 && ( - + )} {currentStep > 0 && ( - )} @@ -235,14 +255,20 @@ export default function AddDataDialog({ knowledgeBase, onDataAdded }) { Object.keys(selectedFilesMap).length === 0 || !newKB.chunkSize || !newKB.overlapSize || - !newKB.processType + !newKB.processType || + isSubmitting } onClick={handleNext} > 下一步 ) : ( - )}