UiHeader.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div id="UiHeader">
  3. <el-menu router :default-active="activeIndex" menu-trigger="click" background-color="#001529" text-color="#fff"
  4. active-text-color="#1890ff" mode="horizontal">
  5. <el-menu-item index="/console">控制台</el-menu-item>
  6. <el-menu-item index="/live">分屏监控</el-menu-item>
  7. <el-menu-item index="/deviceList">国标设备</el-menu-item>
  8. <el-menu-item index="/map">电子地图</el-menu-item>
  9. <el-menu-item index="/streamPushList">推流列表</el-menu-item>
  10. <el-menu-item index="/streamProxyList">拉流代理</el-menu-item>
  11. <el-submenu index="/channel">
  12. <template slot="title">通道管理</template>
  13. <el-menu-item index="/channel/region">行政区划</el-menu-item>
  14. <el-menu-item index="/channel/group">业务分组</el-menu-item>
  15. </el-submenu>
  16. <el-menu-item index="/cloudRecord">云端录像</el-menu-item>
  17. <el-menu-item index="/mediaServerManger">节点管理</el-menu-item>
  18. <el-menu-item index="/parentPlatformList/15/1">国标级联</el-menu-item>
  19. <el-menu-item v-if="editUser" index="/userManager">用户管理</el-menu-item>
  20. <!-- <el-submenu index="/setting">-->
  21. <!-- <template slot="title">系统设置</template>-->
  22. <!-- <el-menu-item index="/setting/web">WEB服务</el-menu-item>-->
  23. <!-- <el-menu-item index="/setting/sip">国标服务</el-menu-item>-->
  24. <!-- <el-menu-item index="/setting/media">媒体服务</el-menu-item>-->
  25. <!-- </el-submenu>-->
  26. <!-- <el-menu-item style="float: right;" @click="loginout">退出</el-menu-item>-->
  27. <el-submenu index="" style="float: right;">
  28. <template slot="title">欢迎,{{ username }}</template>
  29. <el-menu-item @click="openDoc">在线文档</el-menu-item>
  30. <el-menu-item>
  31. <el-switch v-model="alarmNotify" inactive-text="报警信息推送" @change="alarmNotifyChannge"></el-switch>
  32. </el-menu-item>
  33. <el-menu-item @click="changePassword">修改密码</el-menu-item>
  34. <el-menu-item @click="loginout">注销</el-menu-item>
  35. </el-submenu>
  36. </el-menu>
  37. <changePasswordDialog ref="changePasswordDialog"></changePasswordDialog>
  38. </div>
  39. </template>
  40. <script>
  41. import changePasswordDialog from '../components/dialog/changePassword.vue'
  42. import userService from '../components/service/UserService'
  43. import {Notification} from 'element-ui';
  44. export default {
  45. name: "UiHeader",
  46. components: {Notification, changePasswordDialog},
  47. data() {
  48. return {
  49. alarmNotify: false,
  50. sseSource: null,
  51. username: userService.getUser().username,
  52. activeIndex: this.$route.path.indexOf("/", 1)>0?this.$route.path.substring(0, this.$route.path.indexOf("/", 1)):this.$route.path,
  53. editUser: userService.getUser() ? userService.getUser().role.id === 1 : false
  54. };
  55. },
  56. created() {
  57. console.log(34334)
  58. console.log(this.$route.path)
  59. console.log(this.$route.path.indexOf("/", 1))
  60. console.log(this.activeIndex)
  61. if (this.$route.path.startsWith("/channelList")) {
  62. this.activeIndex = "/deviceList"
  63. }
  64. },
  65. mounted() {
  66. window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
  67. this.alarmNotify = this.getAlarmSwitchStatus() === "true";
  68. // TODO: 此处延迟连接 sse, 避免 sse 连接时 browserId 还未生成, 后续待优化
  69. setTimeout(() => {
  70. this.sseControl()
  71. }, 3000);
  72. },
  73. methods: {
  74. loginout() {
  75. this.$axios({
  76. method: 'get',
  77. url: "/api/user/logout"
  78. }).then((res) => {
  79. // 删除用户信息,回到登录页面
  80. userService.clearUserInfo()
  81. this.$router.push('/login');
  82. if (this.sseSource != null) {
  83. this.sseSource.close();
  84. }
  85. }).catch((error) => {
  86. console.error("登出失败")
  87. console.error(error)
  88. });
  89. },
  90. changePassword() {
  91. this.$refs.changePasswordDialog.openDialog()
  92. },
  93. openDoc() {
  94. console.log(process.env.BASE_API)
  95. window.open(!!process.env.BASE_API ? process.env.BASE_API + "/doc.html" : "/doc.html")
  96. },
  97. beforeunloadHandler() {
  98. this.sseSource.close();
  99. },
  100. alarmNotifyChannge() {
  101. this.setAlarmSwitchStatus()
  102. this.sseControl()
  103. },
  104. sseControl() {
  105. let that = this;
  106. if (this.alarmNotify) {
  107. console.log("申请SSE推送API调用,浏览器ID: " + this.$browserId);
  108. this.sseSource = new EventSource('/api/emit?browserId=' + this.$browserId);
  109. this.sseSource.addEventListener('message', function (evt) {
  110. that.$notify({
  111. title: '报警信息',
  112. dangerouslyUseHTMLString: true,
  113. message: evt.data,
  114. type: 'warning',
  115. position: 'bottom-right',
  116. duration: 3000
  117. });
  118. console.log("收到信息:" + evt.data);
  119. });
  120. this.sseSource.addEventListener('open', function (e) {
  121. console.log("SSE连接打开.");
  122. }, false);
  123. this.sseSource.addEventListener('error', function (e) {
  124. if (e.target.readyState == EventSource.CLOSED) {
  125. console.log("SSE连接关闭");
  126. } else {
  127. console.log(e.target.readyState);
  128. }
  129. }, false);
  130. } else {
  131. if (this.sseSource != null) {
  132. this.sseSource.removeEventListener('open', null);
  133. this.sseSource.removeEventListener('message', null);
  134. this.sseSource.removeEventListener('error', null);
  135. this.sseSource.close();
  136. }
  137. }
  138. },
  139. getAlarmSwitchStatus() {
  140. if (localStorage.getItem("alarmSwitchStatus") == null) {
  141. localStorage.setItem("alarmSwitchStatus", false);
  142. }
  143. return localStorage.getItem("alarmSwitchStatus");
  144. },
  145. setAlarmSwitchStatus() {
  146. localStorage.setItem("alarmSwitchStatus", this.alarmNotify);
  147. }
  148. },
  149. destroyed() {
  150. window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
  151. if (this.sseSource != null) {
  152. this.sseSource.removeEventListener('open', null);
  153. this.sseSource.removeEventListener('message', null);
  154. this.sseSource.removeEventListener('error', null);
  155. this.sseSource.close();
  156. }
  157. },
  158. }
  159. </script>
  160. <style>
  161. #UiHeader .el-switch__label {
  162. color: white;
  163. }
  164. .el-menu--popup .el-menu-item .el-switch .el-switch__label {
  165. color: white !important;
  166. }
  167. #UiHeader .el-switch__label.is-active {
  168. color: #409EFF;
  169. }
  170. #UiHeader .el-menu-item.is-active {
  171. color: #fff !important;
  172. background-color: #1890ff !important;
  173. }
  174. #UiHeader .el-submenu.is-active {
  175. background-color: #1890ff !important;
  176. }
  177. #UiHeader .el-submenu.is-active .el-submenu__title {
  178. color: #fff !important;
  179. background-color: #1890ff !important;
  180. }
  181. #UiHeader .el-submenu.is-active .el-submenu__icon-arrow {
  182. color: #fff !important;
  183. }
  184. </style>