From 30c6916d6f7a761258dc7623cd4c21be0a010f37 Mon Sep 17 00:00:00 2001 From: thzxx Date: Sat, 4 Apr 2026 23:41:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=97=A0=E5=8F=8D=E9=A6=88=E7=9A=84bug?= =?UTF-8?q?=EF=BC=8CFileList=E5=9C=A8=E6=B8=85=E7=A9=BA=E5=89=8D=E8=A2=AB?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=AF=BC=E8=87=B4=E4=B8=A2=E5=A4=B1=EF=BC=9B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=86=E5=9D=97=E6=95=B0=E5=92=8C=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=B1=87=E6=80=BB=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/components/kb-modal.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/js/components/kb-modal.js b/js/components/kb-modal.js index b3f48f8..571494a 100644 --- a/js/components/kb-modal.js +++ b/js/components/kb-modal.js @@ -245,24 +245,27 @@ async function createCollection() { * 上传文档处理 */ async function handleDocUpload(e) { - const files = e.target.value; + const fileArr = Array.from(e.target.files || []); e.target.value = ''; + if (fileArr.length === 0) return; + const embedModel = document.querySelector('#selectEmbedModel').value; if (!embedModel) { showToast('请先选择一个嵌入模型', 'warning'); return; } - const fileArr = Array.from(e.target.files || []); - if (fileArr.length === 0) return; - const progressEl = document.querySelector('#kbProgress'); const progressTextEl = document.querySelector('#kbProgressText'); + let successCount = 0; + let failCount = 0; + for (const file of fileArr) { if (file.size > 5 * 1024 * 1024) { showToast(`${file.name} 超过 5MB 限制`, 'warning'); + failCount++; continue; } @@ -271,21 +274,28 @@ async function handleDocUpload(e) { progressTextEl.textContent = `正在处理 ${file.name}...`; const content = await fileToText(file); - await addDocumentToKB( + const result = await addDocumentToKB( currentColId, file.name, content, embedModel, (done, total, msg) => { progressTextEl.textContent = `${file.name}: ${msg} (${done}/${total})`; } ); - showToast(`${file.name} 已添加到知识库`, 'success'); + showToast(`${file.name} 已添加到知识库(${result.chunkCount} 个分块)`, 'success'); + successCount++; } catch (err) { console.error('[KB] 文档处理失败:', err); showToast(`${file.name} 处理失败: ${err.message}`, 'error'); + failCount++; } } progressEl.style.display = 'none'; + + if (fileArr.length > 1) { + showToast(`上传完成:成功 ${successCount} 个,失败 ${failCount} 个`, failCount > 0 ? 'warning' : 'success'); + } + await refreshCollections(); await refreshDocList(); }