From 4c93f9a3c220c4bcd8a31340a155f41389b3caea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kaizheng=28=E9=83=91=E5=87=AF=29?= Date: Wed, 12 Feb 2025 22:55:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/Circle/components/ChatFrame.vue | 24 ++++++++++++++++------- src/views/Circle/hooks/useChatData.js | 8 +++++++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/views/Circle/components/ChatFrame.vue b/src/views/Circle/components/ChatFrame.vue index 12a116f..4a341a5 100644 --- a/src/views/Circle/components/ChatFrame.vue +++ b/src/views/Circle/components/ChatFrame.vue @@ -203,7 +203,9 @@ watch( watch( () => props.newMsg, (data) => { - if ( + if (msgIdsObj.value[[data.id]]) { + Object.assign(msgIdsObj.value[data.id], data); + } else if ( (props.type === 1 && data.interactiveType === 1) || (props.type === 5 && data.interactiveType === 2) || (props.type === 2 && data.userType === 1) || @@ -222,12 +224,20 @@ const imagePreview = (url) => { }; const showCalendar = ref(false); -const { bs, msgListRef, msgList, hasNext, pushNewMsg, refreshMsg, loading } = - useChatData({ - className: `.interact-scroll${props.type}`, - id: route.query.id, - type: props.type, - }); +const { + bs, + msgListRef, + msgList, + msgIdsObj, + hasNext, + pushNewMsg, + refreshMsg, + loading, +} = useChatData({ + className: `.interact-scroll${props.type}`, + id: route.query.id, + type: props.type, +}); const maskUserName = (value) => { return value.charAt(0) + "**"; diff --git a/src/views/Circle/hooks/useChatData.js b/src/views/Circle/hooks/useChatData.js index bf02dec..0018408 100644 --- a/src/views/Circle/hooks/useChatData.js +++ b/src/views/Circle/hooks/useChatData.js @@ -15,6 +15,7 @@ export default function useChatData({ id, className, type }) { const isPullingDown = ref(false); const msgListRef = ref(); const msgList = ref([]); + const msgIdsObj = ref({}); const loading = ref(false); const getLiveHisMsg = async () => { @@ -30,10 +31,12 @@ export default function useChatData({ id, className, type }) { }); if (ret.code === 0) { let list = ret.data.list.reverse() || []; - hasNext.value = ret.data.hasNext; preHisHeight = msgListRef.value.clientHeight; msgList.value = list.concat(msgList.value); + list.forEach((msg) => { + msgIdsObj.value[msg.id] = msg; + }); if (!hasNext.value) { bs.value && bs.value.closePullDown(); } @@ -56,6 +59,7 @@ export default function useChatData({ id, className, type }) { // WebSocket推送的消息 const pushNewMsg = (msg) => { msgList.value.push(msg); + msgIdsObj.value[msg.id] = msg; nextTick(() => { let isBottom = bs.value.maxScrollY + 20 >= bs.value.y; bs.value && bs.value.refresh(); @@ -68,6 +72,7 @@ export default function useChatData({ id, className, type }) { // 刷新消息 const refreshMsg = () => { msgList.value = []; + msgIdsObj.value = {}; getLiveHisMsg(); }; @@ -110,6 +115,7 @@ export default function useChatData({ id, className, type }) { hasNext, bs, msgList, + msgIdsObj, pushNewMsg, refreshMsg, loading,