feat: 增加代课下单收到商品信息变动时重新获取商品信息初始化购物车数据

This commit is contained in:
2025-03-18 14:03:07 +08:00
parent cefabae276
commit 735b325fd3
7 changed files with 274 additions and 73 deletions

View File

@@ -34,6 +34,7 @@ class WebSocketManager {
private maxReconnectAttempts = 10; // 自定义最大重试次数
private reconnectDelay = 5000; // 重试延迟(单位:毫秒)
private timer: any | null = null;
private reconnectTimer: any | null = null
// 初始化 WebSocket 客户端
setupWebSocket() {
@@ -142,7 +143,6 @@ class WebSocketManager {
this.autoConnect = false;
}
}
// 自动重连机制
private reconnect() {
if (!this.autoConnect) {
@@ -151,10 +151,11 @@ class WebSocketManager {
if (this.reconnectAttempts < this.maxReconnectAttempts) {
this.reconnectAttempts++;
console.log(`尝试第 ${this.reconnectAttempts} 次重连...`);
setTimeout(() => {
this.reconnectTimer = setTimeout(() => {
this.setupWebSocket();
}, this.reconnectDelay);
} else {
clearTimeout(this.reconnectTimer);
console.error("达到最大重连次数,停止重连");
ElMessageBox.confirm('达到最大重连次数' + this.maxReconnectAttempts + '次,已停止重连,是否立即重连?', '提示', {
confirmButtonText: '确定',
@@ -177,6 +178,10 @@ class WebSocketManager {
clearInterval(this.timer);
this.timer = null;
}
if (this.reconnectTimer) {
clearInterval(this.reconnectTimer);
this.reconnectTimer = null;
}
}
}