UiHeader.vue 5.7 KB

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