Skip to content

Commit 8537a78

Browse files
committed
fix(view): websocket 获取数据列表
1 parent e96c961 commit 8537a78

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

admin/src/views/api_excel/index.vue

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
</template>
128128

129129
<script>
130+
import { getToken } from '@/utils/auth'
130131
import { getList, deleteAct, search, startTask, download_log } from '@/api/api_excel'
131132
132133
export default {
@@ -159,7 +160,8 @@ export default {
159160
this.currentpage = parseInt(this.listQuery.page)
160161
const perPage = parseInt(this.$route.query.perPage)
161162
this.perpage = isNaN(perPage) ? this.perpage : perPage
162-
this.fetchData()
163+
// this.fetchData()
164+
this.initWebSocket()
163165
},
164166
destroyed() {
165167
this.websock.close() // 离开路由之后断开 websocket 连接
@@ -217,9 +219,10 @@ export default {
217219
}
218220
})
219221
},
220-
initWebSocket(id) { // 初始化 weosocket
222+
initWebSocket() { // 初始化 weosocket
221223
if ('WebSocket' in window) {
222-
const url = 'wss://www.guke1.com/ws?id=' + id
224+
// const url = 'wss://www.guke1.com/ws?id=' + id
225+
const url = 'ws://localhost:5200?action=api_excel&token=' + getToken()
223226
this.websock = new WebSocket(url)
224227
this.websock.onmessage = this.onmessage
225228
this.websock.onopen = this.onopen
@@ -235,15 +238,27 @@ export default {
235238
// const rs = this.send(JSON.stringify(actions))
236239
// console.log(rs)
237240
},
238-
onerror() { // 连接建立失败重连
241+
onerror() {
242+
// 连接建立失败, 发送 http 请求获取数据
239243
// this.initWebSocket()
244+
this.fetchData()
240245
},
241246
onmessage(e) { // 数据接收
242-
console.log(e.data)
247+
// console.log(e.data)
243248
const data = JSON.parse(e.data)
244249
// this.list[2].rate = parseInt(data.data.rate)
245250
// console.log(this.list[2].rate)
246251
console.log(data)
252+
// websocket 返回的数据
253+
this.list = data.data.data
254+
this.listLoading = false
255+
this.total = data.data.total
256+
this.url = data.data.appUrl
257+
// console.log('type', Object.prototype.toString.call(this.list))
258+
setTimeout(() => {
259+
this.reload = false
260+
this.reload_name = '刷新'
261+
}, 800)
247262
},
248263
send(Data) {
249264
this.websock.send(Data)
@@ -276,7 +291,7 @@ export default {
276291
this.reload = false
277292
this.reload_name = '刷新'
278293
}, 800)
279-
this.initWebSocket(8)
294+
// this.initWebSocket()
280295
})
281296
},
282297
handleEdit(index, row) {

0 commit comments

Comments
 (0)