From 378523c4973a924edff94d9abb05d3432d7052e6 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 28 Jul 2026 15:04:28 +0800 Subject: [PATCH] refactor(knowledge): move chunk details into header popups --- frontend/src/components/doc-content.vue | 471 ++++++++++++------------ 1 file changed, 239 insertions(+), 232 deletions(-) diff --git a/frontend/src/components/doc-content.vue b/frontend/src/components/doc-content.vue index ca6a08b2..20a71516 100644 --- a/frontend/src/components/doc-content.vue +++ b/frontend/src/components/doc-content.vue @@ -998,21 +998,6 @@ const getGeneratedQuestions = (item: any): GeneratedQuestion[] => { } }; -// 展开状态管理 -const expandedChunks = ref>(new Set()); - -const toggleQuestions = (index: number) => { - if (expandedChunks.value.has(index)) { - expandedChunks.value.delete(index); - } else { - expandedChunks.value.add(index); - } - // 触发响应式更新 - expandedChunks.value = new Set(expandedChunks.value); -}; - -const isExpanded = (index: number) => expandedChunks.value.has(index); - const editingChunkId = ref(''); const chunkDraft = ref(''); const savingChunkId = ref(''); @@ -1102,7 +1087,11 @@ const showChunkHistory = async (item: any) => { const setChunkHistoryPopupVisible = (item: any, visible: boolean) => { chunkHistoryPopup.value = visible ? item.id : ''; - if (visible) showChunkHistory(item); + if (visible) { + parentContextPopup.value = ''; + questionPopupChunk.value = ''; + showChunkHistory(item); + } }; const selectChunkRevision = (item: any, revision: number) => { @@ -1168,6 +1157,7 @@ const revertChunk = async (item: any, revision: number) => { const questionDrafts = ref>({}); const savingQuestionChunk = ref(''); const regeneratingQuestionChunk = ref(''); +const questionPopupChunk = ref(''); const questionComposerChunk = ref(''); const editingQuestionKey = ref(''); const questionEditDraft = ref(''); @@ -1177,14 +1167,26 @@ watch(() => props.details?.id, () => { metadataEditing.value = false; editingChunkId.value = ''; chunkHistoryPopup.value = ''; + parentContextPopup.value = ''; + questionPopupChunk.value = ''; questionComposerChunk.value = ''; editingQuestionKey.value = ''; }); -const openQuestionComposer = (item: any, index: number) => { +const setQuestionPopupVisible = (item: any, visible: boolean) => { + questionPopupChunk.value = visible ? item.id : ''; + if (visible) { + parentContextPopup.value = ''; + chunkHistoryPopup.value = ''; + } else { + closeQuestionComposer(item); + cancelQuestionEdit(); + } +}; + +const openQuestionComposer = (item: any) => { + questionPopupChunk.value = item.id; questionComposerChunk.value = item.id; - expandedChunks.value.add(index); - expandedChunks.value = new Set(expandedChunks.value); }; const closeQuestionComposer = (item: any) => { @@ -1242,7 +1244,7 @@ const saveQuestionEdit = async (item: any, question: GeneratedQuestion) => { } }; -const regenerateQuestions = async (item: any, index?: number) => { +const regenerateQuestions = async (item: any) => { regeneratingQuestionChunk.value = item.id; try { const result: any = await regenerateGeneratedQuestions(item.id); @@ -1251,10 +1253,6 @@ const regenerateQuestions = async (item: any, index?: number) => { metadata.generated_questions_revision = item.content_revision || 0; item.metadata = metadata; questionComposerChunk.value = ''; - if (typeof index === 'number') { - expandedChunks.value.add(index); - expandedChunks.value = new Set(expandedChunks.value); - } MessagePlugin.success(t('knowledgeBase.questionsRegenerated')); } catch (error: any) { MessagePlugin.error(error?.message || t('common.error')); @@ -1308,22 +1306,14 @@ const isDeleting = (chunkIndex: number, questionId: string) => { return deletingQuestion.value?.chunkIndex === chunkIndex && deletingQuestion.value?.questionId === questionId; }; -// 父 Chunk 上下文展开状态 -const parentContextExpanded = ref>(new Set()); +// 父 Chunk 上下文通过 Header Popup 展示,避免在每个分块下方占用高度。 +const parentContextPopup = ref(''); const parentContextCache = ref>(new Map()); const parentContextLoading = ref>(new Set()); const hasParentChunk = (item: any) => !!item?.parent_chunk_id; -const isParentExpanded = (index: number) => parentContextExpanded.value.has(index); - -const toggleParentContext = async (item: any, index: number) => { - if (parentContextExpanded.value.has(index)) { - parentContextExpanded.value.delete(index); - parentContextExpanded.value = new Set(parentContextExpanded.value); - return; - } - +const loadParentContext = async (item: any, index: number) => { const parentId = item.parent_chunk_id; if (!parentContextCache.value.has(parentId)) { parentContextLoading.value.add(index); @@ -1336,6 +1326,7 @@ const toggleParentContext = async (item: any, index: number) => { } } catch (err) { MessagePlugin.error(t('knowledgeBase.parentContextLoadFailed')); + parentContextPopup.value = ''; return; } finally { parentContextLoading.value.delete(index); @@ -1343,11 +1334,19 @@ const toggleParentContext = async (item: any, index: number) => { } } - parentContextExpanded.value.add(index); - parentContextExpanded.value = new Set(parentContextExpanded.value); + await nextTick(); await runMarkdownPostRenderPipeline(); }; +const setParentContextPopupVisible = (item: any, index: number, visible: boolean) => { + parentContextPopup.value = visible ? item.id : ''; + if (visible) { + questionPopupChunk.value = ''; + chunkHistoryPopup.value = ''; + loadParentContext(item, index); + } +}; + const getParentContent = (item: any) => { return parentContextCache.value.get(item.parent_chunk_id) || ''; }; @@ -1702,10 +1701,6 @@ const handleDetailsScroll = () => { {{ $t('knowledgeBase.childChunk') }} - - - {{ chunk.questions.length }} -
{ + + + + + + + + + + + +