feat(knowledge-base): document list filters and explicit batch-management UX

Add three new optional filters to the document list under a knowledge base
detail page — parse status, source/channel, and updated time range — and
rework multi-select to no longer cause the card title to jitter on hover.

Backend
- Introduce types.KnowledgeListFilter to aggregate optional filter dimensions
  (tag, keyword, file_type, parse_status, source, updated_from/to) and switch
  ListPagedKnowledgeByKnowledgeBaseID (repository/service/interface) to accept
  it instead of a growing positional parameter list.
- The ListKnowledge HTTP handler accepts new parse_status, source, start_time
  and end_time query params; time params accept RFC3339, "YYYY-MM-DD HH:MM:SS"
  and "YYYY-MM-DD". The repository routes source="manual"/"url" onto the type
  column to stay consistent with file_type semantics; other source values match
  the channel column.
- Update the four other callers (agent_service, initialization) to pass an
  empty filter struct, preserving prior behavior.

Frontend
- Add three controls in the doc-filter-bar (status select, source select,
  date-range picker with future-date disabled) wired through getKnowled /
  listKnowledgeFiles into the new backend params.
- Replace the hover-triggered card checkbox with an explicit "批量管理" mode
  (mirrors the session list UX): in card view the checkbox only renders while
  batch mode is on, entered via the per-card "..." menu; the list view keeps
  its leading checkbox column. Switching from list to grid auto-enables batch
  mode when something is already selected, so the selection stays visible.
- DocumentBatchBar now stays open whenever batch mode or selection > 0, and
  its "取消选择" button both clears the selection and exits batch mode.

API surface sync
- Regenerate Swagger artifacts (docs/docs.go / swagger.json / swagger.yaml).
- Update docs/api/knowledge.md with the new query parameters.
- Add backward-compatible ListKnowledgeWithFilter + KnowledgeListFilter to the
  Go SDK; the existing ListKnowledge keeps its signature.

i18n
- New filter labels in zh-CN / en-US / ko-KR / ru-RU; reuse existing
  menu.batchManage / batchManage.cancel for the multi-select strings.
