UiHeader.vue 5.8 KB

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