From c697f6d9e48d5218e6809960cc6051e0d22ec3dc Mon Sep 17 00:00:00 2001 From: wizardchen Date: Wed, 12 Aug 2026 13:21:29 +0800 Subject: [PATCH] fix(frontend): harden document chunk pagination state handling Align segment labels with loaded page data, surface API failures during page transitions, and show a loading state while chunk pages are fetching. --- frontend/src/api/knowledge-base/index.ts | 4 +- frontend/src/components/doc-content.vue | 47 ++++++++++++++++++------ frontend/src/hooks/useKnowledgeBase.ts | 4 +- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/frontend/src/api/knowledge-base/index.ts b/frontend/src/api/knowledge-base/index.ts index eb70e032..323d87c9 100644 --- a/frontend/src/api/knowledge-base/index.ts +++ b/frontend/src/api/knowledge-base/index.ts @@ -391,8 +391,10 @@ export function batchQueryKnowledge(idsQueryString: string, kbId?: string, agent return get(`/api/v1/knowledge/batch?${qs}`); } +export const KNOWLEDGE_CHUNK_PAGE_SIZE = 25; + export function getKnowledgeDetailsCon(id: string, page: number) { - return get(`/api/v1/chunks/${id}?page=${page}&page_size=25`); + return get(`/api/v1/chunks/${id}?page=${page}&page_size=${KNOWLEDGE_CHUNK_PAGE_SIZE}`); } export interface ChunkEditPayload { diff --git a/frontend/src/components/doc-content.vue b/frontend/src/components/doc-content.vue index ab12dfc8..f2f52f74 100644 --- a/frontend/src/components/doc-content.vue +++ b/frontend/src/components/doc-content.vue @@ -12,6 +12,7 @@ import { downKnowledgeDetails, deleteGeneratedQuestion, getChunkByIdOnly, previewKnowledgeFile, updateDocumentChunk, listChunkRevisions, revertDocumentChunk, updateKnowledgeMetadata, regenerateKnowledgeSummary, upsertGeneratedQuestion, regenerateGeneratedQuestions, getKnowledgeDetails, + KNOWLEDGE_CHUNK_PAGE_SIZE, } from "@/api/knowledge-base/index"; import { MessagePlugin } from "tdesign-vue-next"; import { sanitizeHTML, safeMarkdownToHTML, createSafeImage, isValidImageURL, hydrateProtectedFileImages, isValidURL } from '@/utils/security'; @@ -496,10 +497,13 @@ const preprocessMathDelimiters = (rawText: string): string => { .replace(/\\\(([\s\S]*?)\\\)/g, '$$$1$$'); }; const renderer = new marked.Renderer(); -const CHUNK_PAGE_SIZE = 25; +const CHUNK_PAGE_SIZE = KNOWLEDGE_CHUNK_PAGE_SIZE; const chunkPage = ref(1); -let loadedChunkPage = 1; +const loadedChunkPage = ref(1); let pendingChunkPage: number | null = null; +const isChunkPageTransition = computed( + () => Boolean(props.details?.chunkLoading) && chunkPage.value !== loadedChunkPage.value, +); let mdContentWrap = ref() // Drawer uses attach="body", so markdown nodes live outside mdContentWrap in the DOM. const docMarkdownRoot = ref(null) @@ -594,16 +598,16 @@ onMounted(() => { watch(() => props.details?.id, () => { chunkPage.value = 1; - loadedChunkPage = 1; + loadedChunkPage.value = 1; pendingChunkPage = null; }); watch(() => props.details?.chunkLoading, (val) => { if (val === false && pendingChunkPage !== null) { if (props.details?.chunkLoadError) { - chunkPage.value = loadedChunkPage; + chunkPage.value = loadedChunkPage.value; MessagePlugin.warning(props.details.chunkLoadError); } else { - loadedChunkPage = pendingChunkPage; + loadedChunkPage.value = pendingChunkPage; } pendingChunkPage = null; } @@ -1520,7 +1524,7 @@ const downloadFile = () => { }); }; const handleChunkPageChange = (pageInfo: { current: number }) => { - if (props.details?.chunkLoading || pageInfo.current === loadedChunkPage) return; + if (props.details?.chunkLoading || pageInfo.current === loadedChunkPage.value) return; pendingChunkPage = pageInfo.current; emit('getDoc', pageInfo.current); }; @@ -1786,19 +1790,30 @@ const handleChunkPageChange = (pageInfo: { current: number }) => {
-
{{ $t('common.noData') }}
-
+
+ + {{ $t('common.loading') }} +
+
-
{{ $t('common.noData') }}
-
+
+ + {{ $t('common.loading') }} +
+
@@ -2089,6 +2105,15 @@ const handleChunkPageChange = (pageInfo: { current: number }) => { border-top: 1px solid var(--td-component-stroke); } +.chunk-page-loading { + display: flex; + align-items: center; + justify-content: center; + gap: 8px; + min-height: 120px; + color: var(--td-text-color-secondary); +} + .icon-action-btn { width: 28px; min-width: 28px; diff --git a/frontend/src/hooks/useKnowledgeBase.ts b/frontend/src/hooks/useKnowledgeBase.ts index b4b8c243..1e379917 100644 --- a/frontend/src/hooks/useKnowledgeBase.ts +++ b/frontend/src/hooks/useKnowledgeBase.ts @@ -237,10 +237,12 @@ export default function (knowledgeBaseId?: string) { const { data, total: totalResult } = result; details.md = data; details.total = totalResult; + } else { + details.chunkLoadError = result?.message || result?.error?.message || t('knowledgeBase.chunkLoadFailed'); } }) .catch((err: any) => { - if (requestGeneration !== chunkRequestGeneration) return; + if (requestGeneration !== chunkRequestGeneration || activeKnowledgeId !== id) return; details.chunkLoadError = err?.message || t('knowledgeBase.chunkLoadFailed'); console.error("[ChunkLoad] failed", { knowledgeId: id,