fix: 修复开发环境实时连接握手失败

- 开发代理转发线上接口时,WebSocket 握手补 changeOrigin 与 Origin 改写
- 实时连接握手连续失败两次后停止重连
- 版本号升至 4.11.1
This commit is contained in:
Ray.Hao
2026-10-30 17:39:50 +08:00
parent f443eb6bbe
commit 1383b58e80
8 changed files with 83 additions and 154 deletions

View File

@@ -36,7 +36,7 @@ export function configureVxeUI() {
VxeUI.setConfig({
// 全局尺寸
size: "medium",
// 全局 zIndex 起始值,默认是 999,如果项目的的 z-index 样式值过大时就需要跟随设置更大,避免被遮挡
// 全局 zIndex 起始值,默认是 999,如果项目的 z-index 样式值过大时就需要跟随设置更大,避免被遮挡
zIndex: 9999,
// 版本号,对于某些带数据缓存的功能有用到,上升版本号可以用于重置数据
version: 0,

View File

@@ -115,7 +115,6 @@ export const useTagsViewStore = defineStore("tagsView", () => {
if (index > -1) {
cachedViews.value = cachedViews.value.slice(index, index + 1);
} else {
// if index = -1, there is no cached tags
cachedViews.value = [];
}
resolve([...cachedViews.value]);

View File

@@ -39,6 +39,8 @@ interface ConnectionAttempt {
type MessageHandler = (message: RealtimeServerMessage) => void;
const MAX_RECONNECT_ATTEMPTS = 10;
// 从未握手成功时只重试两次,服务端不可用时直接停止
const MAX_HANDSHAKE_ATTEMPTS = 2;
const MAX_BUFFERED_BYTES = 16_384;
const STOP_RECONNECT_CODES = new Set([1000, 1008, 1009, 4003, 4009]);
@@ -129,6 +131,12 @@ export function createRealtimeClient(options: RealtimeClientOptions) {
}
}
if (!retry && enabled) blocked = true;
// 从未连上时快速放弃,避免服务端不可用时反复重连
if (retry && !attempt.connectedAt && retryCount >= MAX_HANDSHAKE_ATTEMPTS) {
enabled = false;
blocked = true;
return;
}
if (retry) scheduleRetry(minimumDelay);
}