UiHeader.vue 4.9 KB

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