|
@@ -139,7 +139,7 @@ export default {
|
139
|
139
|
beforeRouteLeave (to, from, next) {
|
140
|
140
|
// 导航离开该组件的对应路由时调用
|
141
|
141
|
// 可以访问组件实例 `this`
|
142
|
|
- console.log(this.websockets)
|
|
142
|
+ // console.log(this.websockets)
|
143
|
143
|
this.needReload = false
|
144
|
144
|
Object.keys(this.websockets).forEach((key) => {
|
145
|
145
|
this.destroyWebsocket(this.websockets[key])
|
|
@@ -149,51 +149,54 @@ export default {
|
149
|
149
|
},
|
150
|
150
|
methods: {
|
151
|
151
|
init () {
|
152
|
|
- this.needReload = false
|
153
|
|
- Object.keys(this.websockets).forEach((key) => {
|
154
|
|
- this.destroyWebsocket(this.websockets[key])
|
155
|
|
- })
|
156
|
|
- this.websockets = {}
|
157
|
|
- this.needReload = true
|
158
|
|
- // console.log('init')
|
159
|
|
- var param = []
|
160
|
|
- if (!this.CaseId) {
|
161
|
|
- this.$message({
|
162
|
|
- type: 'info',
|
163
|
|
- message: '请先选择案场'
|
|
152
|
+ if (this.needReload) {
|
|
153
|
+ this.needReload = false
|
|
154
|
+ Object.keys(this.websockets).forEach((key) => {
|
|
155
|
+ // console.log(key, this.websockets[key])
|
|
156
|
+ this.websockets[key].close()
|
164
|
157
|
})
|
165
|
|
- return
|
166
|
|
- }
|
167
|
|
- clearInterval(this.interval)
|
168
|
|
- console.log(this.CaseId)
|
169
|
|
- this.GetOrdersList({ caseid: this.CaseId }).then((res) => {
|
170
|
|
- for (var n = 0; n < (res.list || []).length; n++) {
|
171
|
|
- if (res.list[n].IsIntimidate === 0) {
|
172
|
|
- param.push(res.list[n].OrdersId)
|
173
|
|
- }
|
|
158
|
+ this.websockets = {}
|
|
159
|
+ // console.log('init')
|
|
160
|
+ var param = []
|
|
161
|
+ if (!this.CaseId) {
|
|
162
|
+ this.$message({
|
|
163
|
+ type: 'info',
|
|
164
|
+ message: '请先选择案场'
|
|
165
|
+ })
|
|
166
|
+ return
|
174
|
167
|
}
|
175
|
|
- var bool = true
|
176
|
|
- var timer = setInterval(() => {
|
177
|
|
- if (param.length && bool) {
|
178
|
|
- bool = false
|
179
|
|
- this.printPdf(`item_${param[0]}`)
|
180
|
|
- this.putPrintGoodsOrder({
|
181
|
|
- id: param[0]
|
182
|
|
- }).then(() => {
|
183
|
|
- param.splice(0, 1)
|
184
|
|
- bool = true
|
185
|
|
- })
|
186
|
|
- } else {
|
187
|
|
- clearInterval(timer)
|
188
|
|
- }
|
189
|
|
- }, 300)
|
190
|
|
- this.getBusinessStatus(this.CaseId).then(() => {
|
191
|
|
- if (this.businessStatus) {
|
192
|
|
- this.initWebSocket()
|
|
168
|
+ clearInterval(this.interval)
|
|
169
|
+ // console.log(this.CaseId)
|
|
170
|
+ this.GetOrdersList({ caseid: this.CaseId }).then((res) => {
|
|
171
|
+ for (var n = 0; n < (res.list || []).length; n++) {
|
|
172
|
+ if (res.list[n].IsIntimidate === 0) {
|
|
173
|
+ param.push(res.list[n].OrdersId)
|
|
174
|
+ }
|
193
|
175
|
}
|
|
176
|
+ var bool = true
|
|
177
|
+ var timer = setInterval(() => {
|
|
178
|
+ if (param.length && bool) {
|
|
179
|
+ bool = false
|
|
180
|
+ this.printPdf(`item_${param[0]}`)
|
|
181
|
+ this.putPrintGoodsOrder({
|
|
182
|
+ id: param[0]
|
|
183
|
+ }).then(() => {
|
|
184
|
+ param.splice(0, 1)
|
|
185
|
+ bool = true
|
|
186
|
+ })
|
|
187
|
+ } else {
|
|
188
|
+ this.needReload = true
|
|
189
|
+ clearInterval(timer)
|
|
190
|
+ }
|
|
191
|
+ }, 300)
|
|
192
|
+ this.getBusinessStatus(this.CaseId).then(() => {
|
|
193
|
+ if (this.businessStatus) {
|
|
194
|
+ this.initWebSocket()
|
|
195
|
+ }
|
|
196
|
+ })
|
194
|
197
|
})
|
195
|
|
- })
|
196
|
|
- this.refreshList()
|
|
198
|
+ this.refreshList()
|
|
199
|
+ }
|
197
|
200
|
},
|
198
|
201
|
refreshList () {
|
199
|
202
|
this.interval = setInterval(() => {
|
|
@@ -294,9 +297,9 @@ export default {
|
294
|
297
|
// let newinfo = newList.filter(x => this.list.filter(item => item.OrdersId === x.OrdersId).length === 0)
|
295
|
298
|
this.updateList({ list: this.list.concat(newList) }).then(() => {
|
296
|
299
|
newList.forEach((it) => {
|
297
|
|
- console.log(it)
|
|
300
|
+ // console.log(it)
|
298
|
301
|
if (!it.IsIntimidate) {
|
299
|
|
- console.log('print')
|
|
302
|
+ // console.log('print')
|
300
|
303
|
this.putPrintGoodsOrder({
|
301
|
304
|
id: it.OrdersId
|
302
|
305
|
}).then(() => {
|
|
@@ -308,7 +311,7 @@ export default {
|
308
|
311
|
},
|
309
|
312
|
newWebsocket (wsRealPath) {
|
310
|
313
|
const ws = this.websockets[wsRealPath]
|
311
|
|
- console.log('newWebsocket', ws)
|
|
314
|
+ // console.log('newWebsocket', ws)
|
312
|
315
|
if (!ws) {
|
313
|
316
|
const url = `${window.location.origin.replace('http', 'ws')}${wsRealPath}?token=${localStorage.getItem('JWT')}`
|
314
|
317
|
this.websockets[wsRealPath] = new WebSocket(url)
|
|
@@ -317,12 +320,14 @@ export default {
|
317
|
320
|
this.websockets[wsRealPath].onclose = ((ws) => {
|
318
|
321
|
return e => this.reloadWebSocket(e, ws)
|
319
|
322
|
})(this.websockets[wsRealPath])
|
320
|
|
- this.websockets[wsRealPath].interval = setInterval(() => this.websockets[wsRealPath].send(10), 120000)
|
|
323
|
+ this.websockets[wsRealPath].interval = setInterval(() => {
|
|
324
|
+ try { this.websockets[wsRealPath].send(10) } catch (err) { console.log(err) }
|
|
325
|
+ }, 120000)
|
321
|
326
|
}
|
322
|
327
|
},
|
323
|
328
|
reloadWebSocket (e, ws) {
|
324
|
329
|
if (e.target.readyState >= 2) {
|
325
|
|
- console.log(e.currentTarget.url)
|
|
330
|
+ // console.log(e.currentTarget.url)
|
326
|
331
|
Object.keys(this.websockets).forEach((key) => {
|
327
|
332
|
// this.websockets[key].close()
|
328
|
333
|
clearInterval(this.websockets[key].interval)
|
|
@@ -338,7 +343,7 @@ export default {
|
338
|
343
|
},
|
339
|
344
|
destroyWebsocket (ws) {
|
340
|
345
|
ws.onclose = ((ws) => {
|
341
|
|
- console.log('close')
|
|
346
|
+ // console.log('close')
|
342
|
347
|
})(ws)
|
343
|
348
|
ws.close()
|
344
|
349
|
clearInterval(ws.interval)
|