请求聊天总数 设置已读改为websocket模式
This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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();
|
||||
};
|
||||
|
||||
// 连接发生错误的回调方法
|
||||
|
Reference in New Issue
Block a user