From 2ae9cf0e27e82f2b8b488229609add72c6c33e68 Mon Sep 17 00:00:00 2001 From: Ethan-Zhang Date: Thu, 13 Nov 2025 06:07:32 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E5=A4=9A=E5=BC=95=E7=94=A8=E6=A0=87?= =?UTF-8?q?=E8=AF=86=E5=88=87=E6=8D=A2=E9=A2=84=E8=A7=88=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dialoguePanel/DialoguePanel.vue | 10 +++++-- .../dialogue/components/DialogueSession.vue | 29 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/components/dialoguePanel/DialoguePanel.vue b/src/components/dialoguePanel/DialoguePanel.vue index f45008b4..7a2aba33 100644 --- a/src/components/dialoguePanel/DialoguePanel.vue +++ b/src/components/dialoguePanel/DialoguePanel.vue @@ -123,7 +123,7 @@ const emits = defineEmits<{ ): void; (e: 'clearSuggestion', index: number): void; (e: 'openShowFileSource', fileList: Array): void; - (e: 'openDocumentPreview', fileList: Array, markId: string): void; + (e: 'openDocumentPreview', fileList: Array, markId: string, fileIndex: number): void; }>(); const messageArray = ref(props.messageArray || []); @@ -256,9 +256,13 @@ const handleMarkNumberClick = (event: MouseEvent) => { event.stopPropagation(); const clickedElement = event.target as HTMLElement; const markId = clickedElement.id; - // 触发openDocumentPreview事件,传递文件列表和被点击元素的ID + // 🔑 直接从DOM元素获取 data-mark-index 属性 + const markIndexAttr = clickedElement.getAttribute('data-mark-index'); + const fileIndex = markIndexAttr !== null ? parseInt(markIndexAttr, 10) : 0; + + // 触发openDocumentPreview事件,传递文件列表、被点击元素的ID和文件索引 if (props.fileList && props.fileList.length > 0) { - emits('openDocumentPreview', props.fileList, markId); + emits('openDocumentPreview', props.fileList, markId, fileIndex); } } }; diff --git a/src/views/dialogue/components/DialogueSession.vue b/src/views/dialogue/components/DialogueSession.vue index 8907f933..cd63db8a 100644 --- a/src/views/dialogue/components/DialogueSession.vue +++ b/src/views/dialogue/components/DialogueSession.vue @@ -227,7 +227,7 @@ const handleSourceFileClick = (file: any) => { }; // 🔑 打开文档预览panel(点击[[x]]引用标识) -const openDocumentPreview = (fileList: Array, markId: string) => { +const openDocumentPreview = (fileList: Array, markId: string, fileIndex?: number) => { showDocumentPreview.value = true; // 保存被点击的标识ID @@ -255,19 +255,26 @@ const openDocumentPreview = (fileList: Array, markId: string) => { previewFileList.value = formattedList; - // 🔑 修复:根据点击的标识索引选择对应的文件 - // 从 DOM 元素中获取 data-mark-index 属性 - const clickedElement = document.getElementById(markId); + // 🔑 修复:直接使用传入的索引,如果没有传入则尝试从DOM获取 let targetIndex = 0; // 默认第一个 - if (clickedElement) { - const markIndex = clickedElement.getAttribute('data-mark-index'); - if (markIndex !== null) { - const index = parseInt(markIndex, 10); - if (!isNaN(index) && index >= 0 && index < formattedList.length) { - targetIndex = index; + if (fileIndex !== undefined && fileIndex >= 0 && fileIndex < formattedList.length) { + // 优先使用直接传入的索引 + targetIndex = fileIndex; + } else { + // 兜底:尝试从DOM元素中获取 data-mark-index 属性 + nextTick(() => { + const clickedElement = document.getElementById(markId); + if (clickedElement) { + const markIndex = clickedElement.getAttribute('data-mark-index'); + if (markIndex !== null) { + const index = parseInt(markIndex, 10); + if (!isNaN(index) && index >= 0 && index < formattedList.length) { + selectedPreviewFile.value = formattedList[index]; + } + } } - } + }); } selectedPreviewFile.value = formattedList[targetIndex]; -- Gitee