From 9b96a283e000b8eca1fbea3a4dc77c8adb65fe7d Mon Sep 17 00:00:00 2001 From: guoapeng Date: Sat, 14 Jun 2025 10:58:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B7=A5=E8=89=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/default.vue | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/layouts/default.vue b/src/layouts/default.vue index 21aa06f..c4bec15 100644 --- a/src/layouts/default.vue +++ b/src/layouts/default.vue @@ -8,13 +8,14 @@ import Liquid from 'components/home/Liquid/index.vue' import Check from 'components/system/Check/index.vue' import EditDate from 'components/system/EditDate/index.vue' import Stop from 'components/system/Stop/index.vue' +import { ElMessageBox } from 'element-plus' import { useActivateDebug } from 'hooks/useActivateDebug' import { useServerTime } from 'hooks/useServerTime' -import { isClose } from 'libs/socket' +import { isClose, socket } from 'libs/socket' import { authRoutes } from 'router/routes' import { useDebugStore } from 'stores/debugStore' import { useSystemStore } from 'stores/systemStore' -import { computed, onMounted, ref, watch } from 'vue' +import { computed, onMounted, onUnmounted, ref, watch } from 'vue' import { useRouter } from 'vue-router' const { handleLogoClick } = useActivateDebug() @@ -23,6 +24,36 @@ const { currentTime } = useServerTime() const systemStore = useSystemStore() const router = useRouter() +onMounted(() => { + socket.init(receiveMessage, 'alarm') +}) + +onUnmounted(() => { + socket.unregisterCallback(receiveMessage, 'alarm') +}) + +let flag = false + +const receiveMessage = async (data: any) => { + if (flag) { + return + } + flag = true + await ElMessageBox.confirm( + data, + '提示', + { + confirmButtonText: '确认', + showClose: false, + showCancelButton: false, + closeOnClickModal: false, + closeOnPressEscape: false, + type: 'warning', + }, + ) + flag = false +} + watch(() => currentTime.value, () => { systemStore.currentTime = currentTime.value }) @@ -42,6 +73,7 @@ watch(() => systemStore.systemStatus, () => { } }) onMounted(async () => { + socket.init(receiveMessage, 'alarm') console.log('systemStatus', systemStore.systemStatus) if (!systemStore.systemStatus.currentUser) { await router.push('/login')