Commit 3bf2e6eee58f78be92e857bb18d2d11f7e1412b8

Authored by 648540858
1 parent 6d759162

优化录像推送开关

web_src/src/components/UiHeader.vue
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 <!-- <el-menu-item index="/setting/sip">国标服务</el-menu-item>--> 15 <!-- <el-menu-item index="/setting/sip">国标服务</el-menu-item>-->
16 <!-- <el-menu-item index="/setting/media">媒体服务</el-menu-item>--> 16 <!-- <el-menu-item index="/setting/media">媒体服务</el-menu-item>-->
17 <!-- </el-submenu>--> 17 <!-- </el-submenu>-->
18 - <el-switch v-model="alarmNotify" active-text="报警信息推送" style="display: block float: right" @change="sseControl"></el-switch> 18 + <el-switch v-model="alarmNotify" active-text="报警信息推送" style="display: block float: right" @change="alarmNotifyChannge"></el-switch>
19 <!-- <el-menu-item style="float: right;" @click="loginout">退出</el-menu-item>--> 19 <!-- <el-menu-item style="float: right;" @click="loginout">退出</el-menu-item>-->
20 <el-submenu index="" style="float: right;" > 20 <el-submenu index="" style="float: right;" >
21 <template slot="title">欢迎,{{this.$cookies.get("session").username}}</template> 21 <template slot="title">欢迎,{{this.$cookies.get("session").username}}</template>
@@ -35,11 +35,23 @@ export default { @@ -35,11 +35,23 @@ export default {
35 components: { Notification, changePasswordDialog }, 35 components: { Notification, changePasswordDialog },
36 data() { 36 data() {
37 return { 37 return {
38 - alarmNotify: true, 38 + alarmNotify: false,
39 sseSource: null, 39 sseSource: null,
40 activeIndex: this.$route.path, 40 activeIndex: this.$route.path,
41 }; 41 };
42 }, 42 },
  43 + created(){
  44 + if (this.$route.path.startsWith("/channelList")){
  45 + this.activeIndex = "/deviceList"
  46 + }
  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 + },
43 methods:{ 55 methods:{
44 loginout(){ 56 loginout(){
45 this.$axios({ 57 this.$axios({
@@ -65,6 +77,10 @@ export default { @@ -65,6 +77,10 @@ export default {
65 beforeunloadHandler() { 77 beforeunloadHandler() {
66 this.sseSource.close(); 78 this.sseSource.close();
67 }, 79 },
  80 + alarmNotifyChannge(){
  81 + this.setAlarmSwitchStatus()
  82 + this.sseControl()
  83 + },
68 sseControl() { 84 sseControl() {
69 let that = this; 85 let that = this;
70 if (this.alarmNotify) { 86 if (this.alarmNotify) {
@@ -90,31 +106,35 @@ export default { @@ -90,31 +106,35 @@ export default {
90 } 106 }
91 }, false); 107 }, false);
92 } else { 108 } else {
93 - this.sseSource.removeEventListener('open', null);  
94 - this.sseSource.removeEventListener('message', null);  
95 - this.sseSource.removeEventListener('error', null);  
96 - this.sseSource.close(); 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 +
97 } 116 }
  117 + },
  118 + getAlarmSwitchStatus(){
  119 + if (localStorage.getItem("alarmSwitchStatus") == null) {
  120 + localStorage.setItem("alarmSwitchStatus", false);
  121 + }
  122 + return localStorage.getItem("alarmSwitchStatus");
  123 + },
  124 + setAlarmSwitchStatus(){
  125 + localStorage.setItem("alarmSwitchStatus", this.alarmNotify);
98 } 126 }
99 }, 127 },
100 - created(){  
101 - if (this.$route.path.startsWith("/channelList")){  
102 - this.activeIndex = "/deviceList"  
103 - }  
104 - },  
105 - mounted() {  
106 - window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))  
107 - // window.addEventListener('unload', e => this.unloadHandler(e))  
108 - this.sseControl();  
109 - },  
110 destroyed() { 128 destroyed() {
111 window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e)) 129 window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
112 - this.sseSource.removeEventListener('open', null);  
113 - this.sseSource.removeEventListener('message', null);  
114 - this.sseSource.removeEventListener('error', null);  
115 - this.sseSource.close();  
116 - // window.removeEventListener('unload', e => this.unloadHandler(e)) 130 + if (this.sseSource != null) {
  131 + this.sseSource.removeEventListener('open', null);
  132 + this.sseSource.removeEventListener('message', null);
  133 + this.sseSource.removeEventListener('error', null);
  134 + this.sseSource.close();
  135 + }
117 }, 136 },
  137 +
118 } 138 }
119 139
120 </script> 140 </script>