|
@@ -102,7 +102,8 @@ export default {
|
102
|
102
|
business: false,
|
103
|
103
|
caseid: '',
|
104
|
104
|
websockets: {},
|
105
|
|
- interval: () => { }
|
|
105
|
+ interval: () => { },
|
|
106
|
+ needReload: true
|
106
|
107
|
}
|
107
|
108
|
},
|
108
|
109
|
computed: {
|
|
@@ -133,12 +134,13 @@ export default {
|
133
|
134
|
})
|
134
|
135
|
},
|
135
|
136
|
mounted () {
|
136
|
|
- setTimeout(window.location.reload, 600 * 1000)
|
|
137
|
+ // setTimeout(window.location.reload, 600 * 1000)
|
137
|
138
|
},
|
138
|
139
|
beforeRouteLeave (to, from, next) {
|
139
|
140
|
// 导航离开该组件的对应路由时调用
|
140
|
141
|
// 可以访问组件实例 `this`
|
141
|
142
|
console.log(this.websockets)
|
|
143
|
+ this.needReload = false
|
142
|
144
|
Object.keys(this.websockets).forEach((key) => {
|
143
|
145
|
console.log(key, this.websockets[key])
|
144
|
146
|
this.websockets[key].close()
|
|
@@ -148,11 +150,13 @@ export default {
|
148
|
150
|
},
|
149
|
151
|
methods: {
|
150
|
152
|
init () {
|
|
153
|
+ this.needReload = false
|
151
|
154
|
Object.keys(this.websockets).forEach((key) => {
|
152
|
155
|
console.log(key, this.websockets[key])
|
153
|
156
|
this.websockets[key].close()
|
154
|
157
|
})
|
155
|
158
|
this.websockets = {}
|
|
159
|
+ this.needReload = true
|
156
|
160
|
// console.log('init')
|
157
|
161
|
var param = []
|
158
|
162
|
if (!this.CaseId) {
|
|
@@ -307,10 +311,17 @@ export default {
|
307
|
311
|
this.websockets[wsRealPath] = new WebSocket(url)
|
308
|
312
|
this.websockets[wsRealPath].onopen = console.log
|
309
|
313
|
this.websockets[wsRealPath].onmessage = this.websocketonmessage
|
310
|
|
- this.websockets[wsRealPath].onclose = console.log
|
|
314
|
+ this.websockets[wsRealPath].onclose = this.reloadWebSocket
|
311
|
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
|
325
|
open () {
|
315
|
326
|
if (!this.CaseId) {
|
316
|
327
|
this.$message({
|