fix: 暂存

This commit is contained in:
2026-06-23 14:32:00 +08:00
parent 0fae4feadb
commit 7c12697579
6 changed files with 215 additions and 38 deletions
+13
View File
@@ -101,7 +101,20 @@ export const useRoomStore = defineStore('room', () => {
}
/** 添加聊天消息 */
/** 添加聊天消息(自动去重:同用户同内容 2 秒内只保留一条) */
function addMessage(msg: ChatMessage) {
// 去重:检查最后一条消息是否与即将添加的相同
const last = messages.value[messages.value.length - 1]
if (
last &&
last.userId === msg.userId &&
last.content === msg.content &&
Math.abs(last.timestamp - msg.timestamp) < 2000
) {
// 用后端的时间戳更新(更准确),其它不变
last.timestamp = msg.timestamp
return
}
messages.value.push(msg)
}