fix: 修复消息推送在没有登录还会建立连接

This commit is contained in:
xlsea
2024-09-11 14:36:46 +08:00
parent 07e30bd591
commit 2b14b84c67
5 changed files with 20 additions and 20 deletions

View File

@ -1,9 +1,11 @@
<script setup lang="ts">
import { computed, defineAsyncComponent } from 'vue';
import { computed, defineAsyncComponent, onMounted } from 'vue';
import { AdminLayout, LAYOUT_SCROLL_EL_ID } from '@sa/materials';
import type { LayoutMode } from '@sa/materials';
import { useAppStore } from '@/store/modules/app';
import { useThemeStore } from '@/store/modules/theme';
import { initWebSocket } from '@/utils/websocket';
import { initSSE } from '@/utils/sse';
import GlobalHeader from '../modules/global-header/index.vue';
import GlobalSider from '../modules/global-sider/index.vue';
import GlobalTab from '../modules/global-tab/index.vue';
@ -100,6 +102,12 @@ function getSiderCollapsedWidth() {
return w;
}
onMounted(() => {
const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
initWebSocket(`${protocol + window.location.host + import.meta.env.VITE_APP_BASE_API}/resource/websocket`);
initSSE(`${import.meta.env.VITE_APP_BASE_API}/resource/sse`);
});
</script>
<template>