@@ -342,13 +342,21 @@ export default {
342342 })
343343 },
344344 initWebSocket () { // 初始化 weosocket
345+ const that = this
345346 if (' WebSocket' in window ) {
346347 const url = process .env .VUE_APP_WEBSOCKET + ' ?action=api_excel&token=' + getToken () + ' &page=' + this .currentpage + ' &perPage=' + this .perpage
347348 this .websock = new WebSocket (url)
348349 this .websock .onmessage = this .onmessage
349350 this .websock .onopen = this .onopen
350351 this .websock .onerror = this .onerror
351352 this .websock .onclose = this .close
353+
354+ setInterval (function () {
355+ if (that .websock && that .websock .readyState === that .websock .OPEN ) {
356+ // console.log('inSend')
357+ that .send (' {"page":1}' )
358+ }
359+ }, 5000 )
352360 } else {
353361 this .fetchData ()
354362 // 浏览器不支持 WebSocket,使用 ajax 轮询
@@ -359,34 +367,36 @@ export default {
359367 // const actions = { 'id': '7' }
360368 // const rs = this.send(JSON.stringify(actions))
361369 // console.log(rs)
370+ setTimeout (() => {
371+ this .reload = false
372+ this .reload_name = ' 刷新'
373+ }, 800 )
362374 },
363375 onerror () {
364376 // 连接建立失败, 发送 http 请求获取数据
365377 // this.initWebSocket()
366378 this .fetchData ()
367379 },
368380 onmessage (e ) { // 数据接收
369- // console.log(e.data)
370381 const data = JSON .parse (e .data )
371- // this.list[2].rate = parseInt(data.data.rate)
372- // console.log(this.list[2].rate)
373- // console.log(data)
374- // websocket 返回的数据
375- this .list = data .data .data
376- this .listLoading = false
377- this .total = data .data .total
378- this .url = data .data .appUrl
379- // console.log('type', Object.prototype.toString.call(this.list))
380- setTimeout (() => {
381- this .reload = false
382- this .reload_name = ' 刷新'
383- }, 800 )
382+ // console.log(data.data)
383+ if (data && data .data ) {
384+ // this.list[2].rate = parseInt(data.data.rate)
385+ // console.log(this.list[2].rate)
386+ // console.log(data)
387+ // websocket 返回的数据
388+ this .list = data .data .data
389+ this .listLoading = false
390+ this .total = data .data .total
391+ this .url = data .data .appUrl
392+ // console.log('type', Object.prototype.toString.call(this.list))
393+ }
384394 },
385395 send (Data ) {
386396 this .websock .send (Data)
387397 },
388398 close () { // 关闭
389- // console.log('断开连接')
399+ console .log (' 断开连接' )
390400 },
391401 download (index , row ) {
392402 window .location .href = this .url + row .finish_url
0 commit comments