签出调整

This commit is contained in:
2025-11-26 08:58:22 +08:00
parent 92a3076638
commit e9bf7e9e0e

View File

@@ -246,13 +246,13 @@ export default class SocketService {
public connect(): Promise<void> | void { public connect(): Promise<void> | void {
// 检查浏览器支持 // 检查浏览器支持
if (!window.WebSocket) { if (!window.WebSocket) {
// console.log('您的浏览器不支持WebSocket'); // console.log('您的浏览器不支持WebSocket');
return; return;
} }
// 防止重复连接 // 防止重复连接
if (this.connectionStatus === ConnectionStatus.CONNECTING || this.connected) { if (this.connectionStatus === ConnectionStatus.CONNECTING || this.connected) {
// console.warn('WebSocket已连接或正在连接中'); // console.warn('WebSocket已连接或正在连接中');
return; return;
} }
@@ -311,7 +311,7 @@ export default class SocketService {
return; return;
} }
this.callBackMapping[messageType] = callback; this.callBackMapping[messageType] = callback;
// console.log(`注册消息处理器: ${messageType}`); // console.log(`注册消息处理器: ${messageType}`);
} }
/** /**
@@ -447,7 +447,7 @@ export default class SocketService {
// 连接成功事件 // 连接成功事件
this.ws.onopen = () => { this.ws.onopen = () => {
ElMessage.success("WebSocket连接服务端成功"); ElMessage.success("WebSocket连接服务端成功");
// console.log('WebSocket连接成功'); // console.log('WebSocket连接成功');
this.connectionStatus = ConnectionStatus.CONNECTED; this.connectionStatus = ConnectionStatus.CONNECTED;
this.connectRetryCount = 0; this.connectRetryCount = 0;
this.startHeartbeat(); this.startHeartbeat();
@@ -489,7 +489,7 @@ export default class SocketService {
// 连接成功事件 // 连接成功事件
this.ws.onopen = () => { this.ws.onopen = () => {
ElMessage.success("webSocket连接服务端成功了"); ElMessage.success("webSocket连接服务端成功了");
// console.log('连接服务端成功了'); // console.log('连接服务端成功了');
this.connectionStatus = ConnectionStatus.CONNECTED; this.connectionStatus = ConnectionStatus.CONNECTED;
this.connectRetryCount = 0; this.connectRetryCount = 0;
this.startHeartbeat(); this.startHeartbeat();
@@ -497,7 +497,7 @@ export default class SocketService {
// 连接关闭事件 // 连接关闭事件
this.ws.onclose = (event: CloseEvent) => { this.ws.onclose = (event: CloseEvent) => {
// console.log('连接webSocket服务端关闭'); // console.log('连接webSocket服务端关闭');
this.connectionStatus = ConnectionStatus.DISCONNECTED; this.connectionStatus = ConnectionStatus.DISCONNECTED;
this.clearHeartbeat(); this.clearHeartbeat();
@@ -530,7 +530,7 @@ export default class SocketService {
// 心跳响应处理 // 心跳响应处理
if (event.data === 'over') { if (event.data === 'over') {
// console.log(`${new Date().toLocaleTimeString()} - 收到心跳响应`); // console.log(`${new Date().toLocaleTimeString()} - 收到心跳响应`);
this.lastResponseHeartTime = Date.now(); this.lastResponseHeartTime = Date.now();
return; return;
} }
@@ -553,7 +553,7 @@ export default class SocketService {
} }
} else { } else {
// 非JSON格式的消息作为普通文本处理 // 非JSON格式的消息作为普通文本处理
// console.log('收到非JSON格式消息:', event.data); // console.log('收到非JSON格式消息:', event.data);
// 可以添加文本消息的处理逻辑 // 可以添加文本消息的处理逻辑
if (this.callBackMapping['text']) { if (this.callBackMapping['text']) {
this.callBackMapping['text']({ this.callBackMapping['text']({
@@ -587,7 +587,7 @@ export default class SocketService {
const delay = this.config.reconnectDelay! * this.connectRetryCount; const delay = this.config.reconnectDelay! * this.connectRetryCount;
// console.log(`尝试第${this.connectRetryCount}次重连,${delay}ms后开始...`); // console.log(`尝试第${this.connectRetryCount}次重连,${delay}ms后开始...`);
setTimeout(() => { setTimeout(() => {
try { try {
@@ -674,7 +674,7 @@ export default class SocketService {
*/ */
private sendHeartbeat(): void { private sendHeartbeat(): void {
if (this.connected && this.ws) { if (this.connected && this.ws) {
// console.log(`${new Date().toLocaleTimeString()} - 发送心跳消息`); // console.log(`${new Date().toLocaleTimeString()} - 发送心跳消息`);
this.ws.send('alive'); this.ws.send('alive');
} }
} }