diff --git a/src/utils/pk-mini/goeasy.js b/src/utils/pk-mini/goeasy.js index 9df7dad..185aadb 100644 --- a/src/utils/pk-mini/goeasy.js +++ b/src/utils/pk-mini/goeasy.js @@ -52,14 +52,17 @@ export function goEasyLink(data) { onSuccess: function () { console.log('PK IM 连接成功') counter.setIMstate(true) + data.onSuccess?.() resolve(true) }, onFailed: function (error) { console.log('PK IM 连接失败,错误码:' + error.code + ',错误信息:' + error.content) + data.onFailed?.(error) reject(error) }, onProgress: function (attempts) { console.log('PK IM 正在重连中...') + data.onProgress?.(attempts) } }) }) diff --git a/src/views/pk-mini/Message.vue b/src/views/pk-mini/Message.vue index 2e7f245..771e04a 100644 --- a/src/views/pk-mini/Message.vue +++ b/src/views/pk-mini/Message.vue @@ -177,16 +177,20 @@ async function sendMessage() { const msg = await goEasySendMessage({ text: inputText.value, id: String(selectedChat.value.userId), - avatar: currentUser.value.headerIcon, - nickname: currentUser.value.username + avatar: selectedChat.value.data?.avatar || '', + nickname: selectedChat.value.data?.nickname || '' }) messagesList.value.push(msg) inputText.value = '' await nextTick() scrollToBottom() } catch (e) { - console.error('发送消息失败', e) - ElMessage.error('发送失败') + console.error('发送消息失败', e) + if(e =='Error: id can not be the same as your id'){ + ElMessage.error('不能给自己发消息') + }else{ + ElMessage.error('发送失败') + } } } @@ -213,8 +217,8 @@ async function handleFileSelect(event) { const msg = await goEasySendImageMessage({ imagefile: file, id: String(selectedChat.value.userId), - avatar: currentUser.value.headerIcon, - nickname: currentUser.value.username + avatar: selectedChat.value.data?.avatar || '', + nickname: selectedChat.value.data?.nickname || '' }) messagesList.value.push(msg) await nextTick() diff --git a/src/views/pk-mini/PkHall.vue b/src/views/pk-mini/PkHall.vue index de4d7a7..00d1faf 100644 --- a/src/views/pk-mini/PkHall.vue +++ b/src/views/pk-mini/PkHall.vue @@ -457,7 +457,11 @@ async function sendMessage() { scrollToBottom() } catch (e) { console.error('发送消息失败', e) - ElMessage.error('发送失败') + if(e =='Error: id can not be the same as your id'){ + ElMessage.error('不能给自己发消息') + }else{ + ElMessage.error('发送失败') + } } } diff --git a/src/views/pk-mini/PkMiniWorkbench.vue b/src/views/pk-mini/PkMiniWorkbench.vue index c97080a..d97603b 100644 --- a/src/views/pk-mini/PkMiniWorkbench.vue +++ b/src/views/pk-mini/PkMiniWorkbench.vue @@ -25,9 +25,10 @@ import Mine from './Mine.vue' import { initPkGoEasy, goEasyLink, goEasyDisConnect } from '@/utils/pk-mini/goeasy' import { getOtp } from '@/api/pk-mini' import { getMainUserData } from '@/utils/pk-mini/storage' -import { ElMessage } from 'element-plus' +import { ElMessage, ElNotification } from 'element-plus' const activeTab = ref('pk') +let reconnectNotification = null const componentMap = { pk: PkHall, @@ -59,10 +60,32 @@ async function autoLinkIM() { key: otp } - await goEasyLink(data) + await goEasyLink({ + ...data, + onProgress: () => { + if (!reconnectNotification) { + reconnectNotification = ElNotification({ + title: 'IM 重连中', + message: '聊天系统正在重新连接,请稍候...', + type: 'warning', + duration: 0 + }) + } + }, + onSuccess: () => { + if (reconnectNotification) { + reconnectNotification.close() + reconnectNotification = null + } + } + }) console.log('PK Mini: IM 连接成功') } catch (err) { console.error('PK Mini: IM 连接失败', err) + if (reconnectNotification) { + reconnectNotification.close() + reconnectNotification = null + } ElMessage.warning('PK工作台聊天系统连接失败') } } @@ -77,6 +100,11 @@ onMounted(() => { onUnmounted(() => { // 断开 IM 连接 goEasyDisConnect().catch(() => {}) + // 清理重连通知 + if (reconnectNotification) { + reconnectNotification.close() + reconnectNotification = null + } })