feat: Add file type filtering to knowledge base search functionality, enhancing user experience and API capabilities
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; keyword?: string },
|
||||
params: { page: number; page_size: number; tag_id?: string; keyword?: string; file_type?: string },
|
||||
) {
|
||||
const query = new URLSearchParams();
|
||||
query.append('page', String(params.page));
|
||||
@@ -65,6 +65,9 @@ export function listKnowledgeFiles(
|
||||
if (params.keyword) {
|
||||
query.append('keyword', params.keyword);
|
||||
}
|
||||
if (params.file_type) {
|
||||
query.append('file_type', params.file_type);
|
||||
}
|
||||
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; keyword?: string } = { page: 1, page_size: 35 },
|
||||
query: { page: number; page_size: number; tag_id?: string; keyword?: string; file_type?: string } = { page: 1, page_size: 35 },
|
||||
kbId?: string,
|
||||
) => {
|
||||
const targetKbId = kbId || knowledgeBaseId;
|
||||
|
||||
@@ -183,6 +183,8 @@ export default {
|
||||
dragFileNotText: 'Please drag files instead of text or links',
|
||||
searchPlaceholder: 'Search knowledge bases...',
|
||||
docSearchPlaceholder: 'Search document names...',
|
||||
fileTypeFilter: 'File Type',
|
||||
allFileTypes: 'All Types',
|
||||
noMatch: 'No matching knowledge base found',
|
||||
noKnowledge: 'No knowledge bases available',
|
||||
loadingFailed: 'Failed to load knowledge bases'
|
||||
|
||||
@@ -183,6 +183,8 @@ export default {
|
||||
dragFileNotText: 'Пожалуйста, перетащите файлы, а не текст или ссылки',
|
||||
searchPlaceholder: 'Поиск по базам знаний...',
|
||||
docSearchPlaceholder: 'Поиск документов...',
|
||||
fileTypeFilter: 'Тип файла',
|
||||
allFileTypes: 'Все типы',
|
||||
noMatch: 'Совпадающих баз знаний не найдено',
|
||||
noKnowledge: 'Нет доступных баз знаний',
|
||||
loadingFailed: 'Не удалось загрузить базы знаний'
|
||||
|
||||
@@ -186,6 +186,8 @@ export default {
|
||||
dragFileNotText: "请拖拽文件而不是文本或链接",
|
||||
searchPlaceholder: "搜索知识库...",
|
||||
docSearchPlaceholder: "搜索文档名称...",
|
||||
fileTypeFilter: "文件类型",
|
||||
allFileTypes: "全部类型",
|
||||
noMatch: "未找到匹配的知识库",
|
||||
noKnowledge: "暂无可用知识库",
|
||||
loadingFailed: "加载知识库失败",
|
||||
|
||||
@@ -59,6 +59,17 @@ const tagTotal = ref(0);
|
||||
let tagSearchDebounce: ReturnType<typeof setTimeout> | null = null;
|
||||
let docSearchDebounce: ReturnType<typeof setTimeout> | null = null;
|
||||
const docSearchKeyword = ref('');
|
||||
const selectedFileType = ref('');
|
||||
const fileTypeOptions = computed(() => [
|
||||
{ content: t('knowledgeBase.allFileTypes') || '全部类型', value: '' },
|
||||
{ content: 'PDF', value: 'pdf' },
|
||||
{ content: 'DOCX', value: 'docx' },
|
||||
{ content: 'DOC', value: 'doc' },
|
||||
{ content: 'TXT', value: 'txt' },
|
||||
{ content: 'MD', value: 'md' },
|
||||
{ content: 'URL', value: 'url' },
|
||||
{ content: t('knowledgeBase.typeManual') || '手动创建', value: 'manual' },
|
||||
]);
|
||||
type TagInputInstance = ComponentPublicInstance<{ focus: () => void; select: () => void }>;
|
||||
const tagDropdownOptions = computed(() => {
|
||||
const options = [
|
||||
@@ -150,6 +161,7 @@ const loadKnowledgeFiles = (kbIdValue: string) => {
|
||||
page_size: pageSize,
|
||||
tag_id: selectedTagId.value || undefined,
|
||||
keyword: docSearchKeyword.value ? docSearchKeyword.value.trim() : undefined,
|
||||
file_type: selectedFileType.value || undefined,
|
||||
},
|
||||
kbIdValue,
|
||||
);
|
||||
@@ -460,6 +472,15 @@ watch(docSearchKeyword, (newVal, oldVal) => {
|
||||
}, 300);
|
||||
});
|
||||
|
||||
// 监听文件类型筛选变化
|
||||
watch(selectedFileType, (newVal, oldVal) => {
|
||||
if (newVal === oldVal) return;
|
||||
if (kbId.value) {
|
||||
page = 1;
|
||||
loadKnowledgeFiles(kbId.value);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听文件上传事件
|
||||
const handleFileUploaded = (event: CustomEvent) => {
|
||||
const uploadedKbId = event.detail.kbId;
|
||||
@@ -836,7 +857,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, keyword: docSearchKeyword.value ? docSearchKeyword.value.trim() : undefined });
|
||||
getKnowled({ page, page_size: pageSize, tag_id: selectedTagId.value || undefined, keyword: docSearchKeyword.value ? docSearchKeyword.value.trim() : undefined, file_type: selectedFileType.value || undefined });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1125,12 +1146,13 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</aside>
|
||||
<div class="tag-content">
|
||||
<div class="doc-card-area">
|
||||
<!-- 搜索栏 -->
|
||||
<div class="doc-search-bar">
|
||||
<!-- 搜索栏和筛选 -->
|
||||
<div class="doc-filter-bar">
|
||||
<t-input
|
||||
v-model.trim="docSearchKeyword"
|
||||
:placeholder="$t('knowledgeBase.docSearchPlaceholder')"
|
||||
clearable
|
||||
class="doc-search-input"
|
||||
@clear="loadKnowledgeFiles(kbId)"
|
||||
@keydown.enter="loadKnowledgeFiles(kbId)"
|
||||
>
|
||||
@@ -1138,6 +1160,13 @@ async function createNewSession(value: string): Promise<void> {
|
||||
<t-icon name="search" size="16px" />
|
||||
</template>
|
||||
</t-input>
|
||||
<t-select
|
||||
v-model="selectedFileType"
|
||||
:options="fileTypeOptions"
|
||||
:placeholder="$t('knowledgeBase.fileTypeFilter')"
|
||||
class="doc-type-select"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="doc-scroll-container"
|
||||
@@ -1781,9 +1810,21 @@ async function createNewSession(value: string): Promise<void> {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.doc-search-bar {
|
||||
.doc-filter-bar {
|
||||
padding: 0px 0px 10px 0px;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
|
||||
.doc-search-input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.doc-type-select {
|
||||
width: 140px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
:deep(.t-input) {
|
||||
font-size: 13px;
|
||||
@@ -1798,6 +1839,21 @@ async function createNewSession(value: string): Promise<void> {
|
||||
background-color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-select) {
|
||||
.t-input {
|
||||
font-size: 13px;
|
||||
background-color: #f7f9fc;
|
||||
border-color: #e5e9f2;
|
||||
border-radius: 6px;
|
||||
|
||||
&:hover,
|
||||
&.t-is-focused {
|
||||
border-color: #4080ff;
|
||||
background-color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.doc-scroll-container {
|
||||
|
||||
Reference in New Issue
Block a user