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