From 597f2b4461eb38626cfcfc243ca0eefaf076069c Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期六, 23 十二月 2023 19:38:34 +0800
Subject: [PATCH] fix 修复 websocket 非index页面刷新无法重连问题

---
 src/layout/index.vue |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/layout/index.vue b/src/layout/index.vue
index fa43e69..0c1fb17 100644
--- a/src/layout/index.vue
+++ b/src/layout/index.vue
@@ -27,6 +27,14 @@
 import useAppStore from '@/store/modules/app';
 import useSettingsStore from '@/store/modules/settings';
 
+import { initWebSocket } from '@/utils/websocket';
+import useNoticeStore from '@/store/modules/notice';
+
+onMounted(() => {
+  let protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
+  initWebSocket(protocol + window.location.host + import.meta.env.VITE_APP_BASE_API + '/resource/websocket', useNoticeStore());
+});
+
 const settingsStore = useSettingsStore();
 const theme = computed(() => settingsStore.theme);
 const sidebar = computed(() => useAppStore().sidebar);

--
Gitblit v1.9.3