im连接失败提示
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -177,16 +177,20 @@ 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 = ''
|
||||||
await nextTick()
|
await nextTick()
|
||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('发送消息失败', e)
|
console.error('发送消息失败', e)
|
||||||
ElMessage.error('发送失败')
|
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({
|
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()
|
||||||
|
|||||||
@@ -457,7 +457,11 @@ async function sendMessage() {
|
|||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('发送消息失败', e)
|
console.error('发送消息失败', e)
|
||||||
ElMessage.error('发送失败')
|
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 { 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>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user