知识库初始化

This commit is contained in:
2025-12-20 12:03:26 +08:00
parent 566d03491b
commit 1498b91bcf
9 changed files with 3562 additions and 34 deletions

View File

@@ -0,0 +1,72 @@
.kb-categories {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 16px;
margin-bottom: 24px;
.kb-category-card {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
padding: 20px 16px;
background: #f5f7fa;
border: 2px solid transparent;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
&:hover {
background: #ecf5ff;
border-color: #b3d8ff;
}
&.active {
background: #ecf5ff;
border-color: #409eff;
}
.el-icon {
font-size: 32px;
}
.cat-name {
font-size: 14px;
font-weight: 500;
color: #303133;
text-align: center;
}
.cat-count {
font-size: 12px;
color: #909399;
}
}
}
.kb-files-section {
.section-toolbar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
h3 {
margin: 0;
font-size: 16px;
font-weight: 500;
color: #303133;
}
}
.file-name-cell {
display: flex;
align-items: center;
gap: 8px;
.file-icon {
color: #409eff;
font-size: 18px;
}
}
}

View File

@@ -157,10 +157,8 @@ const currentTabDesc = computed(() => currentTabConfig.value.desc)
const currentTabLabel = computed(() => currentTabConfig.value.label)
const currentTabColor = computed(() => currentTabConfig.value.color)
// 当前 Tab 下的知识库列表
const currentKnowledges = computed(() =>
knowledges.value.filter((kb: TbKnowledge) => kb.category === activeTab.value)
)
// 当前 Tab 下的知识库列表(直接使用查询结果,不再前端过滤)
const currentKnowledges = computed(() => knowledges.value)
// 当前选中的知识库名称
const currentKnowledgeName = computed(() => {
@@ -176,16 +174,18 @@ const filteredDocuments = computed(() => {
)
})
// 获取知识库列表
// 获取知识库列表(根据当前 Tab 的 category 查询)
const fetchKnowledges = async () => {
loading.value = true
try {
const result = await aiKnowledgeAPI.listKnowledges({ service: 'workcase' })
if (result.success && Array.isArray(result.data)) {
knowledges.value = result.data
// 默认选中当前 Tab 下的第一个知识库
selectFirstKnowledge()
}
const result = await aiKnowledgeAPI.listKnowledges({
service: 'workcase',
category: activeTab.value
})
console.log('知识库列表响应:', result)
// API 返回的是 dataList 字段
knowledges.value = result.dataList || []
selectFirstKnowledge()
} catch (error) {
console.error('获取知识库列表失败:', error)
ElMessage.error('获取知识库列表失败')
@@ -236,10 +236,13 @@ const fetchDocuments = async (knowledgeId: string) => {
}
}
// Tab 切换
// Tab 切换时重新查询对应类别的知识库
const handleTabChange = () => {
searchKeyword.value = ''
selectFirstKnowledge()
knowledges.value = []
activeKnowledgeId.value = ''
documents.value = []
fetchKnowledges()
}
// 选择知识库