UiHeader.vue 5.3 KB

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