From 71d97f069f64373db5d0b0c4d7efd83ff1a1c5f4 Mon Sep 17 00:00:00 2001 From: wangyifeng <812766448@qq.com> Date: Mon, 21 Apr 2025 16:21:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=AA=92=E4=BD=93=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=9B=A0=E4=B8=BA=E9=A2=84=E5=8A=A0=E8=BD=BD=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E8=A7=82=E5=AF=9F=E8=80=85=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98=EF=BC=9B=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E6=9C=AA=E8=AF=BB=E6=B6=88=E6=81=AF=E5=88=97=E8=A1=A8=E4=B8=AD?= =?UTF-8?q?=E4=BC=9A=E6=9C=89=E8=87=AA=E5=B7=B1=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=9B=E8=A7=A3=E5=86=B3=E5=A4=9A=E4=B8=AA=E5=AA=92=E4=BD=93?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=B7=B2=E8=AF=BB=E6=9C=AA=E8=AF=BB=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/dialog/index.vue | 54 +++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/src/pages/dialog/index.vue b/src/pages/dialog/index.vue index 194b43b..b87cd7d 100644 --- a/src/pages/dialog/index.vue +++ b/src/pages/dialog/index.vue @@ -75,7 +75,11 @@ style="transform: scaleY(-1);" :ref=" (el) => { - if (el) messageRecordElementRefs[item.zp_index] = el + if (el) { + if (item.zp_index !== undefined) { + messageRecordElementRefs[item.zp_index] = el + } + } } " > @@ -222,7 +226,7 @@ > 未读 - 已读 (0/{{ talkParams.num }}) + 已读 (0/{{ (Number(talkParams.num)-1) }}) @@ -711,6 +715,7 @@ const selectMemberByAlphabetRef = ref(null) let observer //获取聊天消息记录元素 const messageRecordElementRefs = ref([]) +const messageRecordElementRefsWithoutIndex = ref([]) const { getDialogueList, @@ -822,7 +827,7 @@ watch( readNumElement.textContent = readNum > 0 ? '已读' : '未读' } else { readNumElement.textContent = - '已读 (' + readNum + '/' + talkParams.num + ')' + '已读 (' + readNum + '/' + (Number(talkParams.num) - 1) + ')' } } } @@ -831,6 +836,7 @@ watch( }, { deep: true, + immediate: true, }, ) @@ -1566,16 +1572,24 @@ watch( } }) } - } else if (lastIndex === 0 && newValue[0].file_num) { + } else if (lastIndex === 0) { + messageRecordElementRefsWithoutIndex.value = [] // 新消息和旧消息的id相同,说明没有比它更新的消息需要处理。但是资源文件是预创建的,需要处理 - console.error('预创建资源文件==================') - const msg = newValue[0] - nextTick(() => { - const element = document.getElementById(`zp-id-${msg.msg_id}`) - if (element) { - messageRecordElementRefs.value.unshift(element) + for (let i = 0; i < newValue.length; i++) { + if (!newValue[i].zp_index && newValue[i].zp_index !== 0) { + if (newValue[i]?.file_num === newValue[i].msg_id) { + return + } + nextTick(() => { + const element = document.getElementById( + `zp-id-${newValue[i].msg_id}`, + ) + if (element) { + messageRecordElementRefsWithoutIndex.value.unshift(element) + } + }) } - }) + } } } } @@ -2116,6 +2130,20 @@ onMounted(async () => { deep: true, }, ) + watch( + messageRecordElementRefsWithoutIndex, + (newMessageRecordElementRefs) => { + if (Array.isArray(newMessageRecordElementRefs)) { + newMessageRecordElementRefs.forEach((el, index) => { + observeElement(el, index) + }) + } + }, + { + immediate: true, + deep: true, + }, + ) if (messageRecordElementRefs.value.length > 0) { messageRecordElementRefs.value.forEach((el, index) => observeElement(el, index), @@ -2459,12 +2487,12 @@ const getMessageReadDetail = (isUnread) => { if (code == 200) { if (Number(isUnread) === 0) { state.value.msgReadDetailTabs[0].title = - '未读 (' + (talkParams.num - data.count) + ')' + '未读 (' + (Number(talkParams.num) - 1 - data.count) + ')' state.value.msgReadDetailTabs[1].title = '已读 (' + data.count + ')' } else if (Number(isUnread) === 1) { state.value.msgReadDetailTabs[0].title = '未读 (' + data.count + ')' state.value.msgReadDetailTabs[1].title = - '已读 (' + (talkParams.num - data.count) + ')' + '已读 (' + (Number(talkParams.num) - 1 - data.count) + ')' } if (state.value.readNumPage === 1) { state.value.msgReadOrNotDetail = data.data