This commit is contained in:
wizardchen
2026-05-12 18:16:34 +08:00
committed by lyingbug
parent f635eaf466
commit cacca049d9
20 changed files with 596 additions and 174 deletions
+18 -10
View File
@@ -133,20 +133,28 @@ 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; file_type?: string },
params: {
page: number;
page_size: number;
tag_id?: string;
keyword?: string;
file_type?: string;
parse_status?: string;
source?: string;
start_time?: string;
end_time?: string;
},
) {
const query = new URLSearchParams();
query.append('page', String(params.page));
query.append('page_size', String(params.page_size));
if (params.tag_id) {
query.append('tag_id', params.tag_id);
}
if (params.keyword) {
query.append('keyword', params.keyword);
}
if (params.file_type) {
query.append('file_type', params.file_type);
}
if (params.tag_id) query.append('tag_id', params.tag_id);
if (params.keyword) query.append('keyword', params.keyword);
if (params.file_type) query.append('file_type', params.file_type);
if (params.parse_status) query.append('parse_status', params.parse_status);
if (params.source) query.append('source', params.source);
if (params.start_time) query.append('start_time', params.start_time);
if (params.end_time) query.append('end_time', params.end_time);
const qs = query.toString();
return get(`/api/v1/knowledge-bases/${kbId}/knowledge?${qs}`);
}
+11 -1
View File
@@ -36,7 +36,17 @@ export default function (knowledgeBaseId?: string) {
chunkLoadError: "",
});
const getKnowled = (
query: { page: number; page_size: number; tag_id?: string; keyword?: string; file_type?: string } = { page: 1, page_size: 35 },
query: {
page: number;
page_size: number;
tag_id?: string;
keyword?: string;
file_type?: string;
parse_status?: string;
source?: string;
start_time?: string;
end_time?: string;
} = { page: 1, page_size: 35 },
kbId?: string,
): Promise<void> => {
const targetKbId = kbId || knowledgeBaseId;
+17
View File
@@ -315,6 +315,23 @@ export default {
docSearchPlaceholder: 'Search document names...',
fileTypeFilter: 'File Type',
allFileTypes: 'All Types',
parseStatusFilter: 'Status',
allParseStatuses: 'All Statuses',
parseStatusPending: 'Pending',
parseStatusProcessing: 'Processing',
parseStatusCompleted: 'Completed',
parseStatusFailed: 'Failed',
sourceFilter: 'Source',
allSources: 'All Sources',
sourceWeb: 'Web',
sourceApi: 'API',
sourceBrowserExtension: 'Browser Extension',
sourceUpload: 'Upload',
sourceUrl: 'URL Import',
sourceManual: 'Manual',
updatedTimeFilter: 'Updated',
updatedTimeFrom: 'From',
updatedTimeTo: 'To',
noMatch: 'No matching knowledge base found',
noKnowledge: 'No knowledge bases available',
loadingFailed: 'Failed to load knowledge bases',
+17
View File
@@ -322,6 +322,23 @@ export default {
docSearchPlaceholder: "문서 이름 검색...",
fileTypeFilter: "파일 유형",
allFileTypes: "모든 유형",
parseStatusFilter: "상태",
allParseStatuses: "모든 상태",
parseStatusPending: "대기 중",
parseStatusProcessing: "처리 중",
parseStatusCompleted: "완료됨",
parseStatusFailed: "실패",
sourceFilter: "출처",
allSources: "모든 출처",
sourceWeb: "웹",
sourceApi: "API",
sourceBrowserExtension: "브라우저 확장",
sourceUpload: "로컬 업로드",
sourceUrl: "URL 가져오기",
sourceManual: "수동 생성",
updatedTimeFilter: "업데이트 시간",
updatedTimeFrom: "시작",
updatedTimeTo: "종료",
noMatch: "일치하는 지식베이스를 찾을 수 없음",
noKnowledge: "사용 가능한 지식베이스 없음",
loadingFailed: "지식베이스 로드 실패",
+17
View File
@@ -286,6 +286,23 @@ export default {
docSearchPlaceholder: 'Поиск документов...',
fileTypeFilter: 'Тип файла',
allFileTypes: 'Все типы',
parseStatusFilter: 'Статус',
allParseStatuses: 'Все статусы',
parseStatusPending: 'Ожидание',
parseStatusProcessing: 'Обработка',
parseStatusCompleted: 'Завершено',
parseStatusFailed: 'Ошибка',
sourceFilter: 'Источник',
allSources: 'Все источники',
sourceWeb: 'Веб',
sourceApi: 'API',
sourceBrowserExtension: 'Расширение браузера',
sourceUpload: 'Загрузка',
sourceUrl: 'URL импорт',
sourceManual: 'Создан вручную',
updatedTimeFilter: 'Обновлено',
updatedTimeFrom: 'С',
updatedTimeTo: 'По',
noMatch: 'Совпадающих баз знаний не найдено',
noKnowledge: 'Нет доступных баз знаний',
loadingFailed: 'Не удалось загрузить базы знаний',
+17
View File
@@ -319,6 +319,23 @@ export default {
docSearchPlaceholder: "搜索文档名称...",
fileTypeFilter: "文件类型",
allFileTypes: "全部类型",
parseStatusFilter: "解析状态",
allParseStatuses: "全部状态",
parseStatusPending: "等待中",
parseStatusProcessing: "处理中",
parseStatusCompleted: "已完成",
parseStatusFailed: "失败",
sourceFilter: "来源",
allSources: "全部来源",
sourceWeb: "网页",
sourceApi: "API",
sourceBrowserExtension: "浏览器扩展",
sourceUpload: "本地上传",
sourceUrl: "URL 导入",
sourceManual: "手动创建",
updatedTimeFilter: "更新时间",
updatedTimeFrom: "起始时间",
updatedTimeTo: "结束时间",
noMatch: "未找到匹配的知识库",
noKnowledge: "暂无可用知识库",
loadingFailed: "加载知识库失败",
+161 -49
View File
@@ -307,22 +307,65 @@ 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: 'PPTX', value: 'pptx' },
{ content: 'PPT', value: 'ppt' },
{ content: 'TXT', value: 'txt' },
{ content: 'MD', value: 'md' },
{ content: 'URL', value: 'url' },
{ content: t('knowledgeBase.typeManual'), value: 'manual' },
{ content: 'MP3', value: 'mp3' },
{ content: 'WAV', value: 'wav' },
{ content: 'M4A', value: 'm4a' },
{ content: 'FLAC', value: 'flac' },
{ content: 'OGG', value: 'ogg' },
{ label: t('knowledgeBase.allFileTypes'), value: '' },
{ label: 'PDF', value: 'pdf' },
{ label: 'DOCX', value: 'docx' },
{ label: 'DOC', value: 'doc' },
{ label: 'PPTX', value: 'pptx' },
{ label: 'PPT', value: 'ppt' },
{ label: 'TXT', value: 'txt' },
{ label: 'MD', value: 'md' },
{ label: 'URL', value: 'url' },
{ label: t('knowledgeBase.typeManual'), value: 'manual' },
{ label: 'MP3', value: 'mp3' },
{ label: 'WAV', value: 'wav' },
{ label: 'M4A', value: 'm4a' },
{ label: 'FLAC', value: 'flac' },
{ label: 'OGG', value: 'ogg' },
]);
const selectedParseStatus = ref('');
const parseStatusOptions = computed(() => [
{ label: t('knowledgeBase.allParseStatuses'), value: '' },
{ label: t('knowledgeBase.parseStatusPending'), value: 'pending' },
{ label: t('knowledgeBase.parseStatusProcessing'), value: 'processing' },
{ label: t('knowledgeBase.parseStatusCompleted'), value: 'completed' },
{ label: t('knowledgeBase.parseStatusFailed'), value: 'failed' },
]);
const selectedSource = ref('');
// Source filter combines ingestion channels and the "manual"/"url" virtual
// sources that the backend routes onto the `type` column.
const sourceOptions = computed(() => [
{ label: t('knowledgeBase.allSources'), value: '' },
{ label: t('knowledgeBase.sourceUpload'), value: 'web' },
{ label: t('knowledgeBase.sourceUrl'), value: 'url' },
{ label: t('knowledgeBase.sourceManual'), value: 'manual' },
{ label: t('knowledgeBase.sourceApi'), value: 'api' },
{ label: t('knowledgeBase.sourceBrowserExtension'), value: 'browser_extension' },
{ label: t('knowledgeBase.channelFeishu'), value: 'feishu' },
{ label: t('knowledgeBase.channelNotion'), value: 'notion' },
{ label: t('knowledgeBase.channelYuque'), value: 'yuque' },
{ label: t('knowledgeBase.channelWechat'), value: 'wechat' },
{ label: t('knowledgeBase.channelWecom'), value: 'wecom' },
{ label: t('knowledgeBase.channelDingtalk'), value: 'dingtalk' },
{ label: t('knowledgeBase.channelSlack'), value: 'slack' },
{ label: t('knowledgeBase.channelIm'), value: 'im' },
]);
// Date range as [start, end] in "YYYY-MM-DD" form (t-date-range-picker default).
const updatedTimeRange = ref<string[]>([]);
// Disable any date after today so users cannot filter into the future.
const disableFutureDate = { after: new Date(new Date().setHours(23, 59, 59, 999)) };
const filterParams = computed(() => {
const [start, end] = updatedTimeRange.value || [];
return {
tag_id: selectedTagId.value || undefined,
keyword: docSearchKeyword.value ? docSearchKeyword.value.trim() : undefined,
file_type: selectedFileType.value || undefined,
parse_status: selectedParseStatus.value || undefined,
source: selectedSource.value || undefined,
start_time: start ? `${start} 00:00:00` : undefined,
end_time: end ? `${end} 23:59:59` : undefined,
};
});
type TagInputInstance = ComponentPublicInstance<{ focus: () => void; select: () => void }>;
const tagDropdownOptions = computed(() =>
tagList.value.map((tag: any) => ({
@@ -419,9 +462,7 @@ const loadKnowledgeFiles = (kbIdValue: string): Promise<void> => {
{
page: 1,
page_size: pageSize,
tag_id: selectedTagId.value || undefined,
keyword: docSearchKeyword.value ? docSearchKeyword.value.trim() : undefined,
file_type: selectedFileType.value || undefined,
...filterParams.value,
},
kbIdValue,
);
@@ -763,6 +804,14 @@ watch(selectedFileType, (newVal, oldVal) => {
}
});
// 监听解析状态/来源/更新时间范围筛选变化(与文件类型行为一致)
watch([selectedParseStatus, selectedSource, updatedTimeRange], () => {
if (kbId.value) {
page = 1;
loadKnowledgeFiles(kbId.value);
}
}, { deep: true });
// 监听文件上传事件
const handleFileUploaded = (event: CustomEvent) => {
const uploadedKbId = event.detail.kbId;
@@ -1625,7 +1674,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, keyword: docSearchKeyword.value ? docSearchKeyword.value.trim() : undefined, file_type: selectedFileType.value || undefined });
getKnowled({ page, page_size: pageSize, ...filterParams.value });
}
}
}
@@ -1680,6 +1729,42 @@ const clearSelection = () => {
lastSelectedIndex = -1;
};
// Batch (multi-select) mode mirrors the session list's "批量管理" UX: while off,
// no checkbox is rendered so the title doesn't jitter on hover; while on,
// checkboxes are persistent and clicking a card toggles its selection.
const batchMode = ref(false);
const toggleBatchMode = () => {
batchMode.value = !batchMode.value;
if (!batchMode.value) clearSelection();
};
// "取消选择" / 退出批量管理:清空选择,并退出 grid 视图下的批量模式。
const handleBatchCancel = () => {
clearSelection();
batchMode.value = false;
};
// 切到卡片视图时,如果列表视图里已经勾选过文档,需要自动开启批量管理模式,
// 否则卡片视图默认不渲染 checkbox,会看不到勾选态。
watch(viewMode, (mode) => {
if (mode === 'grid' && selectedIds.value.size > 0) {
batchMode.value = true;
}
});
// Triggered from a card / row "..." menu — match the session-list UX where
// the menu item simply opens batch mode (no auto-selection).
const handleEnterBatchFromCard = (item: any) => {
if (item) item.isMore = false;
moreIndex.value = -1;
clearSelection();
batchMode.value = true;
};
const onCardClick = (item: any) => {
if (batchMode.value) {
onCardGridCheckboxChange(item.id, !selectedIds.value.has(item.id));
} else {
openCardDetails(item);
}
};
const openBatchDeleteDialog = () => {
if (selectedIds.value.size === 0) return;
batchDeleteDialog.value = true;
@@ -1695,6 +1780,7 @@ const confirmBatchDelete = async () => {
if (res?.success) {
MessagePlugin.success(t('knowledgeBase.batchDeleteSuccess', { count: ids.length }));
clearSelection();
batchMode.value = false;
batchDeleteDialog.value = false;
page = 1;
// 后端将批量删除放入异步队列,立刻拉列表仍可能包含待删项;短轮询直到列表与后端一致或超时
@@ -1730,9 +1816,12 @@ const handleListAction = (
};
// Clear selection on filter/tag/kb change to avoid acting on hidden items.
watch([selectedTagId, docSearchKeyword, selectedFileType, kbId], () => {
clearSelection();
});
watch(
[selectedTagId, docSearchKeyword, selectedFileType, selectedParseStatus, selectedSource, updatedTimeRange, kbId],
() => {
clearSelection();
},
);
// After cardList reloads: stable keys rely on correct indices for shift-range; clamp anchor index.
watch(cardList, () => {
@@ -2130,6 +2219,28 @@ async function createNewSession(value: string): Promise<void> {
class="doc-type-select"
clearable
/>
<t-select
v-model="selectedParseStatus"
:options="parseStatusOptions"
:placeholder="$t('knowledgeBase.parseStatusFilter')"
class="doc-type-select"
clearable
/>
<t-select
v-model="selectedSource"
:options="sourceOptions"
:placeholder="$t('knowledgeBase.sourceFilter')"
class="doc-type-select"
clearable
/>
<t-date-range-picker
v-model="updatedTimeRange"
:placeholder="[$t('knowledgeBase.updatedTimeFrom'), $t('knowledgeBase.updatedTimeTo')]"
:disable-date="disableFutureDate"
class="doc-date-range"
clearable
allow-input
/>
<div class="doc-view-toggle" role="group" :aria-label="$t('knowledgeBase.viewModeToggle')">
<t-tooltip :content="$t('knowledgeBase.viewModeGrid')" placement="top">
<button
@@ -2194,10 +2305,10 @@ async function createNewSession(value: string): Promise<void> {
<!-- 现有文档卡片 -->
<div
class="knowledge-card"
:class="{ 'is-selected': selectedIds.has(item.id), 'has-selection': selectedIds.size > 0 }"
:class="{ 'is-selected': selectedIds.has(item.id), 'batch-mode': batchMode }"
v-for="(item, index) in cardList"
:key="item.id"
@click="openCardDetails(item)"
@click="onCardClick(item)"
@mouseenter="onCardMouseEnter($event, item)"
@mousemove="onCardMouseMove($event)"
@mouseleave="onCardMouseLeave"
@@ -2205,9 +2316,8 @@ async function createNewSession(value: string): Promise<void> {
<div class="card-content">
<div class="card-content-nav">
<div
v-if="canEdit"
v-if="canEdit && batchMode"
class="card-nav-check"
:class="{ active: selectedIds.has(item.id) }"
@click.stop
>
<t-checkbox
@@ -2255,6 +2365,10 @@ async function createNewSession(value: string): Promise<void> {
<t-icon class="icon" name="swap" />
<span>{{ t('knowledgeBase.moveDocument') }}</span>
</div>
<div class="card-menu-item" @click.stop="handleEnterBatchFromCard(item)">
<t-icon class="icon" name="queue" />
<span>{{ t('menu.batchManage') }}</span>
</div>
<div class="card-menu-item danger" @click.stop="delCard(index, item)">
<t-icon class="icon" name="delete" />
<span>{{ t('knowledgeBase.deleteDocument') }}</span>
@@ -2442,11 +2556,12 @@ async function createNewSession(value: string): Promise<void> {
</div>
</template>
</div>
<div class="doc-batch-bar-anchor" v-show="selectedIds.size > 0">
<div class="doc-batch-bar-anchor" v-show="batchMode || selectedIds.size > 0">
<DocumentBatchBar
:count="selectedIds.size"
:loading="batchDeleting"
@clear="clearSelection"
:visible="batchMode || selectedIds.size > 0"
@cancel="handleBatchCancel"
@delete="openBatchDeleteDialog"
/>
</div>
@@ -3063,10 +3178,11 @@ async function createNewSession(value: string): Promise<void> {
display: flex;
gap: 12px;
align-items: center;
flex-wrap: wrap;
.doc-search-input {
flex: 1;
min-width: 0;
flex: 1 1 220px;
min-width: 220px;
}
.doc-type-select {
@@ -3074,6 +3190,18 @@ async function createNewSession(value: string): Promise<void> {
flex-shrink: 0;
}
.doc-date-range {
width: 280px;
flex-shrink: 0;
// TDesign focuses both the outer popup reference and inner inputs, which
// visually stacks into a "double border" — drop the inner shadow.
:deep(.t-input--focused),
:deep(.t-is-focused) {
box-shadow: none;
}
}
.doc-view-toggle {
flex-shrink: 0;
display: inline-flex;
@@ -3854,26 +3982,17 @@ async function createNewSession(value: string): Promise<void> {
cursor: pointer;
transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
/* 默认折叠不占位,悬停/多选/已选时展开,避免非选择态左侧错位 */
/* 仅在批量管理模式下渲染 checkbox,常态下不占位,避免标题在 hover 时右滑 */
.card-nav-check {
flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
width: 0;
width: 22px;
height: 29px;
margin-right: 0;
opacity: 0;
overflow: hidden;
transition: width 0.2s ease, margin-right 0.2s ease, opacity 0.2s ease;
margin-right: 8px;
cursor: pointer;
&.active {
width: 22px;
margin-right: 8px;
opacity: 1;
}
.card-select-checkbox {
margin: 0;
line-height: 0;
@@ -3900,13 +4019,6 @@ async function createNewSession(value: string): Promise<void> {
}
}
&:hover .card-nav-check,
&.has-selection .card-nav-check {
width: 22px;
margin-right: 8px;
opacity: 1;
}
.card-content {
flex: 1;
min-height: 0;
@@ -4,10 +4,13 @@ import { useI18n } from 'vue-i18n';
defineProps<{
count: number;
loading?: boolean;
// When true the bar stays visible even with 0 selections, so users can exit
// batch mode from here without selecting anything first.
visible?: boolean;
}>();
const emit = defineEmits<{
(e: 'clear'): void;
(e: 'cancel'): void;
(e: 'delete'): void;
}>();
@@ -16,11 +19,22 @@ const { t } = useI18n();
<template>
<transition name="batch-bar-fade">
<div v-if="count > 0" class="doc-batch-bar" role="region" :aria-label="t('knowledgeBase.selectedCount', { count })">
<div
v-if="visible || count > 0"
class="doc-batch-bar"
role="region"
:aria-label="t('knowledgeBase.selectedCount', { count })"
>
<div class="batch-bar-inner">
<div class="batch-bar-left">
<span class="batch-bar-count">{{ t('knowledgeBase.selectedCount', { count }) }}</span>
<t-button variant="text" theme="default" size="small" class="batch-bar-clear" @click="emit('clear')">
<t-button
variant="text"
theme="default"
size="small"
class="batch-bar-clear"
@click="emit('cancel')"
>
{{ t('knowledgeBase.clearSelection') }}
</t-button>
</div>
@@ -29,6 +43,7 @@ const { t } = useI18n();
theme="danger"
variant="outline"
size="small"
:disabled="count === 0"
:loading="loading"
@click="emit('delete')"
>