main.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <div class="mainMaster">
  3. <div class="menu">
  4. <img
  5. src="../../assets/img/logo.png"
  6. style="width: 100%; margin-bottom: 2em"
  7. alt=""
  8. />
  9. <div
  10. @click="() => selectMenuFunc(item)"
  11. v-for="(item, index) in menu"
  12. :key="index"
  13. :class="{
  14. 'menu-item': true,
  15. active: selectMenu == item.path
  16. }"
  17. >
  18. <span
  19. :class="{ menu_iconfont: true, [item.icon]: true }"
  20. style="margin-right: 5px; font-size: 20px"
  21. >
  22. </span>
  23. {{ item.title }}
  24. </div>
  25. </div>
  26. <router-view :isUp="isUp" class="rightMain" />
  27. </div>
  28. </template>
  29. <script setup>
  30. // import header_local from './components/header.vue';
  31. import { ref } from 'vue';
  32. import { ElNotification } from 'element-plus';
  33. import { useRoute, useRouter } from 'vue-router';
  34. import config from '../../config/index';
  35. const Router = useRouter();
  36. const Route = useRoute();
  37. const selectMenu = ref(Route.fullPath);
  38. const isUp = ref(0);
  39. let eventSource = null;
  40. const menu = JSON.parse(localStorage.getItem('menu') || '[]');
  41. for (let i = 0; i < menu.length; i++) {
  42. const v = menu[i];
  43. if (v.path === Route.fullPath) {
  44. document.title = v.title;
  45. break;
  46. }
  47. }
  48. const selectMenuFunc = item => {
  49. if (!item.path || Route.fullPath == item.path) return;
  50. selectMenu.value = item.path;
  51. document.title = item.title;
  52. Router.push({
  53. path: item.path,
  54. query: {}
  55. });
  56. };
  57. /**
  58. * @description: 通知权限
  59. * 1 如果用户已经同意授权,返回值为granted;
  60. * 2 如果用户已经拒绝授权,返回值为denied;
  61. * 3 如果用户还没有作出选择,返回值为default;
  62. */
  63. function notificationFunc() {
  64. return new Promise((resolve, reject) => {
  65. if (!Notification) return resolve(false);
  66. if (Notification.permission === 'granted') {
  67. resolve(true);
  68. } else {
  69. Notification.requestPermission().then(() => {
  70. resolve(true);
  71. });
  72. }
  73. });
  74. }
  75. function sse() {
  76. eventSource = new EventSource(
  77. config.base.videoProcessing +
  78. '/user/sse?token=' +
  79. localStorage.getItem('token')
  80. );
  81. eventSource.addEventListener('message', event => {
  82. // 处理来自服务器的消息
  83. const data = JSON.parse(event.data);
  84. isUp.value += 1;
  85. window.processing_getList && window.processing_getList();
  86. if (Notification) {
  87. new Notification('提示', {
  88. body: data.msg,
  89. icon: '' // 可选的图标路径
  90. });
  91. return;
  92. }
  93. ElNotification({
  94. title: '提示',
  95. message: data.msg,
  96. duration: 0
  97. });
  98. });
  99. eventSource.onerror = error => {
  100. // 处理错误
  101. console.error(error);
  102. eventSource && eventSource.close();
  103. sse();
  104. };
  105. }
  106. notificationFunc().then(isTrue => {
  107. sse();
  108. });
  109. </script>
  110. <style scoped>
  111. .mainMaster {
  112. width: 100vw;
  113. height: 100vh;
  114. min-width: 960px;
  115. overflow: auto;
  116. display: flex;
  117. }
  118. .mainMaster .menu {
  119. position: relative;
  120. display: inline-block;
  121. max-width: 230px;
  122. min-width: 200px;
  123. padding: 32px 15px 0;
  124. background-color: #393b48;
  125. height: 99.7%;
  126. flex: 1;
  127. }
  128. .mainMaster .icon {
  129. width: 1.8em;
  130. margin-right: 6px;
  131. margin-top: 0.6em;
  132. float: left;
  133. }
  134. .mainMaster .rightMain {
  135. display: inline-block;
  136. vertical-align: top;
  137. height: 100%;
  138. overflow-y: auto;
  139. flex: 1;
  140. font-size: 14px;
  141. }
  142. .menu-item {
  143. padding: 0 16px;
  144. height: 3em;
  145. line-height: 3em;
  146. cursor: pointer;
  147. font-size: 15px;
  148. color: #f3f3f3;
  149. }
  150. .mainMaster .min-item {
  151. padding-left: 5px;
  152. text-align: center;
  153. padding-right: 5px;
  154. width: 60px;
  155. background-color: #ddd;
  156. }
  157. .min-item .menu-item {
  158. padding: 10px 0px;
  159. }
  160. .min-item .icon {
  161. margin: 0;
  162. }
  163. .menu-item:hover {
  164. color: rgb(64, 158, 255);
  165. }
  166. .active {
  167. font-weight: 600;
  168. border-radius: 8px;
  169. color: rgb(64, 158, 255);
  170. background-color: rgba(0, 0, 0, 0.1);
  171. }
  172. </style>