From fd01b5a61f1a92db90c00e7bb1b4162a2b61bfa3 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期三, 04 十二月 2024 11:42:07 +0800 Subject: [PATCH] update 优化 白名单支持对通配符路径匹配 --- src/utils/sse.ts | 21 +++++++++------------ 1 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/utils/sse.ts b/src/utils/sse.ts index a08f282..69447ad 100644 --- a/src/utils/sse.ts +++ b/src/utils/sse.ts @@ -2,26 +2,25 @@ import { ElNotification } from 'element-plus'; import useNoticeStore from '@/store/modules/notice'; -let message = ''; - // 鍒濆鍖� export const initSSE = (url: any) => { - url = url + '?Authorization=Bearer ' + getToken() + '&clientid=' + import.meta.env.VITE_APP_CLIENT_ID - const { - data, - error - } = useEventSource(url, [], { + if (import.meta.env.VITE_APP_SSE === 'false') { + return; + } + + url = url + '?Authorization=Bearer ' + getToken() + '&clientid=' + import.meta.env.VITE_APP_CLIENT_ID; + const { data, error } = useEventSource(url, [], { autoReconnect: { retries: 10, delay: 3000, onFailed() { - console.log('Failed to connect after 10 retries') - }, + console.log('Failed to connect after 10 retries'); + } } }); watch(error, () => { - console.log('SSE connection error:', error.value) + console.log('SSE connection error:', error.value); error.value = null; }); @@ -41,5 +40,3 @@ data.value = null; }); }; - - -- Gitblit v1.9.3