im连接失败提示

This commit is contained in:
2026-02-26 16:29:11 +08:00
parent 35f08b0c99
commit e1e4c8f531
4 changed files with 48 additions and 9 deletions

View File

@@ -52,14 +52,17 @@ export function goEasyLink(data) {
onSuccess: function () { onSuccess: function () {
console.log('PK IM 连接成功') console.log('PK IM 连接成功')
counter.setIMstate(true) counter.setIMstate(true)
data.onSuccess?.()
resolve(true) resolve(true)
}, },
onFailed: function (error) { onFailed: function (error) {
console.log('PK IM 连接失败,错误码:' + error.code + ',错误信息:' + error.content) console.log('PK IM 连接失败,错误码:' + error.code + ',错误信息:' + error.content)
data.onFailed?.(error)
reject(error) reject(error)
}, },
onProgress: function (attempts) { onProgress: function (attempts) {
console.log('PK IM 正在重连中...') console.log('PK IM 正在重连中...')
data.onProgress?.(attempts)
} }
}) })
}) })

View File

@@ -177,8 +177,8 @@ async function sendMessage() {
const msg = await goEasySendMessage({ const msg = await goEasySendMessage({
text: inputText.value, text: inputText.value,
id: String(selectedChat.value.userId), id: String(selectedChat.value.userId),
avatar: currentUser.value.headerIcon, avatar: selectedChat.value.data?.avatar || '',
nickname: currentUser.value.username nickname: selectedChat.value.data?.nickname || ''
}) })
messagesList.value.push(msg) messagesList.value.push(msg)
inputText.value = '' inputText.value = ''
@@ -186,9 +186,13 @@ async function sendMessage() {
scrollToBottom() scrollToBottom()
} catch (e) { } catch (e) {
console.error('发送消息失败', e) console.error('发送消息失败', e)
if(e =='Error: id can not be the same as your id'){
ElMessage.error('不能给自己发消息')
}else{
ElMessage.error('发送失败') ElMessage.error('发送失败')
} }
} }
}
function handleSendImage() { function handleSendImage() {
if (!isGoEasyEnabled()) { if (!isGoEasyEnabled()) {
@@ -213,8 +217,8 @@ async function handleFileSelect(event) {
const msg = await goEasySendImageMessage({ const msg = await goEasySendImageMessage({
imagefile: file, imagefile: file,
id: String(selectedChat.value.userId), id: String(selectedChat.value.userId),
avatar: currentUser.value.headerIcon, avatar: selectedChat.value.data?.avatar || '',
nickname: currentUser.value.username nickname: selectedChat.value.data?.nickname || ''
}) })
messagesList.value.push(msg) messagesList.value.push(msg)
await nextTick() await nextTick()

View File

@@ -457,9 +457,13 @@ async function sendMessage() {
scrollToBottom() scrollToBottom()
} catch (e) { } catch (e) {
console.error('发送消息失败', e) console.error('发送消息失败', e)
if(e =='Error: id can not be the same as your id'){
ElMessage.error('不能给自己发消息')
}else{
ElMessage.error('发送失败') ElMessage.error('发送失败')
} }
} }
}
// 发送图片 // 发送图片
function handleSendImage() { function handleSendImage() {

View File

@@ -25,9 +25,10 @@ import Mine from './Mine.vue'
import { initPkGoEasy, goEasyLink, goEasyDisConnect } from '@/utils/pk-mini/goeasy' import { initPkGoEasy, goEasyLink, goEasyDisConnect } from '@/utils/pk-mini/goeasy'
import { getOtp } from '@/api/pk-mini' import { getOtp } from '@/api/pk-mini'
import { getMainUserData } from '@/utils/pk-mini/storage' import { getMainUserData } from '@/utils/pk-mini/storage'
import { ElMessage } from 'element-plus' import { ElMessage, ElNotification } from 'element-plus'
const activeTab = ref('pk') const activeTab = ref('pk')
let reconnectNotification = null
const componentMap = { const componentMap = {
pk: PkHall, pk: PkHall,
@@ -59,10 +60,32 @@ async function autoLinkIM() {
key: otp 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 连接成功') console.log('PK Mini: IM 连接成功')
} catch (err) { } catch (err) {
console.error('PK Mini: IM 连接失败', err) console.error('PK Mini: IM 连接失败', err)
if (reconnectNotification) {
reconnectNotification.close()
reconnectNotification = null
}
ElMessage.warning('PK工作台聊天系统连接失败') ElMessage.warning('PK工作台聊天系统连接失败')
} }
} }
@@ -77,6 +100,11 @@ onMounted(() => {
onUnmounted(() => { onUnmounted(() => {
// 断开 IM 连接 // 断开 IM 连接
goEasyDisConnect().catch(() => {}) goEasyDisConnect().catch(() => {})
// 清理重连通知
if (reconnectNotification) {
reconnectNotification.close()
reconnectNotification = null
}
}) })
</script> </script>