From cacca049d9543d49b11a326b3ac8235ea935544b Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 12 May 2026 18:16:34 +0800 Subject: [PATCH] feat(knowledge-base): document list filters and explicit batch-management UX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- client/knowledge.go | 63 +++++- docs/api/knowledge.md | 18 +- docs/docs.go | 34 ++- docs/swagger.json | 34 ++- docs/swagger.yaml | 24 ++ frontend/src/api/knowledge-base/index.ts | 28 ++- frontend/src/hooks/useKnowledgeBase.ts | 12 +- frontend/src/i18n/locales/en-US.ts | 17 ++ frontend/src/i18n/locales/ko-KR.ts | 17 ++ frontend/src/i18n/locales/ru-RU.ts | 17 ++ frontend/src/i18n/locales/zh-CN.ts | 17 ++ .../src/views/knowledge/KnowledgeBase.vue | 210 ++++++++++++++---- .../knowledge/components/DocumentBatchBar.vue | 21 +- internal/application/repository/knowledge.go | 95 ++++---- internal/application/service/agent_service.go | 2 +- internal/application/service/knowledge.go | 42 ++-- internal/handler/initialization.go | 6 +- internal/handler/knowledge.go | 70 +++++- internal/types/interfaces/knowledge.go | 22 +- internal/types/knowledge.go | 21 ++ 20 files changed, 596 insertions(+), 174 deletions(-) diff --git a/client/knowledge.go b/client/knowledge.go index 6d9ec8d4..fb31acfa 100644 --- a/client/knowledge.go +++ b/client/knowledge.go @@ -278,20 +278,65 @@ func (c *Client) GetKnowledgeBatch(ctx context.Context, knowledgeIDs []string) ( return response.Data, nil } -// ListKnowledge lists knowledge entries in a knowledge base with pagination +// ListKnowledge lists knowledge entries in a knowledge base with pagination. +// For richer filtering (keyword, file type, parse status, source, time range) +// use ListKnowledgeWithFilter. func (c *Client) ListKnowledge(ctx context.Context, knowledgeBaseID string, page int, pageSize int, tagID string, +) ([]Knowledge, int64, error) { + return c.ListKnowledgeWithFilter(ctx, knowledgeBaseID, page, pageSize, KnowledgeListFilter{TagID: tagID}) +} + +// KnowledgeListFilter mirrors the server-side filters accepted by GET +// /api/v1/knowledge-bases/{id}/knowledge. Empty / zero fields are omitted from +// the request. +type KnowledgeListFilter struct { + TagID string + Keyword string + FileType string + ParseStatus string + Source string + // StartTime / EndTime filter on knowledge updated_at. Zero values are skipped. + // They are serialized in RFC3339 format. + StartTime time.Time + EndTime time.Time +} + +// ListKnowledgeWithFilter lists knowledge entries with the full filter surface. +func (c *Client) ListKnowledgeWithFilter(ctx context.Context, + knowledgeBaseID string, + page int, + pageSize int, + filter KnowledgeListFilter, ) ([]Knowledge, int64, error) { path := fmt.Sprintf("/api/v1/knowledge-bases/%s/knowledge", knowledgeBaseID) queryParams := url.Values{} queryParams.Add("page", strconv.Itoa(page)) queryParams.Add("page_size", strconv.Itoa(pageSize)) - if tagID != "" { - queryParams.Add("tag_id", tagID) + if filter.TagID != "" { + queryParams.Add("tag_id", filter.TagID) + } + if filter.Keyword != "" { + queryParams.Add("keyword", filter.Keyword) + } + if filter.FileType != "" { + queryParams.Add("file_type", filter.FileType) + } + if filter.ParseStatus != "" { + queryParams.Add("parse_status", filter.ParseStatus) + } + if filter.Source != "" { + queryParams.Add("source", filter.Source) + } + if !filter.StartTime.IsZero() { + queryParams.Add("start_time", filter.StartTime.Format(time.RFC3339)) + } + if !filter.EndTime.IsZero() { + queryParams.Add("end_time", filter.EndTime.Format(time.RFC3339)) } resp, err := c.doRequest(ctx, http.MethodGet, path, nil, queryParams) @@ -439,8 +484,8 @@ func (c *Client) UpdateImageInfo(ctx context.Context, // CreateManualKnowledgeRequest contains the parameters for creating a manual Markdown knowledge entry. type CreateManualKnowledgeRequest struct { - Title string `json:"title"` - Content string `json:"content"` + Title string `json:"title"` + Content string `json:"content"` TagID string `json:"tag_id,omitempty"` Channel string `json:"channel,omitempty"` } @@ -550,8 +595,8 @@ func (c *Client) MoveKnowledge(ctx context.Context, req *MoveKnowledgeRequest) ( } var result struct { - Success bool `json:"success"` - Data *MoveKnowledgeResponse `json:"data"` + Success bool `json:"success"` + Data *MoveKnowledgeResponse `json:"data"` } if err := parseResponse(resp, &result); err != nil { return nil, err @@ -579,8 +624,8 @@ func (c *Client) GetKnowledgeMoveProgress(ctx context.Context, taskID string) (* } var result struct { - Success bool `json:"success"` - Data *KnowledgeMoveProgress `json:"data"` + Success bool `json:"success"` + Data *KnowledgeMoveProgress `json:"data"` } if err := parseResponse(resp, &result); err != nil { return nil, err diff --git a/docs/api/knowledge.md b/docs/api/knowledge.md index 5ecd2d57..48b071df 100644 --- a/docs/api/knowledge.md +++ b/docs/api/knowledge.md @@ -258,13 +258,17 @@ curl --location 'http://localhost:8080/api/v1/knowledge-bases/kb-00000001/knowle **查询参数**: -| 字段 | 类型 | 默认 | 说明 | -| ----------- | ------- | ---- | ----------------------------------- | -| `page` | integer | 1 | 页码(从 1 开始) | -| `page_size` | integer | 20 | 每页条数 | -| `tag_id` | string | - | 按标签 ID 过滤 | -| `keyword` | string | - | 按标题/内容关键词过滤 | -| `file_type` | string | - | 按单个文件扩展名过滤(如 `pdf`) | +| 字段 | 类型 | 默认 | 说明 | +| -------------- | ------- | ---- | --------------------------------------------------------------------------------------------------- | +| `page` | integer | 1 | 页码(从 1 开始) | +| `page_size` | integer | 20 | 每页条数 | +| `tag_id` | string | - | 按标签 ID 过滤 | +| `keyword` | string | - | 按标题/内容关键词过滤 | +| `file_type` | string | - | 按单个文件扩展名过滤(如 `pdf`);特殊值 `manual` / `url` 命中 `type` 列 | +| `parse_status` | string | - | 按解析状态过滤:`pending` / `processing` / `completed` / `failed` | +| `source` | string | - | 按来源/渠道过滤:`web` / `api` / `browser_extension` / `feishu` / `notion` / `yuque` / `wechat` 等; 特殊值 `manual` / `url` 命中 `type` 列 | +| `start_time` | string | - | 更新时间起点,接受 RFC3339 (`2024-05-01T00:00:00+08:00`) 或 `YYYY-MM-DD HH:MM:SS` / `YYYY-MM-DD` | +| `end_time` | string | - | 更新时间终点,格式同 `start_time` | **请求**: diff --git a/docs/docs.go b/docs/docs.go index f9cb6f34..e9024861 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -5097,6 +5097,30 @@ const docTemplate = `{ "description": "文件类型筛选", "name": "file_type", "in": "query" + }, + { + "type": "string", + "description": "解析状态筛选 (pending/processing/completed/failed)", + "name": "parse_status", + "in": "query" + }, + { + "type": "string", + "description": "来源/渠道筛选 (web/api/feishu/notion/yuque/wechat/...,或 manual/url 按 type 过滤)", + "name": "source", + "in": "query" + }, + { + "type": "string", + "description": "更新时间起点,RFC3339 格式", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "description": "更新时间终点,RFC3339 格式", + "name": "end_time", + "in": "query" } ], "responses": { @@ -15217,6 +15241,10 @@ const docTemplate = `{ "description": "API key for the search provider (encrypted in DB)", "type": "string" }, + "base_url": { + "description": "Base URL for self-hosted search engines (e.g. SearXNG instance URL).\nValidated with utils.ValidateURLForSSRF; private hosts must be added to SSRF_WHITELIST.", + "type": "string" + }, "engine_id": { "description": "Google Custom Search Engine ID (only for Google provider)", "type": "string" @@ -15242,7 +15270,8 @@ const docTemplate = `{ "duckduckgo", "tavily", "ollama", - "baidu" + "baidu", + "searxng" ], "x-enum-varnames": [ "WebSearchProviderTypeBing", @@ -15250,7 +15279,8 @@ const docTemplate = `{ "WebSearchProviderTypeDuckDuckGo", "WebSearchProviderTypeTavily", "WebSearchProviderTypeOllama", - "WebSearchProviderTypeBaidu" + "WebSearchProviderTypeBaidu", + "WebSearchProviderTypeSearxng" ] }, "github_com_Tencent_WeKnora_internal_types.WikiConfig": { diff --git a/docs/swagger.json b/docs/swagger.json index 960ddc71..e87f24d3 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -5090,6 +5090,30 @@ "description": "文件类型筛选", "name": "file_type", "in": "query" + }, + { + "type": "string", + "description": "解析状态筛选 (pending/processing/completed/failed)", + "name": "parse_status", + "in": "query" + }, + { + "type": "string", + "description": "来源/渠道筛选 (web/api/feishu/notion/yuque/wechat/...,或 manual/url 按 type 过滤)", + "name": "source", + "in": "query" + }, + { + "type": "string", + "description": "更新时间起点,RFC3339 格式", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "description": "更新时间终点,RFC3339 格式", + "name": "end_time", + "in": "query" } ], "responses": { @@ -15210,6 +15234,10 @@ "description": "API key for the search provider (encrypted in DB)", "type": "string" }, + "base_url": { + "description": "Base URL for self-hosted search engines (e.g. SearXNG instance URL).\nValidated with utils.ValidateURLForSSRF; private hosts must be added to SSRF_WHITELIST.", + "type": "string" + }, "engine_id": { "description": "Google Custom Search Engine ID (only for Google provider)", "type": "string" @@ -15235,7 +15263,8 @@ "duckduckgo", "tavily", "ollama", - "baidu" + "baidu", + "searxng" ], "x-enum-varnames": [ "WebSearchProviderTypeBing", @@ -15243,7 +15272,8 @@ "WebSearchProviderTypeDuckDuckGo", "WebSearchProviderTypeTavily", "WebSearchProviderTypeOllama", - "WebSearchProviderTypeBaidu" + "WebSearchProviderTypeBaidu", + "WebSearchProviderTypeSearxng" ] }, "github_com_Tencent_WeKnora_internal_types.WikiConfig": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index f78feeba..c3b2557b 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -2986,6 +2986,11 @@ definitions: api_key: description: API key for the search provider (encrypted in DB) type: string + base_url: + description: |- + Base URL for self-hosted search engines (e.g. SearXNG instance URL). + Validated with utils.ValidateURLForSSRF; private hosts must be added to SSRF_WHITELIST. + type: string engine_id: description: Google Custom Search Engine ID (only for Google provider) type: string @@ -3008,6 +3013,7 @@ definitions: - tavily - ollama - baidu + - searxng type: string x-enum-varnames: - WebSearchProviderTypeBing @@ -3016,6 +3022,7 @@ definitions: - WebSearchProviderTypeTavily - WebSearchProviderTypeOllama - WebSearchProviderTypeBaidu + - WebSearchProviderTypeSearxng github_com_Tencent_WeKnora_internal_types.WikiConfig: properties: extraction_granularity: @@ -7478,6 +7485,23 @@ paths: in: query name: file_type type: string + - description: 解析状态筛选 (pending/processing/completed/failed) + in: query + name: parse_status + type: string + - description: 来源/渠道筛选 (web/api/feishu/notion/yuque/wechat/...,或 manual/url + 按 type 过滤) + in: query + name: source + type: string + - description: 更新时间起点,RFC3339 格式 + in: query + name: start_time + type: string + - description: 更新时间终点,RFC3339 格式 + in: query + name: end_time + type: string produces: - application/json responses: diff --git a/frontend/src/api/knowledge-base/index.ts b/frontend/src/api/knowledge-base/index.ts index 0caa32ee..61b6bb38 100644 --- a/frontend/src/api/knowledge-base/index.ts +++ b/frontend/src/api/knowledge-base/index.ts @@ -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}`); } diff --git a/frontend/src/hooks/useKnowledgeBase.ts b/frontend/src/hooks/useKnowledgeBase.ts index 58e70893..239cb572 100644 --- a/frontend/src/hooks/useKnowledgeBase.ts +++ b/frontend/src/hooks/useKnowledgeBase.ts @@ -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 => { const targetKbId = kbId || knowledgeBaseId; diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 7675c9fa..bc3dcfc0 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -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', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 616e9e43..1623c0de 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -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: "지식베이스 로드 실패", diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 8b9d8b3b..544b4d5e 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -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: 'Не удалось загрузить базы знаний', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index c285e561..1cbd287b 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -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: "加载知识库失败", diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue index db6270ba..0751bb8e 100644 --- a/frontend/src/views/knowledge/KnowledgeBase.vue +++ b/frontend/src/views/knowledge/KnowledgeBase.vue @@ -307,22 +307,65 @@ let docSearchDebounce: ReturnType | 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([]); +// 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 => { { 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 { class="doc-type-select" clearable /> + + +