feat: Improve knowledge base loading and dropdown UI in manual knowledge editor
- Enhanced the knowledge base loading function with detailed logging for better debugging and visibility of the data flow. - Filtered knowledge bases to include only document types, improving the relevance of displayed options. - Updated the dropdown component to include a custom empty state message when no document-type knowledge bases are available. - Adjusted z-index styles for dropdowns to ensure proper visibility in various UI contexts. - Added localization strings for the new empty state message in English, Russian, and Chinese.
This commit is contained in:
@@ -405,9 +405,21 @@ const loadKnowledgeBases = async () => {
|
||||
kbLoading.value = true
|
||||
try {
|
||||
const res: any = await listKnowledgeBases()
|
||||
const list: KnowledgeBaseOption[] = Array.isArray(res?.data)
|
||||
? res.data.map((item: any) => ({ label: item.name, value: item.id }))
|
||||
: []
|
||||
console.log('[ManualEditor] Raw knowledge bases response:', res?.data)
|
||||
|
||||
const allKbs = Array.isArray(res?.data) ? res.data : []
|
||||
console.log('[ManualEditor] All knowledge bases:', allKbs)
|
||||
console.log('[ManualEditor] KB types:', allKbs.map((kb: any) => ({ name: kb.name, type: kb.type })))
|
||||
|
||||
const list: KnowledgeBaseOption[] = allKbs
|
||||
.filter((item: any) => {
|
||||
const isDocument = !item.type || item.type === 'document'
|
||||
console.log(`[ManualEditor] KB "${item.name}" (type: ${item.type}): ${isDocument ? 'INCLUDED' : 'FILTERED OUT'}`)
|
||||
return isDocument
|
||||
})
|
||||
.map((item: any) => ({ label: item.name, value: item.id }))
|
||||
|
||||
console.log('[ManualEditor] Filtered knowledge bases:', list)
|
||||
kbOptions.value = list
|
||||
|
||||
if (mode.value === 'create') {
|
||||
@@ -425,6 +437,9 @@ const loadKnowledgeBases = async () => {
|
||||
form.kbId = list[0]?.value ?? ''
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[ManualEditor] Final kbOptions:', kbOptions.value)
|
||||
console.log('[ManualEditor] Selected kbId:', form.kbId)
|
||||
} catch (error) {
|
||||
console.error('[ManualEditor] Failed to load knowledge base list:', error)
|
||||
kbOptions.value = []
|
||||
@@ -659,8 +674,19 @@ onBeforeUnmount(() => {
|
||||
:loading="kbLoading"
|
||||
:options="kbOptions"
|
||||
:placeholder="$t('manualEditor.form.knowledgeBasePlaceholder')"
|
||||
:popup-props="{ overlayStyle: { zIndex: 2200 } }"
|
||||
/>
|
||||
:popup-props="{
|
||||
attach: 'body',
|
||||
overlayStyle: { zIndex: 3000 },
|
||||
onVisibleChange: (visible) => console.log('[ManualEditor] Select dropdown visible:', visible)
|
||||
}"
|
||||
@focus="() => console.log('[ManualEditor] Select focused, options:', kbOptions)"
|
||||
>
|
||||
<template #empty>
|
||||
<div style="padding: 20px; text-align: center; color: #999;">
|
||||
{{ $t('manualEditor.noDocumentKnowledgeBases') || '暂无可用的文档型知识库,请先创建一个文档型知识库' }}
|
||||
</div>
|
||||
</template>
|
||||
</t-select>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
@@ -1021,3 +1047,21 @@ onBeforeUnmount(() => {
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- 全局样式:确保在dialog中的select下拉列表能够正常显示 -->
|
||||
<style lang="less">
|
||||
// TDesign Select 下拉框在 Dialog 中的 z-index 修复
|
||||
.t-select__dropdown {
|
||||
z-index: 3000 !important;
|
||||
}
|
||||
|
||||
// 确保挂载到 body 的 select popup 能正常显示
|
||||
body > .t-popup {
|
||||
z-index: 3000 !important;
|
||||
}
|
||||
|
||||
// 针对 manual-knowledge-editor 中的 select
|
||||
.manual-knowledge-editor + .t-select__dropdown,
|
||||
.manual-knowledge-editor ~ .t-select__dropdown {
|
||||
z-index: 3000 !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -618,6 +618,7 @@ export default {
|
||||
titlePlaceholder: 'Enter title',
|
||||
contentPlaceholder: 'Supports Markdown. Use # headings, lists, code blocks, etc.'
|
||||
},
|
||||
noDocumentKnowledgeBases: 'No document-type knowledge bases available. Please create one first',
|
||||
status: {
|
||||
draftTag: 'Status: Draft',
|
||||
publishedTag: 'Status: Published',
|
||||
|
||||
@@ -1488,6 +1488,7 @@ export default {
|
||||
titlePlaceholder: 'Введите заголовок',
|
||||
contentPlaceholder: 'Поддерживается Markdown. Используйте # заголовки, списки, блоки кода и т.д.'
|
||||
},
|
||||
noDocumentKnowledgeBases: 'Нет доступных баз знаний типа "документ". Пожалуйста, создайте одну сначала',
|
||||
status: {
|
||||
draftTag: 'Статус: Черновик',
|
||||
publishedTag: 'Статус: Опубликовано',
|
||||
|
||||
@@ -977,6 +977,7 @@ export default {
|
||||
titlePlaceholder: "请输入标题",
|
||||
contentPlaceholder: "支持 Markdown 语法,可使用 # 标题、列表、代码块等",
|
||||
},
|
||||
noDocumentKnowledgeBases: "暂无可用的文档型知识库,请先创建一个文档型知识库",
|
||||
status: {
|
||||
draftTag: "当前状态:草稿",
|
||||
publishedTag: "当前状态:已发布",
|
||||
|
||||
@@ -1097,10 +1097,11 @@ const kbInfo = ref<any>(null)
|
||||
const knowledgeList = ref<Array<{ id: string; name: string; type?: string }>>([])
|
||||
const knowledgeDropdownOptions = computed(() =>
|
||||
knowledgeList.value
|
||||
.filter((item) => !item.type || item.type === 'document')
|
||||
.map((item) => ({
|
||||
content: item.name,
|
||||
value: item.id,
|
||||
prefixIcon: () => h(TIcon, { name: item.type === 'faq' ? 'help-circle' : 'file', size: '16px' }),
|
||||
prefixIcon: () => h(TIcon, { name: 'file', size: '16px' }),
|
||||
})),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user