|
@@ -19,6 +19,7 @@
|
|
|
</template>
|
|
|
</van-nav-bar>
|
|
|
<template v-if="showPage">
|
|
|
+
|
|
|
<van-list
|
|
|
ref="chatListRef"
|
|
|
class="flex-1 overflow-y-auto px-12 flex flex-col"
|
|
@@ -32,10 +33,11 @@
|
|
|
{{ followStatus }}在对方关注或回复前,最多只能发送1条信息
|
|
|
</div>
|
|
|
</van-list>
|
|
|
-<!-- <van-pull-refresh v-model="refreshing" @refresh="loadMore">-->
|
|
|
-<!-- -->
|
|
|
-<!-- </van-pull-refresh>-->
|
|
|
- <ChatInput :operates="['image']" @focus="scrollToBottom" @send="handleSendMessage"></ChatInput>
|
|
|
+<!-- <van-pull-refresh v-model="refreshing" @refresh="loadMore" class="flex-1">
|
|
|
+ </van-pull-refresh>-->
|
|
|
+<!-- <div class="fixed bottom-0 left-0 right-0 w-full">-->
|
|
|
+ <ChatInput :operates="['image']" @focus="scrollToBottom" @send="handleSendMessage"></ChatInput>
|
|
|
+<!-- </div>-->
|
|
|
</template>
|
|
|
<template v-else>
|
|
|
<div class="flex-1 grid place-items-center text-black-9">
|
|
@@ -111,7 +113,7 @@ const getChatList = async (type = 'init') => {
|
|
|
})
|
|
|
pageNum.value = page;
|
|
|
await handleResponse(res);
|
|
|
- currConversationChatList.value = handleChatList(res.data?.dataList)
|
|
|
+ currConversationChatList.value = handleChatList(res.data?.data)
|
|
|
console.log(currConversationChatList.value, 'currConversationChatList')
|
|
|
if (type === 'init') await scrollToBottom()
|
|
|
await getFollowStatus()
|
|
@@ -145,6 +147,7 @@ const sendTextMessage = async (text) => {
|
|
|
const isLink = !!findHyperlinks(text)
|
|
|
if (isLink) msg.messageType = 4;
|
|
|
currConversationChatList.value.push(msg)
|
|
|
+ await scrollToBottom()
|
|
|
const res = await chatsStore.sendSocketMessage(msg)
|
|
|
console.log('luck:', res)
|
|
|
} catch (e) {
|
|
@@ -179,6 +182,7 @@ const sendImageMessage = async (file) => {
|
|
|
}
|
|
|
}
|
|
|
currConversationChatList.value.push(msg)
|
|
|
+ await scrollToBottom()
|
|
|
await chatsStore.sendSocketMessage(msg)
|
|
|
} catch (e) {
|
|
|
console.error(e, '??')
|
|
@@ -201,7 +205,7 @@ const handleSendMessage = async ({type, messageContent}) => {
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
- await scrollToBottom()
|
|
|
+
|
|
|
} catch (e) {
|
|
|
|
|
|
} finally {
|
|
@@ -210,12 +214,14 @@ const handleSendMessage = async ({type, messageContent}) => {
|
|
|
}
|
|
|
|
|
|
const scrollToBottom = async () => {
|
|
|
- await nextTick(); // 确保DOM已经更新
|
|
|
- const listElement = chatListRef.value?.$el;
|
|
|
- if (listElement) {
|
|
|
- const scrollContainer = listElement;
|
|
|
- scrollContainer.scrollTop = scrollContainer.scrollHeight;
|
|
|
- }
|
|
|
+ setTimeout(async () => {
|
|
|
+ await nextTick(); // 确保DOM已经更新
|
|
|
+ const listElement = chatListRef.value?.$el;
|
|
|
+ if (listElement) {
|
|
|
+ const scrollContainer = listElement;
|
|
|
+ scrollContainer.scrollTop = scrollContainer.scrollHeight;
|
|
|
+ }
|
|
|
+ }, 200)
|
|
|
};
|
|
|
|
|
|
// 获取我与对方的关注情况
|
|
@@ -258,10 +264,11 @@ function getLocalId() {
|
|
|
onMounted(() => {
|
|
|
initGroupId()
|
|
|
XYWebSocket.SocketEventsBus.on(XYWebSocket.SocketEvents.chatEvent, async (chat) => {
|
|
|
- console.log('XYWebSocket', chat)
|
|
|
- if (chat.groupId && chat.groupId === groupId.value) {
|
|
|
- // await getChatList()
|
|
|
+ const isCurrGroupId = chat.groupId && chat.groupId === groupId.value;
|
|
|
+ const isOtherUserMessage = chat.sendUserId && chatsStore.isRealMessage(chat.sendUserId)
|
|
|
+ if (isCurrGroupId && isOtherUserMessage) {
|
|
|
currConversationChatList.value.push(chat)
|
|
|
+ await scrollToBottom()
|
|
|
}
|
|
|
})
|
|
|
})
|