UiHeader.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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="/control">控制台</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="/pushVideoList">推流列表</el-menu-item>
  10. <el-menu-item index="/streamProxyList">拉流代理</el-menu-item>
  11. <el-menu-item index="/cloudRecord">云端录像</el-menu-item>
  12. <el-menu-item index="/mediaServerManger">节点管理</el-menu-item>
  13. <el-menu-item index="/parentPlatformList/15/1">国标级联</el-menu-item>
  14. <!-- <el-submenu index="/setting">-->
  15. <!-- <template slot="title">系统设置</template>-->
  16. <!-- <el-menu-item index="/setting/web">WEB服务</el-menu-item>-->
  17. <!-- <el-menu-item index="/setting/sip">国标服务</el-menu-item>-->
  18. <!-- <el-menu-item index="/setting/media">媒体服务</el-menu-item>-->
  19. <!-- </el-submenu>-->
  20. <!-- <el-menu-item style="float: right;" @click="loginout">退出</el-menu-item>-->
  21. <el-submenu index="" style="float: right;">
  22. <template slot="title">欢迎,{{ this.$cookies.get("session").username }}</template>
  23. <el-menu-item @click="openDoc">在线文档</el-menu-item>
  24. <el-menu-item >
  25. <el-switch v-model="alarmNotify" inactive-text="报警信息推送" @change="alarmNotifyChannge"></el-switch>
  26. </el-menu-item>
  27. <el-menu-item @click="changePassword">修改密码</el-menu-item>
  28. <el-menu-item @click="loginout">注销</el-menu-item>
  29. </el-submenu>
  30. </el-menu>
  31. <changePasswordDialog ref="changePasswordDialog"></changePasswordDialog>
  32. </div>
  33. </template>
  34. <script>
  35. import changePasswordDialog from '../components/dialog/changePassword.vue'
  36. export default {
  37. name: "UiHeader",
  38. components: {Notification, changePasswordDialog},
  39. data() {
  40. return {
  41. alarmNotify: false,
  42. sseSource: null,
  43. activeIndex: this.$route.path,
  44. };
  45. },
  46. created() {
  47. if (this.$route.path.startsWith("/channelList")) {
  48. this.activeIndex = "/deviceList"
  49. }
  50. },
  51. mounted() {
  52. window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
  53. // window.addEventListener('unload', e => this.unloadHandler(e))
  54. this.alarmNotify = this.getAlarmSwitchStatus() === "true";
  55. this.sseControl();
  56. },
  57. methods: {
  58. loginout() {
  59. this.$axios({
  60. method: 'get',
  61. url: "/api/user/logout"
  62. }).then((res) => {
  63. // 删除cookie,回到登录页面
  64. this.$cookies.remove("session");
  65. this.$router.push('/login');
  66. this.sseSource.close();
  67. }).catch((error) => {
  68. console.error("登出失败")
  69. console.error(error)
  70. });
  71. },
  72. changePassword() {
  73. this.$refs.changePasswordDialog.openDialog()
  74. },
  75. openDoc() {
  76. console.log(process.env.BASE_API)
  77. window.open(!!process.env.BASE_API ? process.env.BASE_API + "/doc.html" : "/doc.html")
  78. },
  79. beforeunloadHandler() {
  80. this.sseSource.close();
  81. },
  82. alarmNotifyChannge() {
  83. this.setAlarmSwitchStatus()
  84. this.sseControl()
  85. },
  86. sseControl() {
  87. let that = this;
  88. if (this.alarmNotify) {
  89. console.log("申请SSE推送API调用,浏览器ID: " + this.$browserId);
  90. this.sseSource = new EventSource('/api/emit?browserId=' + this.$browserId);
  91. this.sseSource.addEventListener('message', function (evt) {
  92. that.$notify({
  93. title: '收到报警信息',
  94. dangerouslyUseHTMLString: true,
  95. message: evt.data,
  96. type: 'warning'
  97. });
  98. console.log("收到信息:" + evt.data);
  99. });
  100. this.sseSource.addEventListener('open', function (e) {
  101. console.log("SSE连接打开.");
  102. }, false);
  103. this.sseSource.addEventListener('error', function (e) {
  104. if (e.target.readyState == EventSource.CLOSED) {
  105. console.log("SSE连接关闭");
  106. } else {
  107. console.log(e.target.readyState);
  108. }
  109. }, false);
  110. } else {
  111. if (this.sseSource != null) {
  112. this.sseSource.removeEventListener('open', null);
  113. this.sseSource.removeEventListener('message', null);
  114. this.sseSource.removeEventListener('error', null);
  115. this.sseSource.close();
  116. }
  117. }
  118. },
  119. getAlarmSwitchStatus() {
  120. if (localStorage.getItem("alarmSwitchStatus") == null) {
  121. localStorage.setItem("alarmSwitchStatus", false);
  122. }
  123. return localStorage.getItem("alarmSwitchStatus");
  124. },
  125. setAlarmSwitchStatus() {
  126. localStorage.setItem("alarmSwitchStatus", this.alarmNotify);
  127. }
  128. },
  129. destroyed() {
  130. window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
  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. </script>
  140. <style>
  141. #UiHeader .el-switch__label {
  142. color: white ;
  143. }
  144. .el-menu--popup .el-menu-item .el-switch .el-switch__label {
  145. color: white !important;
  146. }
  147. #UiHeader .el-switch__label.is-active{
  148. color: #409EFF;
  149. }
  150. #UiHeader .el-menu-item.is-active {
  151. color: #fff!important;
  152. background-color: #1890ff!important;
  153. }
  154. </style>