From 943efae7a0cc66bdb488ff76954f4eebcef54d20 Mon Sep 17 00:00:00 2001 From: xsx <825657193@qq.com> Date: Fri, 12 Apr 2024 18:39:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=BE=E7=89=87=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E5=9C=A8=E5=A4=B4=E9=83=A8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- im-ui/src/store/chatStore.js | 7 ++----- im-uniapp/store/chatStore.js | 13 ++++++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/im-ui/src/store/chatStore.js b/im-ui/src/store/chatStore.js index 0e626fa..9a240be 100644 --- a/im-ui/src/store/chatStore.js +++ b/im-ui/src/store/chatStore.js @@ -176,9 +176,8 @@ export default { } // 根据id顺序插入,防止消息乱序 let insertPos = chat.messages.length; - - if(msgInfo.id>0){ - //防止 图片、文件 在发送方 显示 在顶端 因为还没存库,id=0 + // 防止 图片、文件 在发送方 显示 在顶端 因为还没存库,id=0 + if(msgInfo.id && msgInfo.id > 0){ for (let idx in chat.messages) { if (chat.messages[idx].id && msgInfo.id < chat.messages[idx].id) { insertPos = idx; @@ -187,8 +186,6 @@ export default { } } } - - chat.messages.splice(insertPos, 0, msgInfo); this.commit("saveToStorage"); }, diff --git a/im-uniapp/store/chatStore.js b/im-uniapp/store/chatStore.js index 005ec61..0d9ba68 100644 --- a/im-uniapp/store/chatStore.js +++ b/im-uniapp/store/chatStore.js @@ -178,11 +178,14 @@ export default { } // 根据id顺序插入,防止消息乱序 let insertPos = chat.messages.length; - for (let idx in chat.messages) { - if (chat.messages[idx].id && msgInfo.id < chat.messages[idx].id) { - insertPos = idx; - console.log(`消息出现乱序,位置:${chat.messages.length},修正至:${insertPos}`); - break; + // 防止 图片、文件 在发送方 显示 在顶端 因为还没存库,id=0 + if(msgInfo.id && msgInfo.id > 0){ + for (let idx in chat.messages) { + if (chat.messages[idx].id && msgInfo.id < chat.messages[idx].id) { + insertPos = idx; + console.log(`消息出现乱序,位置:${chat.messages.length},修正至:${insertPos}`); + break; + } } } chat.messages.splice(insertPos, 0, msgInfo);