fix: 修复学员端我的消息滚动问题

This commit is contained in:
QDKF 2025-09-27 20:51:47 +08:00
parent fed060545a
commit 080ce9e724

View File

@ -565,6 +565,10 @@ const selectedConversation = ref<Conversation | null>(null)
const messageInput = ref('')
const showEmojiPicker = ref(false)
//
const isUserScrolling = ref(false)
const shouldAutoScroll = ref(true)
//
const emojiList = ref([
'😀', '😃', '😄', '😁', '😆', '😅', '😂', '🤣', '😊', '😇',
@ -1284,9 +1288,9 @@ const selectConversation = async (conversation: Conversation) => {
await loadGroupMembers(String(conversation.id))
}
//
//
nextTick(() => {
scrollToBottom()
scrollToBottom(true)
// ID
const latestMessageId = getLatestMessageId()
@ -1635,14 +1639,14 @@ const sendImageMessage = async (imageData: { file: File; url: string; name: stri
//
updateConversationLastMessage(String(selectedConversation.value!.id), newMessage)
//
//
nextTick(() => {
scrollToBottom()
scrollToBottom(true)
})
//
setTimeout(() => {
scrollToBottom()
scrollToBottom(true)
}, 200)
// ID
@ -1770,9 +1774,9 @@ const sendMessage = async () => {
//
updateConversationLastMessage(String(selectedConversation.value.id), newMessage)
//
//
nextTick(() => {
scrollToBottom()
scrollToBottom(true)
resetTextareaHeight()
// 使IDID
@ -1841,8 +1845,8 @@ const shouldShowViewMore = computed(() => {
})
//
const scrollToBottom = () => {
if (messagesContainer.value) {
const scrollToBottom = (force = false) => {
if (messagesContainer.value && (shouldAutoScroll.value || force)) {
// 使setTimeoutDOM
setTimeout(() => {
if (messagesContainer.value) {
@ -2034,10 +2038,21 @@ const getLatestMessageId = (): string | null => {
//
let scrollDebounceTimer: NodeJS.Timeout | null = null
//
const isAtBottom = () => {
if (!messagesContainer.value) return true
const { scrollTop, scrollHeight, clientHeight } = messagesContainer.value
return scrollHeight - scrollTop - clientHeight < 50 // 50px
}
//
const handleMessagesScroll = () => {
if (!messagesContainer.value || !selectedConversation.value) return
const atBottom = isAtBottom()
shouldAutoScroll.value = atBottom
isUserScrolling.value = !atBottom
// ID使ID
//
}
@ -2239,7 +2254,7 @@ const pollForNewMessages = async () => {
//
await addNewMessages(messages)
//
//
nextTick(() => {
scrollToBottom()
})