fix: 修复销毁websocket后还有心跳检测的问题

This commit is contained in:
2025-09-23 20:30:48 +08:00
parent 8720c43570
commit 86c87b2cc4
2 changed files with 574 additions and 577 deletions

View File

@@ -388,6 +388,7 @@ const initHandler = () => {
if (!appStore.hasToken) return;
loadRecentConversation();
///loadConversationMsgList();
initTypewriterManager();
initWebSocket();
};
@@ -395,8 +396,6 @@ onMounted(() => {
try {
getMainPageData();
addNoticeListener();
initTypewriterManager();
// 有token时加载最近会话、最近消息、初始化socket
initHandler();
} catch (error) {

View File

@@ -121,8 +121,7 @@ export class WebSocketManager {
this.connectionState = false;
this._safeCallCallback("onError", {
type: "CONNECTION_ERROR",
message:
"uni.connectSocket返回的SocketTask对象无效",
message: "uni.connectSocket返回的SocketTask对象无效",
originalError: null,
});
this.scheduleReconnect();
@@ -427,9 +426,7 @@ export class WebSocketManager {
}
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
console.error(
`达到最大重连次数(${this.maxReconnectAttempts}),停止重连`
);
console.error(`达到最大重连次数(${this.maxReconnectAttempts}),停止重连`);
this.connectionState = false;
this.isConnecting = false;
@@ -573,6 +570,7 @@ export class WebSocketManager {
*/
close() {
this.stopHeartbeat();
this.resetConnectionState();
// 清理重连定时器
TimerUtils.clearTimer(this.reconnectTimer);