im通讯修复,遗留问题发送消息后名字变成自己的

This commit is contained in:
2026-02-26 15:57:22 +08:00
parent 5c1911314f
commit 35f08b0c99
4 changed files with 49 additions and 17 deletions

View File

@@ -137,6 +137,7 @@ export function goEasySendMessage(data) {
if (!isGoEasyEnabled()) { if (!isGoEasyEnabled()) {
return Promise.reject(new Error('GoEasy 未启用')) return Promise.reject(new Error('GoEasy 未启用'))
} }
console.log("```````````````````````名称``````````````````````", data.nickname);
const goeasy = getPkGoEasy() const goeasy = getPkGoEasy()
const im = goeasy.im const im = goeasy.im

View File

@@ -30,7 +30,7 @@
<!-- 消息列表 --> <!-- 消息列表 -->
<div class="chat-panel"> <div class="chat-panel">
<div v-if="selectedChat" class="chat-container"> <div v-if="selectedChat" class="chat-container">
<div class="chat-messages" ref="chatMessagesRef"> <div class="chat-messages" ref="chatMessagesRef" :style="{ visibility: isScrollReady ? 'visible' : 'hidden' }">
<div <div
v-for="(msg, index) in messagesList" v-for="(msg, index) in messagesList"
:key="index" :key="index"
@@ -82,7 +82,7 @@
</template> </template>
<script setup> <script setup>
import { ref, onMounted, onUnmounted, nextTick, watch } from 'vue' import { ref, onMounted, onUnmounted, onActivated, nextTick, watch } from 'vue'
import { getMainUserData } from '@/utils/pk-mini/storage' import { getMainUserData } from '@/utils/pk-mini/storage'
import { TimestamptolocalTime } from '@/utils/pk-mini/timeConversion' import { TimestamptolocalTime } from '@/utils/pk-mini/timeConversion'
import { isGoEasyEnabled } from '@/config/pk-mini' import { isGoEasyEnabled } from '@/config/pk-mini'
@@ -107,6 +107,7 @@ const selectedChat = ref(null)
const messagesList = ref([]) const messagesList = ref([])
const inputText = ref('') const inputText = ref('')
const currentUser = ref({}) const currentUser = ref({})
const isScrollReady = ref(false)
const chatMessagesRef = ref(null) const chatMessagesRef = ref(null)
const fileInputRef = ref(null) const fileInputRef = ref(null)
const unreadStore = pkUnreadStore() const unreadStore = pkUnreadStore()
@@ -137,7 +138,7 @@ async function selectChat(item) {
await nextTick() await nextTick()
scrollToBottom() scrollToBottom()
// 异步卡片内容加载完后再滚一次 // 异步卡片内容加载完后再滚一次
setTimeout(scrollToBottom, 300) scrollToBottomHidden()
// 标记消息已读 // 标记消息已读
goEasyMessageRead({ id: String(item.userId) }).catch(() => {}) goEasyMessageRead({ id: String(item.userId) }).catch(() => {})
unreadStore.decrease(item.unread || 0) unreadStore.decrease(item.unread || 0)
@@ -153,6 +154,16 @@ function scrollToBottom() {
} }
} }
function scrollToBottomHidden() {
isScrollReady.value = false
setTimeout(() => {
if (chatMessagesRef.value) {
chatMessagesRef.value.scrollTop = chatMessagesRef.value.scrollHeight
}
isScrollReady.value = true
}, 300)
}
async function sendMessage() { async function sendMessage() {
if (!isGoEasyEnabled()) { if (!isGoEasyEnabled()) {
ElMessage.warning('消息功能暂时不可用GoEasy 订阅未续费)') ElMessage.warning('消息功能暂时不可用GoEasy 订阅未续费)')
@@ -167,7 +178,7 @@ async function sendMessage() {
text: inputText.value, text: inputText.value,
id: String(selectedChat.value.userId), id: String(selectedChat.value.userId),
avatar: currentUser.value.headerIcon, avatar: currentUser.value.headerIcon,
nickname: currentUser.value.nickName nickname: currentUser.value.username
}) })
messagesList.value.push(msg) messagesList.value.push(msg)
inputText.value = '' inputText.value = ''
@@ -203,7 +214,7 @@ async function handleFileSelect(event) {
imagefile: file, imagefile: file,
id: String(selectedChat.value.userId), id: String(selectedChat.value.userId),
avatar: currentUser.value.headerIcon, avatar: currentUser.value.headerIcon,
nickname: currentUser.value.nickName nickname: currentUser.value.username
}) })
messagesList.value.push(msg) messagesList.value.push(msg)
await nextTick() await nextTick()
@@ -225,16 +236,22 @@ onMounted(() => {
} }
} }
// 切换回消息页面时,滚到聊天记录最底部 // 切换回消息页面时,滚到聊天记录最底部
nextTick(() => setTimeout(scrollToBottom, 300)) nextTick(() => scrollToBottomHidden())
})
// KeepAlive 缓存激活时触发(从其他页面切回消息页面)
onActivated(() => {
scrollToBottomHidden()
}) })
// 监听 chatMessagesRef 出现selectedChat 从 null 变为有值时 DOM 才渲染) // 监听 chatMessagesRef 出现selectedChat 从 null 变为有值时 DOM 才渲染)
watch(chatMessagesRef, (el) => { watch(chatMessagesRef, (el) => {
if (el) setTimeout(scrollToBottom, 300) if (el) scrollToBottomHidden()
}) })
function onConversationsUpdated(conversations) { function onConversationsUpdated(conversations) {
chatList.value = conversations.conversations || [] chatList.value = conversations.conversations || []
console.log("chatList返回",chatList.value)
} }
function onMessageReceived(message) { function onMessageReceived(message) {
@@ -450,7 +467,7 @@ onUnmounted(() => {
border: none; border: none;
outline: none; outline: none;
resize: none; resize: none;
height: 50px; height: 100px;
font-size: 14px; font-size: 14px;
padding: 10px; padding: 10px;
} }

View File

@@ -122,7 +122,7 @@
<div class="chat-panel"> <div class="chat-panel">
<div v-if="selectedItem" class="chat-container"> <div v-if="selectedItem" class="chat-container">
<div class="chat-header">{{ chatUserInfo.nickName || '聊天' }}</div> <div class="chat-header">{{ chatUserInfo.nickName || '聊天' }}</div>
<div class="chat-messages" ref="chatMessagesRef"> <div class="chat-messages" ref="chatMessagesRef" :style="{ visibility: isScrollReady ? 'visible' : 'hidden' }">
<div <div
v-for="(msg, index) in messagesList" v-for="(msg, index) in messagesList"
:key="index" :key="index"
@@ -216,7 +216,7 @@
</template> </template>
<script setup> <script setup>
import { ref, onMounted, onUnmounted, nextTick } from 'vue' import { ref, onMounted, onUnmounted, onActivated, nextTick } from 'vue'
import { getPkList, getUserInfo, getAnchorListById, createPkRecord } from '@/api/pk-mini' import { getPkList, getUserInfo, getAnchorListById, createPkRecord } from '@/api/pk-mini'
import { getCountryNamesArray } from '@/utils/pk-mini/countryUtil' import { getCountryNamesArray } from '@/utils/pk-mini/countryUtil'
import { TimestamptolocalTime } from '@/utils/pk-mini/timeConversion' import { TimestamptolocalTime } from '@/utils/pk-mini/timeConversion'
@@ -263,6 +263,7 @@ const inputText = ref('')
const currentUser = ref({}) const currentUser = ref({})
const chatMessagesRef = ref(null) const chatMessagesRef = ref(null)
const fileInputRef = ref(null) const fileInputRef = ref(null)
const isScrollReady = ref(false)
// 邀请相关状态 // 邀请相关状态
const inviteDialogVisible = ref(false) const inviteDialogVisible = ref(false)
@@ -395,10 +396,8 @@ async function handleItemClick(item) {
// GoEasy 已启用,加载聊天消息 // GoEasy 已启用,加载聊天消息
const messages = await goEasyGetMessages({ id: String(item.senderId), timestamp: null }) const messages = await goEasyGetMessages({ id: String(item.senderId), timestamp: null })
messagesList.value = messages || [] messagesList.value = messages || []
await nextTick() // 隐藏后滚到底部再显示,避免视觉跳动
scrollToBottom() scrollToBottomHidden()
// 异步卡片内容加载完后再滚一次
setTimeout(scrollToBottom, 300)
// 标记消息已读 // 标记消息已读
goEasyMessageRead({ id: String(item.senderId) }).catch(() => {}) goEasyMessageRead({ id: String(item.senderId) }).catch(() => {})
} else { } else {
@@ -425,6 +424,16 @@ function scrollToBottom() {
} }
} }
function scrollToBottomHidden() {
isScrollReady.value = false
setTimeout(() => {
if (chatMessagesRef.value) {
chatMessagesRef.value.scrollTop = chatMessagesRef.value.scrollHeight
}
isScrollReady.value = true
}, 300)
}
// 发送消息 // 发送消息
async function sendMessage() { async function sendMessage() {
if (!isGoEasyEnabled()) { if (!isGoEasyEnabled()) {
@@ -582,6 +591,11 @@ onMounted(() => {
} }
}) })
// KeepAlive 缓存激活时触发(从其他页面切回 PK 页面)
onActivated(() => {
scrollToBottomHidden()
})
onUnmounted(() => { onUnmounted(() => {
if (isGoEasyEnabled()) { if (isGoEasyEnabled()) {
const goeasy = getPkGoEasy() const goeasy = getPkGoEasy()
@@ -1004,7 +1018,7 @@ onUnmounted(() => {
.input-box textarea { .input-box textarea {
width: 100%; width: 100%;
height: 50px; height: 80px;
border: none; border: none;
outline: none; outline: none;
resize: none; resize: none;

View File

@@ -54,8 +54,8 @@ async function autoLinkIM() {
const otp = await getOtp() const otp = await getOtp()
const data = { const data = {
id: String(userData.id), id: String(userData.id),
avatar: userData.headerIcon || '', // avatar: userData.headerIcon || '',
nickname: userData.nickName || userData.username || '', nickname: userData.username || '',
key: otp key: otp
} }