im通讯修复,遗留问题发送消息后名字变成自己的
This commit is contained in:
@@ -137,6 +137,7 @@ export function goEasySendMessage(data) {
|
||||
if (!isGoEasyEnabled()) {
|
||||
return Promise.reject(new Error('GoEasy 未启用'))
|
||||
}
|
||||
console.log("```````````````````````名称``````````````````````", data.nickname);
|
||||
|
||||
const goeasy = getPkGoEasy()
|
||||
const im = goeasy.im
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<!-- 消息列表 -->
|
||||
<div class="chat-panel">
|
||||
<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
|
||||
v-for="(msg, index) in messagesList"
|
||||
:key="index"
|
||||
@@ -82,7 +82,7 @@
|
||||
</template>
|
||||
|
||||
<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 { TimestamptolocalTime } from '@/utils/pk-mini/timeConversion'
|
||||
import { isGoEasyEnabled } from '@/config/pk-mini'
|
||||
@@ -107,6 +107,7 @@ const selectedChat = ref(null)
|
||||
const messagesList = ref([])
|
||||
const inputText = ref('')
|
||||
const currentUser = ref({})
|
||||
const isScrollReady = ref(false)
|
||||
const chatMessagesRef = ref(null)
|
||||
const fileInputRef = ref(null)
|
||||
const unreadStore = pkUnreadStore()
|
||||
@@ -137,7 +138,7 @@ async function selectChat(item) {
|
||||
await nextTick()
|
||||
scrollToBottom()
|
||||
// 异步卡片内容加载完后再滚一次
|
||||
setTimeout(scrollToBottom, 300)
|
||||
scrollToBottomHidden()
|
||||
// 标记消息已读
|
||||
goEasyMessageRead({ id: String(item.userId) }).catch(() => {})
|
||||
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() {
|
||||
if (!isGoEasyEnabled()) {
|
||||
ElMessage.warning('消息功能暂时不可用(GoEasy 订阅未续费)')
|
||||
@@ -167,7 +178,7 @@ async function sendMessage() {
|
||||
text: inputText.value,
|
||||
id: String(selectedChat.value.userId),
|
||||
avatar: currentUser.value.headerIcon,
|
||||
nickname: currentUser.value.nickName
|
||||
nickname: currentUser.value.username
|
||||
})
|
||||
messagesList.value.push(msg)
|
||||
inputText.value = ''
|
||||
@@ -203,7 +214,7 @@ async function handleFileSelect(event) {
|
||||
imagefile: file,
|
||||
id: String(selectedChat.value.userId),
|
||||
avatar: currentUser.value.headerIcon,
|
||||
nickname: currentUser.value.nickName
|
||||
nickname: currentUser.value.username
|
||||
})
|
||||
messagesList.value.push(msg)
|
||||
await nextTick()
|
||||
@@ -225,16 +236,22 @@ onMounted(() => {
|
||||
}
|
||||
}
|
||||
// 切换回消息页面时,滚到聊天记录最底部
|
||||
nextTick(() => setTimeout(scrollToBottom, 300))
|
||||
nextTick(() => scrollToBottomHidden())
|
||||
})
|
||||
|
||||
// KeepAlive 缓存激活时触发(从其他页面切回消息页面)
|
||||
onActivated(() => {
|
||||
scrollToBottomHidden()
|
||||
})
|
||||
|
||||
// 监听 chatMessagesRef 出现(selectedChat 从 null 变为有值时 DOM 才渲染)
|
||||
watch(chatMessagesRef, (el) => {
|
||||
if (el) setTimeout(scrollToBottom, 300)
|
||||
if (el) scrollToBottomHidden()
|
||||
})
|
||||
|
||||
function onConversationsUpdated(conversations) {
|
||||
chatList.value = conversations.conversations || []
|
||||
console.log("chatList返回",chatList.value)
|
||||
}
|
||||
|
||||
function onMessageReceived(message) {
|
||||
@@ -450,7 +467,7 @@ onUnmounted(() => {
|
||||
border: none;
|
||||
outline: none;
|
||||
resize: none;
|
||||
height: 50px;
|
||||
height: 100px;
|
||||
font-size: 14px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
<div class="chat-panel">
|
||||
<div v-if="selectedItem" class="chat-container">
|
||||
<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
|
||||
v-for="(msg, index) in messagesList"
|
||||
:key="index"
|
||||
@@ -216,7 +216,7 @@
|
||||
</template>
|
||||
|
||||
<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 { getCountryNamesArray } from '@/utils/pk-mini/countryUtil'
|
||||
import { TimestamptolocalTime } from '@/utils/pk-mini/timeConversion'
|
||||
@@ -263,6 +263,7 @@ const inputText = ref('')
|
||||
const currentUser = ref({})
|
||||
const chatMessagesRef = ref(null)
|
||||
const fileInputRef = ref(null)
|
||||
const isScrollReady = ref(false)
|
||||
|
||||
// 邀请相关状态
|
||||
const inviteDialogVisible = ref(false)
|
||||
@@ -395,10 +396,8 @@ async function handleItemClick(item) {
|
||||
// GoEasy 已启用,加载聊天消息
|
||||
const messages = await goEasyGetMessages({ id: String(item.senderId), timestamp: null })
|
||||
messagesList.value = messages || []
|
||||
await nextTick()
|
||||
scrollToBottom()
|
||||
// 异步卡片内容加载完后再滚一次
|
||||
setTimeout(scrollToBottom, 300)
|
||||
// 隐藏后滚到底部再显示,避免视觉跳动
|
||||
scrollToBottomHidden()
|
||||
// 标记消息已读
|
||||
goEasyMessageRead({ id: String(item.senderId) }).catch(() => {})
|
||||
} 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() {
|
||||
if (!isGoEasyEnabled()) {
|
||||
@@ -582,6 +591,11 @@ onMounted(() => {
|
||||
}
|
||||
})
|
||||
|
||||
// KeepAlive 缓存激活时触发(从其他页面切回 PK 页面)
|
||||
onActivated(() => {
|
||||
scrollToBottomHidden()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (isGoEasyEnabled()) {
|
||||
const goeasy = getPkGoEasy()
|
||||
@@ -1004,7 +1018,7 @@ onUnmounted(() => {
|
||||
|
||||
.input-box textarea {
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
height: 80px;
|
||||
border: none;
|
||||
outline: none;
|
||||
resize: none;
|
||||
|
||||
@@ -54,8 +54,8 @@ async function autoLinkIM() {
|
||||
const otp = await getOtp()
|
||||
const data = {
|
||||
id: String(userData.id),
|
||||
avatar: userData.headerIcon || '',
|
||||
nickname: userData.nickName || userData.username || '',
|
||||
// avatar: userData.headerIcon || '',
|
||||
nickname: userData.username || '',
|
||||
key: otp
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user