fix: 知识库支持分租户添加
- 添加按钮始终可见(不再在租户列表视图隐藏) - 在租户详情视图添加时,自动关联当前租户,弹窗标题显示租户名 - 在租户列表视图添加时,弹窗显示租户选择器让用户选择目标租户 - 分类选项统一添加 OTA升级
This commit is contained in:
Binary file not shown.
@@ -20,7 +20,6 @@ Object.assign(TSPDashboard.prototype, {
|
|||||||
tenantListEl.style.display = '';
|
tenantListEl.style.display = '';
|
||||||
tenantDetailEl.style.display = 'none';
|
tenantDetailEl.style.display = 'none';
|
||||||
if (searchBar) searchBar.style.display = 'none';
|
if (searchBar) searchBar.style.display = 'none';
|
||||||
if (addBtn) addBtn.style.display = 'none';
|
|
||||||
if (uploadBtn) uploadBtn.style.display = 'none';
|
if (uploadBtn) uploadBtn.style.display = 'none';
|
||||||
|
|
||||||
// 显示加载中
|
// 显示加载中
|
||||||
@@ -345,21 +344,19 @@ Object.assign(TSPDashboard.prototype, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Task 7.3: 添加知识条目时自动设置 tenant_id
|
const body = { question, answer, category, confidence_score: confidence };
|
||||||
const body = {
|
// 确定 tenant_id:优先用当前租户详情视图的,否则用弹窗里的选择器
|
||||||
question,
|
|
||||||
answer,
|
|
||||||
category,
|
|
||||||
confidence_score: confidence
|
|
||||||
};
|
|
||||||
if (this.knowledgeCurrentTenantId) {
|
if (this.knowledgeCurrentTenantId) {
|
||||||
body.tenant_id = 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', {
|
const response = await fetch('/api/knowledge', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: { 'Content-Type': 'application/json' },
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(body)
|
body: JSON.stringify(body)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -368,14 +365,13 @@ Object.assign(TSPDashboard.prototype, {
|
|||||||
this.showNotification('知识添加成功', 'success');
|
this.showNotification('知识添加成功', 'success');
|
||||||
bootstrap.Modal.getInstance(document.getElementById('addKnowledgeModal')).hide();
|
bootstrap.Modal.getInstance(document.getElementById('addKnowledgeModal')).hide();
|
||||||
document.getElementById('knowledge-form').reset();
|
document.getElementById('knowledge-form').reset();
|
||||||
// Task 7.3: 刷新当前视图
|
|
||||||
if (this.knowledgeCurrentTenantId) {
|
if (this.knowledgeCurrentTenantId) {
|
||||||
this.loadKnowledgeTenantDetail(this.knowledgeCurrentTenantId, this.paginationConfig.currentKnowledgePage);
|
this.loadKnowledgeTenantDetail(this.knowledgeCurrentTenantId, this.paginationConfig.currentKnowledgePage);
|
||||||
} else {
|
} else {
|
||||||
this.loadKnowledgeTenantList();
|
this.loadKnowledgeTenantList();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.showNotification('添加知识失败', 'error');
|
this.showNotification('添加知识失败: ' + (data.error || ''), 'error');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('添加知识失败:', 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 => `<option value="${t.tenant_id}">${t.name} (${t.tenant_id})</option>`).join('');
|
||||||
|
}
|
||||||
|
} catch (e) { console.warn('加载租户列表失败:', e); }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async uploadFile() {
|
async uploadFile() {
|
||||||
const fileInput = document.getElementById('file-input');
|
const fileInput = document.getElementById('file-input');
|
||||||
const processMethod = document.getElementById('process-method').value;
|
const processMethod = document.getElementById('process-method').value;
|
||||||
|
|||||||
@@ -900,7 +900,7 @@
|
|||||||
<button class="btn btn-outline-secondary btn-sm" id="knowledge-refresh-btn" onclick="dashboard.refreshKnowledge()">
|
<button class="btn btn-outline-secondary btn-sm" id="knowledge-refresh-btn" onclick="dashboard.refreshKnowledge()">
|
||||||
<i class="fas fa-sync-alt me-1"></i>刷新
|
<i class="fas fa-sync-alt me-1"></i>刷新
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addKnowledgeModal" style="display:none" id="knowledge-add-btn">
|
<button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addKnowledgeModal" id="knowledge-add-btn" onclick="dashboard.prepareAddKnowledge()">
|
||||||
<i class="fas fa-plus me-1"></i>添加知识
|
<i class="fas fa-plus me-1"></i>添加知识
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-success btn-sm" data-bs-toggle="modal" data-bs-target="#uploadFileModal" style="display:none" id="knowledge-upload-btn">
|
<button class="btn btn-success btn-sm" data-bs-toggle="modal" data-bs-target="#uploadFileModal" style="display:none" id="knowledge-upload-btn">
|
||||||
@@ -2454,11 +2454,17 @@
|
|||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title">添加知识</h5>
|
<h5 class="modal-title" id="addKnowledgeModalTitle">添加知识</h5>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form id="knowledge-form">
|
<form id="knowledge-form">
|
||||||
|
<div class="mb-3" id="knowledge-tenant-select-group" style="display:none">
|
||||||
|
<label class="form-label">所属租户</label>
|
||||||
|
<select class="form-select" id="knowledge-tenant-select">
|
||||||
|
<option value="default">默认租户</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">问题</label>
|
<label class="form-label">问题</label>
|
||||||
<input type="text" class="form-control" id="knowledge-question" required>
|
<input type="text" class="form-control" id="knowledge-question" required>
|
||||||
@@ -2474,6 +2480,7 @@
|
|||||||
<option value="APP功能">APP功能</option>
|
<option value="APP功能">APP功能</option>
|
||||||
<option value="远程控制">远程控制</option>
|
<option value="远程控制">远程控制</option>
|
||||||
<option value="车辆绑定">车辆绑定</option>
|
<option value="车辆绑定">车辆绑定</option>
|
||||||
|
<option value="OTA升级">OTA升级</option>
|
||||||
<option value="其他">其他</option>
|
<option value="其他">其他</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user