yuang-framework-ui-common 1.0.122 → 1.0.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -97,14 +97,18 @@ export class FrameworkSseClient {
|
|
|
97
97
|
|
|
98
98
|
this.reconnectAttempts = 0;
|
|
99
99
|
this.openHandler?.();
|
|
100
|
-
|
|
100
|
+
if(getIsDebug()) {
|
|
101
|
+
console.log('[SSE] 连接已建立(Fetch 流式)');
|
|
102
|
+
}
|
|
101
103
|
|
|
102
104
|
while (true) {
|
|
103
105
|
if (this.isManualClose) break;
|
|
104
106
|
|
|
105
107
|
const { done, value } = await reader.read();
|
|
106
108
|
if (done) {
|
|
107
|
-
|
|
109
|
+
if(getIsDebug()) {
|
|
110
|
+
console.log('[SSE] 流式响应已结束');
|
|
111
|
+
}
|
|
108
112
|
break;
|
|
109
113
|
}
|
|
110
114
|
|
|
@@ -138,7 +142,9 @@ export class FrameworkSseClient {
|
|
|
138
142
|
|
|
139
143
|
// 兼容非标准消息格式
|
|
140
144
|
if (!cleanMessage.startsWith('data:') && !cleanMessage.startsWith('event:')) {
|
|
141
|
-
|
|
145
|
+
if(getIsDebug()) {
|
|
146
|
+
console.log('[SSE] 兼容非标准消息格式:', cleanMessage);
|
|
147
|
+
}
|
|
142
148
|
const messageEvent = {
|
|
143
149
|
data: cleanMessage,
|
|
144
150
|
type: 'message'
|
|
@@ -172,7 +178,9 @@ export class FrameworkSseClient {
|
|
|
172
178
|
// 🔥 核心修复1:解析到 sseClientId 时即时处理
|
|
173
179
|
if (eventType === 'sseClientId') {
|
|
174
180
|
data = data.replace(/"/g,'');
|
|
175
|
-
|
|
181
|
+
if(getIsDebug()) {
|
|
182
|
+
console.log(`[SSE] [${this.moduleCode}] 获取到 sseClientId:`, data);
|
|
183
|
+
}
|
|
176
184
|
setLocalStorageItem(getSseClientIdKey(this.moduleCode), data, 60 * 30)
|
|
177
185
|
// 即时触发回调,同步到 Hook 的响应式变量
|
|
178
186
|
this.onSseClientIdUpdate?.(data);
|
|
@@ -204,7 +212,9 @@ export class FrameworkSseClient {
|
|
|
204
212
|
}
|
|
205
213
|
|
|
206
214
|
this.reconnectAttempts++;
|
|
207
|
-
|
|
215
|
+
if(getIsDebug()) {
|
|
216
|
+
console.log(`[SSE] 准备第 ${this.reconnectAttempts} 次重连,间隔 ${this.reconnectInterval}ms`);
|
|
217
|
+
}
|
|
208
218
|
this.reconnectTimer = window.setTimeout(() => {
|
|
209
219
|
this.connectSse();
|
|
210
220
|
this.reconnectTimer = null;
|
|
@@ -225,13 +235,17 @@ export class FrameworkSseClient {
|
|
|
225
235
|
close(): void {
|
|
226
236
|
this.isManualClose = true;
|
|
227
237
|
this.cleanup();
|
|
228
|
-
|
|
238
|
+
if(getIsDebug()) {
|
|
239
|
+
console.log(`[SSE] [${this.moduleCode}] 连接已手动关闭`);
|
|
240
|
+
}
|
|
229
241
|
}
|
|
230
242
|
|
|
231
243
|
reconnectSse(): void {
|
|
232
244
|
this.isManualClose = false;
|
|
233
245
|
this.connectSse();
|
|
234
|
-
|
|
246
|
+
if(getIsDebug()) {
|
|
247
|
+
console.log(`[SSE] [${this.moduleCode}] 触发手动重连`);
|
|
248
|
+
}
|
|
235
249
|
}
|
|
236
250
|
|
|
237
251
|
isSseConnected(): boolean {
|
|
@@ -286,7 +300,9 @@ export function useSse(
|
|
|
286
300
|
|
|
287
301
|
// 消息处理回调(仅处理业务消息)
|
|
288
302
|
const messageHandler: SseMessageHandler = (data, event) => {
|
|
289
|
-
|
|
303
|
+
if(getIsDebug()) {
|
|
304
|
+
console.log(`[SSE Hook] [${moduleCode}] 接收消息:`, data, event);
|
|
305
|
+
}
|
|
290
306
|
// 业务消息才加入列表,避免 clientId 事件混入
|
|
291
307
|
if (event?.type !== 'sseClientId') {
|
|
292
308
|
sseMessageList.value.push(data);
|
|
@@ -297,7 +313,9 @@ export function useSse(
|
|
|
297
313
|
// 连接成功回调
|
|
298
314
|
const openHandler: SseOpenHandler = () => {
|
|
299
315
|
isSseConnected.value = true;
|
|
300
|
-
|
|
316
|
+
if(getIsDebug()) {
|
|
317
|
+
console.log(`[${moduleCode}] SSE 连接成功`);
|
|
318
|
+
}
|
|
301
319
|
};
|
|
302
320
|
|
|
303
321
|
// 错误处理回调
|
|
@@ -384,7 +402,9 @@ export function useSse(
|
|
|
384
402
|
sseClient.close();
|
|
385
403
|
sseClient = null;
|
|
386
404
|
isSseConnected.value = false;
|
|
387
|
-
|
|
405
|
+
if(getIsDebug()) {
|
|
406
|
+
console.log(`[${moduleCode}] SSE 连接已断开`);
|
|
407
|
+
}
|
|
388
408
|
}
|
|
389
409
|
};
|
|
390
410
|
|
|
@@ -394,7 +414,9 @@ export function useSse(
|
|
|
394
414
|
const reconnectSse = () => {
|
|
395
415
|
if (sseClient) {
|
|
396
416
|
sseClient.reconnectSse();
|
|
397
|
-
|
|
417
|
+
if(getIsDebug()) {
|
|
418
|
+
console.log(`[${moduleCode}] 已触发 SSE 手动重连`);
|
|
419
|
+
}
|
|
398
420
|
} else {
|
|
399
421
|
console.warn(`[${moduleCode}] 暂无有效 SSE 连接,请先建立连接`);
|
|
400
422
|
}
|