first commit
This commit is contained in:
@@ -1173,8 +1173,39 @@ registerPage('kb-create', function(container) {
|
||||
};
|
||||
|
||||
window.__finishWizard = function() {
|
||||
collectStepData();
|
||||
|
||||
// TODO: 调用 API POST /api/v1/knowledge-bases 创建知识库
|
||||
console.log('创建知识库数据:', formData);
|
||||
|
||||
const typeMap = {
|
||||
doc_search: '文档搜索',
|
||||
data_query: '数据查询',
|
||||
image_qa: '图片问答',
|
||||
video_search: '音视频搜索',
|
||||
};
|
||||
const createdAt = new Date();
|
||||
const pad = value => String(value).padStart(2, '0');
|
||||
const createdText = `${createdAt.getFullYear()}-${pad(createdAt.getMonth() + 1)}-${pad(createdAt.getDate())} ${pad(createdAt.getHours())}:${pad(createdAt.getMinutes())}:${pad(createdAt.getSeconds())}`;
|
||||
const uploadedCount = Array.isArray(formData.uploadedFiles) ? formData.uploadedFiles.length : 0;
|
||||
const newKb = {
|
||||
id: `kb-${Date.now()}`,
|
||||
name: formData.name || '未命名知识库',
|
||||
description: formData.description || '暂无描述',
|
||||
docs: uploadedCount * 24,
|
||||
size: uploadedCount ? `${Math.max(1, uploadedCount * 8)}MB` : '0MB',
|
||||
type: formData.type || 'doc_search',
|
||||
typeName: typeMap[formData.type] || '文档搜索',
|
||||
status: uploadedCount ? 'processing' : 'ready',
|
||||
createdAt: createdText,
|
||||
updatedAt: createdText,
|
||||
tags: [],
|
||||
};
|
||||
const catalog = Array.isArray(window.__knowledgeBaseCatalog)
|
||||
? window.__knowledgeBaseCatalog
|
||||
: [];
|
||||
catalog.unshift(newKb);
|
||||
window.__knowledgeBaseCatalog = catalog;
|
||||
|
||||
clearDraft();
|
||||
Toast.success('知识库创建成功!');
|
||||
@@ -1302,8 +1333,18 @@ registerPage('kb-create', function(container) {
|
||||
|
||||
window.__retryUpload = function(index) {
|
||||
if (formData.uploadedFiles[index]) {
|
||||
formData.uploadedFiles[index].status = 'uploading';
|
||||
const fileObj = formData.uploadedFiles[index];
|
||||
fileObj.status = 'uploading';
|
||||
renderPage();
|
||||
setTimeout(() => {
|
||||
fileObj.status = 'processing';
|
||||
renderPage();
|
||||
}, 500);
|
||||
setTimeout(() => {
|
||||
fileObj.status = 'ready';
|
||||
renderPage();
|
||||
Toast.success(`${fileObj.name} 已重新上传并解析完成`);
|
||||
}, 1500);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1422,11 +1463,101 @@ registerPage('kb-create', function(container) {
|
||||
|
||||
window.__loadCategoryFiles = function(category) {
|
||||
// TODO: 调用 API GET /api/v1/categories/:id/files
|
||||
Toast.info(`加载 ${category} 文件列表`);
|
||||
createModal({
|
||||
title: `${category} 文件列表`,
|
||||
size: 'lg',
|
||||
content: `
|
||||
<div style="display:flex;flex-direction:column;gap:10px">
|
||||
${['儿童科学百科.pdf', '科学小实验.docx', '物理入门.xlsx'].map((name, index) => `
|
||||
<div style="display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px;border:1px solid var(--border);border-radius:var(--radius)">
|
||||
<div>
|
||||
<div style="font-weight:600">${name}</div>
|
||||
<div style="font-size:12px;color:var(--text-muted)">mock-file-${index + 1} · ${(index + 1) * 2}.4MB</div>
|
||||
</div>
|
||||
<button class="btn btn-outline btn-sm" onclick="Toast.success('已选择 ${name}')">选择</button>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
`,
|
||||
confirmText: '',
|
||||
cancelText: '关闭'
|
||||
});
|
||||
};
|
||||
|
||||
window.__showCategoryDrawer = function() {
|
||||
Toast.info('类目管理功能');
|
||||
const renderCategoryRows = () => {
|
||||
const list = document.getElementById('categoryManageList');
|
||||
if (!list) return;
|
||||
list.innerHTML = categories.map(category => `
|
||||
<div style="display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px;border:1px solid var(--border);border-radius:var(--radius)">
|
||||
<div>
|
||||
<div style="font-weight:600">${category.name}</div>
|
||||
<div style="font-size:12px;color:var(--text-muted)">${category.fileCount} 个文件 · ${category.id}</div>
|
||||
</div>
|
||||
<div style="display:flex;gap:6px">
|
||||
<button class="btn btn-outline btn-sm" onclick="window.__chooseCategoryFromModal('${category.name}')">选择</button>
|
||||
${category.id === 'cat-001' ? '' : `
|
||||
<button class="btn btn-ghost btn-sm" onclick="window.__removeCategoryFromModal('${category.id}')">
|
||||
<i data-lucide="trash-2" style="width:14px;height:14px"></i>
|
||||
</button>
|
||||
`}
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
lucide.createIcons({ elements: list });
|
||||
};
|
||||
|
||||
createModal({
|
||||
title: '类目管理',
|
||||
size: 'lg',
|
||||
content: `
|
||||
<div style="display:flex;gap:10px;margin-bottom:14px">
|
||||
<input class="form-control" id="newCategoryName" placeholder="输入新类目名称">
|
||||
<button class="btn btn-primary" type="button" onclick="window.__addCategoryFromModal()">添加</button>
|
||||
</div>
|
||||
<div id="categoryManageList" style="display:flex;flex-direction:column;gap:10px"></div>
|
||||
`,
|
||||
confirmText: '',
|
||||
cancelText: '关闭'
|
||||
});
|
||||
|
||||
window.__addCategoryFromModal = function() {
|
||||
const input = document.getElementById('newCategoryName');
|
||||
const name = input?.value.trim();
|
||||
if (!name) {
|
||||
Toast.warning('请输入类目名称');
|
||||
return;
|
||||
}
|
||||
categories.push({
|
||||
id: `cat-${Date.now()}`,
|
||||
name,
|
||||
fileCount: 0,
|
||||
});
|
||||
input.value = '';
|
||||
renderCategoryRows();
|
||||
Toast.success('类目已添加');
|
||||
};
|
||||
|
||||
window.__removeCategoryFromModal = function(id) {
|
||||
const index = categories.findIndex(category => category.id === id);
|
||||
if (index !== -1) {
|
||||
categories.splice(index, 1);
|
||||
renderCategoryRows();
|
||||
Toast.success('类目已删除');
|
||||
}
|
||||
};
|
||||
|
||||
window.__chooseCategoryFromModal = function(name) {
|
||||
formData.category = name;
|
||||
hasUnsavedChanges = true;
|
||||
const select = document.getElementById('categorySelect');
|
||||
if (select && Array.from(select.options).some(option => option.value === name)) {
|
||||
select.value = name;
|
||||
}
|
||||
Toast.success(`已选择类目:${name}`);
|
||||
};
|
||||
|
||||
setTimeout(renderCategoryRows, 50);
|
||||
};
|
||||
|
||||
window.__saveDraft = saveDraft;
|
||||
|
||||
Reference in New Issue
Block a user