fix: 修复文档上传无反馈的bug,FileList在清空前被读取导致丢失;增加分块数和批量汇总提示

This commit is contained in:
thzxx
2026-04-04 23:41:09 +08:00
parent 8c7ad06dce
commit 30c6916d6f
+16 -6
View File
@@ -245,24 +245,27 @@ async function createCollection() {
* 上传文档处理 * 上传文档处理
*/ */
async function handleDocUpload(e) { async function handleDocUpload(e) {
const files = e.target.value; const fileArr = Array.from(e.target.files || []);
e.target.value = ''; e.target.value = '';
if (fileArr.length === 0) return;
const embedModel = document.querySelector('#selectEmbedModel').value; const embedModel = document.querySelector('#selectEmbedModel').value;
if (!embedModel) { if (!embedModel) {
showToast('请先选择一个嵌入模型', 'warning'); showToast('请先选择一个嵌入模型', 'warning');
return; return;
} }
const fileArr = Array.from(e.target.files || []);
if (fileArr.length === 0) return;
const progressEl = document.querySelector('#kbProgress'); const progressEl = document.querySelector('#kbProgress');
const progressTextEl = document.querySelector('#kbProgressText'); const progressTextEl = document.querySelector('#kbProgressText');
let successCount = 0;
let failCount = 0;
for (const file of fileArr) { for (const file of fileArr) {
if (file.size > 5 * 1024 * 1024) { if (file.size > 5 * 1024 * 1024) {
showToast(`${file.name} 超过 5MB 限制`, 'warning'); showToast(`${file.name} 超过 5MB 限制`, 'warning');
failCount++;
continue; continue;
} }
@@ -271,21 +274,28 @@ async function handleDocUpload(e) {
progressTextEl.textContent = `正在处理 ${file.name}...`; progressTextEl.textContent = `正在处理 ${file.name}...`;
const content = await fileToText(file); const content = await fileToText(file);
await addDocumentToKB( const result = await addDocumentToKB(
currentColId, file.name, content, embedModel, currentColId, file.name, content, embedModel,
(done, total, msg) => { (done, total, msg) => {
progressTextEl.textContent = `${file.name}: ${msg} (${done}/${total})`; progressTextEl.textContent = `${file.name}: ${msg} (${done}/${total})`;
} }
); );
showToast(`${file.name} 已添加到知识库`, 'success'); showToast(`${file.name} 已添加到知识库${result.chunkCount} 个分块)`, 'success');
successCount++;
} catch (err) { } catch (err) {
console.error('[KB] 文档处理失败:', err); console.error('[KB] 文档处理失败:', err);
showToast(`${file.name} 处理失败: ${err.message}`, 'error'); showToast(`${file.name} 处理失败: ${err.message}`, 'error');
failCount++;
} }
} }
progressEl.style.display = 'none'; progressEl.style.display = 'none';
if (fileArr.length > 1) {
showToast(`上传完成:成功 ${successCount} 个,失败 ${failCount}`, failCount > 0 ? 'warning' : 'success');
}
await refreshCollections(); await refreshCollections();
await refreshDocList(); await refreshDocList();
} }