2025-03-31 18:24:37 +08:00
|
|
|
<template>
|
|
|
|
<div class="app-wrapper">
|
|
|
|
<v-sidebar />
|
|
|
|
<v-header />
|
|
|
|
<div class="main-container">
|
|
|
|
<div class="app-main" :class="{ 'content-collapse': sidebar.collapse }">
|
2025-04-01 13:52:57 +08:00
|
|
|
<router-view v-slot="{ Component }">
|
|
|
|
<transition name="move" mode="out-in">
|
2025-04-10 19:00:17 +08:00
|
|
|
<keep-alive :include="[]">
|
2025-04-01 13:52:57 +08:00
|
|
|
<component :is="Component"></component>
|
|
|
|
</keep-alive>
|
|
|
|
</transition>
|
|
|
|
</router-view>
|
2025-03-31 18:24:37 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2025-04-22 18:31:46 +08:00
|
|
|
<Alarm ref="alarmRef" />
|
|
|
|
<audio ref="audioPlayer" hidden>
|
|
|
|
<source src="../assets/audio/alarm.mp3" type="audio/mpeg" />
|
|
|
|
</audio>
|
2025-03-31 18:24:37 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { useSidebarStore } from "@/store/sidebar";
|
|
|
|
import vHeader from "@/components/header.vue";
|
|
|
|
import vSidebar from "@/components/sidebar.vue";
|
2025-04-12 18:35:54 +08:00
|
|
|
import { inject, onBeforeUnmount, onMounted, ref } from "vue";
|
2025-04-22 18:31:46 +08:00
|
|
|
import { format } from "@/utils";
|
|
|
|
import Alarm from "@/components/alarm.vue";
|
2025-04-25 18:23:20 +08:00
|
|
|
import { ElMessageBox } from "element-plus";
|
2025-03-31 18:24:37 +08:00
|
|
|
|
2025-04-22 18:31:46 +08:00
|
|
|
const ws: any = inject("ws");
|
2025-03-31 18:24:37 +08:00
|
|
|
const sidebar = useSidebarStore();
|
2025-04-11 18:46:52 +08:00
|
|
|
const audioPlayer = ref(null);
|
2025-04-22 18:31:46 +08:00
|
|
|
const alarmRef = ref();
|
2025-04-11 18:46:52 +08:00
|
|
|
|
2025-04-12 18:35:54 +08:00
|
|
|
const handleBeforeUnload = (event: any) => {
|
|
|
|
localStorage.removeItem("isReload");
|
2025-04-11 18:46:52 +08:00
|
|
|
};
|
2025-04-12 18:35:54 +08:00
|
|
|
|
2025-04-22 18:31:46 +08:00
|
|
|
const onMessage = (res) => {
|
|
|
|
if (res.cmd == "warning") {
|
|
|
|
alarmRef.value.visible = true;
|
|
|
|
alarmRef.value.warningList.unshift({ ...res, createTime: format(new Date(), "HH:mm:ss") });
|
|
|
|
if (audioPlayer.value) {
|
|
|
|
audioPlayer.value.play().catch((error) => {
|
|
|
|
console.error("自动播放被阻止:", error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-04-12 18:35:54 +08:00
|
|
|
onMounted(() => {
|
2025-04-29 09:43:10 +08:00
|
|
|
// const isReload = localStorage.getItem("isReload");
|
|
|
|
// if (isReload !== "true") {
|
|
|
|
// ElMessageBox.alert("由于浏览器安全策略,用户必须点击屏幕才能播放告警声音", "提示", {
|
|
|
|
// confirmButtonText: "OK",
|
|
|
|
// callback: () => {
|
|
|
|
// localStorage.setItem("isReload", "true");
|
|
|
|
// },
|
|
|
|
// });
|
|
|
|
// }
|
2025-04-12 18:35:54 +08:00
|
|
|
|
2025-04-29 09:43:10 +08:00
|
|
|
// if (ws.socket == null) {
|
|
|
|
// ws.connect();
|
|
|
|
// }
|
|
|
|
// ws.onMessage(onMessage);
|
2025-04-28 17:18:11 +08:00
|
|
|
|
2025-04-12 18:35:54 +08:00
|
|
|
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
|
|
});
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
|
|
});
|
2025-03-31 18:24:37 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="less">
|
2025-04-01 18:07:18 +08:00
|
|
|
// @media screen and (max-width: 800px) {
|
|
|
|
// .main-container {
|
|
|
|
// margin-left: 0 !important;
|
|
|
|
// }
|
|
|
|
// .sidebar-container {
|
|
|
|
// width: 0 !important;
|
|
|
|
// }
|
|
|
|
// .app-wrapper-header {
|
|
|
|
// width: 100% !important;
|
|
|
|
// }
|
|
|
|
// }
|
2025-03-31 18:24:37 +08:00
|
|
|
.app-wrapper {
|
|
|
|
position: relative;
|
|
|
|
width: 100%;
|
|
|
|
height: 100vh;
|
|
|
|
background: #f0f2f5;
|
|
|
|
overflow: hidden;
|
|
|
|
.main-container {
|
|
|
|
height: 100vh;
|
|
|
|
margin-left: 210px;
|
|
|
|
min-height: 100%;
|
|
|
|
position: relative;
|
|
|
|
transition: 0.3s;
|
|
|
|
background-color: #f2f4fa;
|
|
|
|
}
|
|
|
|
.app-main {
|
2025-04-01 13:52:57 +08:00
|
|
|
// height: 100vh;
|
|
|
|
height: calc(100vh - 90px);
|
2025-03-31 18:24:37 +08:00
|
|
|
position: relative;
|
|
|
|
width: 100%;
|
2025-04-01 13:52:57 +08:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
// padding-top: 70px;
|
|
|
|
margin-top: 70px;
|
2025-03-31 18:24:37 +08:00
|
|
|
box-sizing: border-box;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|