diff --git a/data/tsp_assistant.db b/data/tsp_assistant.db index 33745c5..46b1d5f 100644 Binary files a/data/tsp_assistant.db and b/data/tsp_assistant.db differ diff --git a/src/web/static/js/modules/knowledge.js b/src/web/static/js/modules/knowledge.js index e0ee71d..ff71f0e 100644 --- a/src/web/static/js/modules/knowledge.js +++ b/src/web/static/js/modules/knowledge.js @@ -20,7 +20,6 @@ Object.assign(TSPDashboard.prototype, { tenantListEl.style.display = ''; tenantDetailEl.style.display = 'none'; if (searchBar) searchBar.style.display = 'none'; - if (addBtn) addBtn.style.display = 'none'; if (uploadBtn) uploadBtn.style.display = 'none'; // 显示加载中 @@ -345,21 +344,19 @@ Object.assign(TSPDashboard.prototype, { } try { - // Task 7.3: 添加知识条目时自动设置 tenant_id - const body = { - question, - answer, - category, - confidence_score: confidence - }; + const body = { question, answer, category, confidence_score: confidence }; + // 确定 tenant_id:优先用当前租户详情视图的,否则用弹窗里的选择器 if (this.knowledgeCurrentTenantId) { body.tenant_id = this.knowledgeCurrentTenantId; + } else { + const selectEl = document.getElementById('knowledge-tenant-select'); + if (selectEl && selectEl.value) { + body.tenant_id = selectEl.value; + } } const response = await fetch('/api/knowledge', { method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, + headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }); @@ -368,14 +365,13 @@ Object.assign(TSPDashboard.prototype, { this.showNotification('知识添加成功', 'success'); bootstrap.Modal.getInstance(document.getElementById('addKnowledgeModal')).hide(); document.getElementById('knowledge-form').reset(); - // Task 7.3: 刷新当前视图 if (this.knowledgeCurrentTenantId) { this.loadKnowledgeTenantDetail(this.knowledgeCurrentTenantId, this.paginationConfig.currentKnowledgePage); } else { this.loadKnowledgeTenantList(); } } else { - this.showNotification('添加知识失败', 'error'); + this.showNotification('添加知识失败: ' + (data.error || ''), 'error'); } } catch (error) { console.error('添加知识失败:', error); @@ -383,6 +379,29 @@ Object.assign(TSPDashboard.prototype, { } }, + async prepareAddKnowledge() { + const titleEl = document.getElementById('addKnowledgeModalTitle'); + const selectGroup = document.getElementById('knowledge-tenant-select-group'); + if (this.knowledgeCurrentTenantId) { + // 在租户详情视图里,直接添加到当前租户 + if (titleEl) titleEl.textContent = `添加知识 — ${this.knowledgeCurrentTenantId}`; + if (selectGroup) selectGroup.style.display = 'none'; + } else { + // 在租户列表视图里,显示租户选择器 + if (titleEl) titleEl.textContent = '添加知识'; + if (selectGroup) selectGroup.style.display = ''; + // 填充租户选择器 + try { + const resp = await fetch('/api/tenants'); + const tenants = await resp.json(); + const selectEl = document.getElementById('knowledge-tenant-select'); + if (selectEl && Array.isArray(tenants)) { + selectEl.innerHTML = tenants.map(t => ``).join(''); + } + } catch (e) { console.warn('加载租户列表失败:', e); } + } + }, + async uploadFile() { const fileInput = document.getElementById('file-input'); const processMethod = document.getElementById('process-method').value; diff --git a/src/web/templates/dashboard.html b/src/web/templates/dashboard.html index 02514f6..2c0fb65 100644 --- a/src/web/templates/dashboard.html +++ b/src/web/templates/dashboard.html @@ -900,7 +900,7 @@ -