diff --git a/src/views/dialogue/components/DialogueSession.vue b/src/views/dialogue/components/DialogueSession.vue index cd63db8aa6abf7d1a8ebeee106e201ce1e767903..5b9f14293e19c7b1ab946e232b2f385b7927bb00 100644 --- a/src/views/dialogue/components/DialogueSession.vue +++ b/src/views/dialogue/components/DialogueSession.vue @@ -253,12 +253,20 @@ const openDocumentPreview = (fileList: Array, markId: string, fileIndex?: n } }); - previewFileList.value = formattedList; + // 🔑 关键修复:按照 documentOrder 排序,确保数组顺序与引用标识[[1]][[2]]对应 + // documentOrder字段定义了文档在引用中的顺序(1对应第一个引用,2对应第二个引用) + const sortedList = [...formattedList].sort((a, b) => { + const orderA = a.documentOrder ?? 999; + const orderB = b.documentOrder ?? 999; + return orderA - orderB; + }); + + previewFileList.value = sortedList; // 🔑 修复:直接使用传入的索引,如果没有传入则尝试从DOM获取 let targetIndex = 0; // 默认第一个 - if (fileIndex !== undefined && fileIndex >= 0 && fileIndex < formattedList.length) { + if (fileIndex !== undefined && fileIndex >= 0 && fileIndex < sortedList.length) { // 优先使用直接传入的索引 targetIndex = fileIndex; } else { @@ -269,15 +277,15 @@ const openDocumentPreview = (fileList: Array, markId: string, fileIndex?: n 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]; + if (!isNaN(index) && index >= 0 && index < sortedList.length) { + selectedPreviewFile.value = sortedList[index]; } } } }); } - selectedPreviewFile.value = formattedList[targetIndex]; + selectedPreviewFile.value = sortedList[targetIndex]; } else { previewFileList.value = []; selectedPreviewFile.value = null;