feat:修复聊天界面消息位置展示错误问题

This commit is contained in:
bujinyuan
2026-03-03 13:46:03 +08:00
parent 35788f6d2f
commit 7b1d061955
3 changed files with 144 additions and 205 deletions

View File

@@ -16,6 +16,7 @@ import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import imApi from '@/api/im'
import wsService from '@/services/websocket'
import { useUserStore } from '@/store/user'
export const useChatStore = defineStore('chat', () => {
/** 会话列表 */
@@ -83,11 +84,12 @@ export const useChatStore = defineStore('chat', () => {
const sendMessage = (params) => {
const clientMsgId = _generateClientMsgId()
const { conversationId, targetUserId, content, type = 1 } = params
const userStore = useUserStore()
const tempMsg = {
id: 0,
conversation_id: conversationId || 0,
sender_id: 0,
sender_id: Number(userStore.userInfo?.id) || 0,
type,
content,
status: 1,
@@ -263,6 +265,11 @@ export const useChatStore = defineStore('chat', () => {
if (code === 0) {
pending.status = 'sent'
const convId = data.conversation_id
if (pending.tempMsg && pending.tempMsg.conversation_id === 0 && convId) {
currentConversationId.value = convId
}
const messages = messagesMap.value[convId]
if (messages) {
const idx = messages.findIndex(m => m.client_msg_id === data.client_msg_id)