123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <template>
- <div class="mainMaster">
- <div class="menu">
- <img
- src="../../assets/img/logo.png"
- style="width: 100%; margin-bottom: 2em"
- alt=""
- />
- <div
- @click="() => selectMenuFunc(item)"
- v-for="(item, index) in menu"
- :key="index"
- :class="{
- 'menu-item': true,
- active: selectMenu == item.path
- }"
- >
- <span
- :class="{ menu_iconfont: true, [item.icon]: true }"
- style="margin-right: 5px; font-size: 20px"
- >
- </span>
- {{ item.title }}
- </div>
- </div>
- <router-view :isUp="isUp" class="rightMain" />
- </div>
- </template>
- <script setup>
- // import header_local from './components/header.vue';
- import { ref } from 'vue';
- import { ElNotification } from 'element-plus';
- import { useRoute, useRouter } from 'vue-router';
- import config from '../../config/index';
- const Router = useRouter();
- const Route = useRoute();
- const selectMenu = ref(Route.fullPath);
- const isUp = ref(0);
- let eventSource = null;
- const menu = JSON.parse(localStorage.getItem('menu') || '[]');
- for (let i = 0; i < menu.length; i++) {
- const v = menu[i];
- if (v.path === Route.fullPath) {
- document.title = v.title;
- break;
- }
- }
- const selectMenuFunc = item => {
- if (!item.path || Route.fullPath == item.path) return;
- selectMenu.value = item.path;
- document.title = item.title;
- Router.push({
- path: item.path,
- query: {}
- });
- };
- /**
- * @description: 通知权限
- * 1 如果用户已经同意授权,返回值为granted;
- * 2 如果用户已经拒绝授权,返回值为denied;
- * 3 如果用户还没有作出选择,返回值为default;
- */
- function notificationFunc() {
- return new Promise((resolve, reject) => {
- if (!Notification) return resolve(false);
- if (Notification.permission === 'granted') {
- resolve(true);
- } else {
- Notification.requestPermission().then(() => {
- resolve(true);
- });
- }
- });
- }
- function sse() {
- eventSource = new EventSource(
- config.base.videoProcessing +
- '/user/sse?token=' +
- localStorage.getItem('token')
- );
- eventSource.addEventListener('message', event => {
- // 处理来自服务器的消息
- const data = JSON.parse(event.data);
- isUp.value += 1;
- window.processing_getList && window.processing_getList();
- if (Notification) {
- new Notification('提示', {
- body: data.msg,
- icon: '' // 可选的图标路径
- });
- return;
- }
- ElNotification({
- title: '提示',
- message: data.msg,
- duration: 0
- });
- });
- eventSource.onerror = error => {
- // 处理错误
- console.error(error);
- eventSource && eventSource.close();
- sse();
- };
- }
- notificationFunc().then(isTrue => {
- sse();
- });
- </script>
- <style scoped>
- .mainMaster {
- width: 100vw;
- height: 100vh;
- min-width: 960px;
- overflow: auto;
- display: flex;
- }
- .mainMaster .menu {
- position: relative;
- display: inline-block;
- max-width: 230px;
- min-width: 200px;
- padding: 32px 15px 0;
- background-color: #393b48;
- height: 99.7%;
- flex: 1;
- }
- .mainMaster .icon {
- width: 1.8em;
- margin-right: 6px;
- margin-top: 0.6em;
- float: left;
- }
- .mainMaster .rightMain {
- display: inline-block;
- vertical-align: top;
- height: 100%;
- overflow-y: auto;
- flex: 1;
- font-size: 14px;
- }
- .menu-item {
- padding: 0 16px;
- height: 3em;
- line-height: 3em;
- cursor: pointer;
- font-size: 15px;
- color: #f3f3f3;
- }
- .mainMaster .min-item {
- padding-left: 5px;
- text-align: center;
- padding-right: 5px;
- width: 60px;
- background-color: #ddd;
- }
- .min-item .menu-item {
- padding: 10px 0px;
- }
- .min-item .icon {
- margin: 0;
- }
- .menu-item:hover {
- color: rgb(64, 158, 255);
- }
- .active {
- font-weight: 600;
- border-radius: 8px;
- color: rgb(64, 158, 255);
- background-color: rgba(0, 0, 0, 0.1);
- }
- </style>
|