feat: Enhance knowledge base functionality by adding document search capability and updating related API and UI components
This commit is contained in:
@@ -54,7 +54,7 @@ export function createManualKnowledge(kbId: string, data: { title: string; conte
|
||||
|
||||
export function listKnowledgeFiles(
|
||||
kbId: string,
|
||||
params: { page: number; page_size: number; tag_id?: string },
|
||||
params: { page: number; page_size: number; tag_id?: string; keyword?: string },
|
||||
) {
|
||||
const query = new URLSearchParams();
|
||||
query.append('page', String(params.page));
|
||||
@@ -62,6 +62,9 @@ export function listKnowledgeFiles(
|
||||
if (params.tag_id) {
|
||||
query.append('tag_id', params.tag_id);
|
||||
}
|
||||
if (params.keyword) {
|
||||
query.append('keyword', params.keyword);
|
||||
}
|
||||
const qs = query.toString();
|
||||
return get(`/api/v1/knowledge-bases/${kbId}/knowledge?${qs}`);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export default function (knowledgeBaseId?: string) {
|
||||
file_type: ""
|
||||
});
|
||||
const getKnowled = (
|
||||
query: { page: number; page_size: number; tag_id?: string } = { page: 1, page_size: 35 },
|
||||
query: { page: number; page_size: number; tag_id?: string; keyword?: string } = { page: 1, page_size: 35 },
|
||||
kbId?: string,
|
||||
) => {
|
||||
const targetKbId = kbId || knowledgeBaseId;
|
||||
|
||||
@@ -182,6 +182,7 @@ export default {
|
||||
textMarkdownFormat: 'text, markdown format files, max 200K',
|
||||
dragFileNotText: 'Please drag files instead of text or links',
|
||||
searchPlaceholder: 'Search knowledge bases...',
|
||||
docSearchPlaceholder: 'Search document names...',
|
||||
noMatch: 'No matching knowledge base found',
|
||||
noKnowledge: 'No knowledge bases available',
|
||||
loadingFailed: 'Failed to load knowledge bases'
|
||||
|
||||
@@ -182,6 +182,7 @@ export default {
|
||||
textMarkdownFormat: 'Файлы text, markdown формата, не более 200 КБ',
|
||||
dragFileNotText: 'Пожалуйста, перетащите файлы, а не текст или ссылки',
|
||||
searchPlaceholder: 'Поиск по базам знаний...',
|
||||
docSearchPlaceholder: 'Поиск документов...',
|
||||
noMatch: 'Совпадающих баз знаний не найдено',
|
||||
noKnowledge: 'Нет доступных баз знаний',
|
||||
loadingFailed: 'Не удалось загрузить базы знаний'
|
||||
|
||||
@@ -185,6 +185,7 @@ export default {
|
||||
textMarkdownFormat: "text、markdown格式文件,不超过200K",
|
||||
dragFileNotText: "请拖拽文件而不是文本或链接",
|
||||
searchPlaceholder: "搜索知识库...",
|
||||
docSearchPlaceholder: "搜索文档名称...",
|
||||
noMatch: "未找到匹配的知识库",
|
||||
noKnowledge: "暂无可用知识库",
|
||||
loadingFailed: "加载知识库失败",
|
||||
|
||||
@@ -57,6 +57,8 @@ const tagHasMore = ref(false);
|
||||
const tagLoadingMore = ref(false);
|
||||
const tagTotal = ref(0);
|
||||
let tagSearchDebounce: ReturnType<typeof setTimeout> | null = null;
|
||||
let docSearchDebounce: ReturnType<typeof setTimeout> | null = null;
|
||||
const docSearchKeyword = ref('');
|
||||
type TagInputInstance = ComponentPublicInstance<{ focus: () => void; select: () => void }>;
|
||||
const tagDropdownOptions = computed(() => {
|
||||
const options = [
|
||||
@@ -147,6 +149,7 @@ const loadKnowledgeFiles = (kbIdValue: string) => {
|
||||
page: 1,
|
||||
page_size: pageSize,
|
||||
tag_id: selectedTagId.value || undefined,
|
||||
keyword: docSearchKeyword.value ? docSearchKeyword.value.trim() : undefined,
|
||||
},
|
||||
kbIdValue,
|
||||
);
|
||||
@@ -443,6 +446,20 @@ watch(tagSearchQuery, (newVal, oldVal) => {
|
||||
}, 300);
|
||||
});
|
||||
|
||||
// 监听文档搜索关键词变化
|
||||
watch(docSearchKeyword, (newVal, oldVal) => {
|
||||
if (newVal === oldVal) return;
|
||||
if (docSearchDebounce) {
|
||||
clearTimeout(docSearchDebounce);
|
||||
}
|
||||
docSearchDebounce = window.setTimeout(() => {
|
||||
if (kbId.value) {
|
||||
page = 1;
|
||||
loadKnowledgeFiles(kbId.value);
|
||||
}
|
||||
}, 300);
|
||||
});
|
||||
|
||||
// 监听文件上传事件
|
||||
const handleFileUploaded = (event: CustomEvent) => {
|
||||
const uploadedKbId = event.detail.kbId;
|
||||
@@ -819,7 +836,7 @@ const handleScroll = () => {
|
||||
if (scrollTop + clientHeight >= scrollHeight) {
|
||||
page++;
|
||||
if (cardList.value.length < total.value && page <= pageNum) {
|
||||
getKnowled({ page, page_size: pageSize, tag_id: selectedTagId.value || undefined });
|
||||
getKnowled({ page, page_size: pageSize, tag_id: selectedTagId.value || undefined, keyword: docSearchKeyword.value ? docSearchKeyword.value.trim() : undefined });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1108,6 +1125,20 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</aside>
|
||||
<div class="tag-content">
|
||||
<div class="doc-card-area">
|
||||
<!-- 搜索栏 -->
|
||||
<div class="doc-search-bar">
|
||||
<t-input
|
||||
v-model.trim="docSearchKeyword"
|
||||
:placeholder="$t('knowledgeBase.docSearchPlaceholder')"
|
||||
clearable
|
||||
@clear="loadKnowledgeFiles(kbId)"
|
||||
@keydown.enter="loadKnowledgeFiles(kbId)"
|
||||
>
|
||||
<template #prefix-icon>
|
||||
<t-icon name="search" size="16px" />
|
||||
</template>
|
||||
</t-input>
|
||||
</div>
|
||||
<div
|
||||
class="doc-scroll-container"
|
||||
:class="{ 'is-empty': !cardList.length }"
|
||||
@@ -1750,6 +1781,25 @@ async function createNewSession(value: string): Promise<void> {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.doc-search-bar {
|
||||
padding: 0px 0px 10px 0px;
|
||||
flex-shrink: 0;
|
||||
|
||||
:deep(.t-input) {
|
||||
font-size: 13px;
|
||||
background-color: #f7f9fc;
|
||||
border-color: #e5e9f2;
|
||||
border-radius: 6px;
|
||||
|
||||
&:hover,
|
||||
&:focus,
|
||||
&.t-is-focused {
|
||||
border-color: #4080ff;
|
||||
background-color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.doc-scroll-container {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
Reference in New Issue
Block a user