请求聊天总数 设置已读改为websocket模式

This commit is contained in:
wxl
2025-01-12 01:54:15 +08:00
parent 6a0e09c90e
commit 7bfb2df8de
22 changed files with 1107 additions and 138 deletions

View File

@@ -54,3 +54,24 @@ export function getAuthorChat(params) {
params
})
}
export function getUnReadCount() {
return request({
url: '/admin/chat/getUnReadCount',
method: 'get',
})
}
export function readAuthorMessage(data) {
return request({
url: '/admin/chat/readAuthorMessage',
method: 'post',
data: data,
noLoading:true
})
}

View File

@@ -1,3 +1,5 @@
import {error} from "@/utils";
class WebSocketManager {
constructor() {
this.webSocketInstance = null; // WebSocket实例对象使用更清晰的命名
@@ -32,6 +34,16 @@ class WebSocketManager {
}
console.log("连接WebSocket");
this.webSocketInstance = new WebSocket(url);
const timeoutTimer = setTimeout(() => {
console.log(this.isConnected)
if (!this.isConnected) {
error("WebSocket连接超时")
}
clearTimeout(timeoutTimer)
}, 5000);
this.webSocketInstance.onmessage = (event) => {
const data = event.data;
if (data === 'pong') {
@@ -53,6 +65,8 @@ class WebSocketManager {
console.log("WebSocket连接成功");
this.isConnected = true;
this.heartbeatCheck.start();
this.onConnectCallback && this.onConnectCallback();
};
// 连接发生错误的回调方法