ytj 6 年前
父节点
当前提交
229971e326
共有 1 个文件被更改,包括 14 次插入3 次删除
  1. 14
    3
      src/pages/system/newOrder/newOrderList/index.vue

+ 14
- 3
src/pages/system/newOrder/newOrderList/index.vue 查看文件

102
       business: false,
102
       business: false,
103
       caseid: '',
103
       caseid: '',
104
       websockets: {},
104
       websockets: {},
105
-      interval: () => { }
105
+      interval: () => { },
106
+      needReload: true
106
     }
107
     }
107
   },
108
   },
108
   computed: {
109
   computed: {
133
     })
134
     })
134
   },
135
   },
135
   mounted () {
136
   mounted () {
136
-    setTimeout(window.location.reload, 600 * 1000)
137
+    // setTimeout(window.location.reload, 600 * 1000)
137
   },
138
   },
138
   beforeRouteLeave (to, from, next) {
139
   beforeRouteLeave (to, from, next) {
139
     // 导航离开该组件的对应路由时调用
140
     // 导航离开该组件的对应路由时调用
140
     // 可以访问组件实例 `this`
141
     // 可以访问组件实例 `this`
141
     console.log(this.websockets)
142
     console.log(this.websockets)
143
+    this.needReload = false
142
     Object.keys(this.websockets).forEach((key) => {
144
     Object.keys(this.websockets).forEach((key) => {
143
       console.log(key, this.websockets[key])
145
       console.log(key, this.websockets[key])
144
       this.websockets[key].close()
146
       this.websockets[key].close()
148
   },
150
   },
149
   methods: {
151
   methods: {
150
     init () {
152
     init () {
153
+      this.needReload = false
151
       Object.keys(this.websockets).forEach((key) => {
154
       Object.keys(this.websockets).forEach((key) => {
152
         console.log(key, this.websockets[key])
155
         console.log(key, this.websockets[key])
153
         this.websockets[key].close()
156
         this.websockets[key].close()
154
       })
157
       })
155
       this.websockets = {}
158
       this.websockets = {}
159
+      this.needReload = true
156
       // console.log('init')
160
       // console.log('init')
157
       var param = []
161
       var param = []
158
       if (!this.CaseId) {
162
       if (!this.CaseId) {
307
         this.websockets[wsRealPath] = new WebSocket(url)
311
         this.websockets[wsRealPath] = new WebSocket(url)
308
         this.websockets[wsRealPath].onopen = console.log
312
         this.websockets[wsRealPath].onopen = console.log
309
         this.websockets[wsRealPath].onmessage = this.websocketonmessage
313
         this.websockets[wsRealPath].onmessage = this.websocketonmessage
310
-        this.websockets[wsRealPath].onclose = console.log
314
+        this.websockets[wsRealPath].onclose = this.reloadWebSocket
311
         setInterval(() => this.websockets[wsRealPath].send(10), 120000)
315
         setInterval(() => this.websockets[wsRealPath].send(10), 120000)
312
       }
316
       }
313
     },
317
     },
318
+    reloadWebSocket (e) {
319
+      console.log(e.currentTarget.url)
320
+      if (this.needReload) { // 此变量判断是否需要重连
321
+        this.websockets = {}
322
+        this.initWebSocket()
323
+      }
324
+    },
314
     open () {
325
     open () {
315
       if (!this.CaseId) {
326
       if (!this.CaseId) {
316
         this.$message({
327
         this.$message({