im连接失败提示
This commit is contained in:
@@ -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)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -177,8 +177,8 @@ 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 = ''
|
||||
@@ -186,8 +186,12 @@ async function sendMessage() {
|
||||
scrollToBottom()
|
||||
} catch (e) {
|
||||
console.error('发送消息失败', e)
|
||||
if(e =='Error: id can not be the same as your id'){
|
||||
ElMessage.error('不能给自己发消息')
|
||||
}else{
|
||||
ElMessage.error('发送失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleSendImage() {
|
||||
@@ -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()
|
||||
|
||||
@@ -457,8 +457,12 @@ async function sendMessage() {
|
||||
scrollToBottom()
|
||||
} catch (e) {
|
||||
console.error('发送消息失败', e)
|
||||
if(e =='Error: id can not be the same as your id'){
|
||||
ElMessage.error('不能给自己发消息')
|
||||
}else{
|
||||
ElMessage.error('发送失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 发送图片
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user