Skip to content

Commit 7aa8acf

Browse files
committed
fix(view): 增加 websocket 配置
1 parent 247885f commit 7aa8acf

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

admin/config/dev.env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ const prodEnv = require('./prod.env')
55
module.exports = merge(prodEnv, {
66
NODE_ENV: '"development"',
77
BASE_API: '"http://localhost:8000"',
8+
WEBSOCKET: '"ws://127.0.0.1:5200"',
89
})

admin/config/prod.env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
module.exports = {
33
NODE_ENV: '"production"',
44
BASE_API: '"https://www.guke1.com"',
5+
WEBSOCKET: '"wss://www.guke1.com/ws"',
56
}

admin/src/views/api_excel/index.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,14 @@ export default {
222222
},
223223
initWebSocket() { // 初始化 weosocket
224224
if ('WebSocket' in window) {
225-
// const url = 'wss://www.guke1.com/ws?action=api_excel&token=' + getToken()
226-
const url = 'ws://localhost:5200?action=api_excel&token=' + getToken()
225+
const url = process.env.WEBSOCKET + '?action=api_excel&token=' + getToken()
227226
this.websock = new WebSocket(url)
228227
this.websock.onmessage = this.onmessage
229228
this.websock.onopen = this.onopen
230229
this.websock.onerror = this.onerror
231230
this.websock.onclose = this.close
232231
} else {
232+
this.fetchData()
233233
// 浏览器不支持 WebSocket,使用 ajax 轮询
234234
console.log('Your browser does not support WebSocket!')
235235
}
@@ -249,7 +249,7 @@ export default {
249249
const data = JSON.parse(e.data)
250250
// this.list[2].rate = parseInt(data.data.rate)
251251
// console.log(this.list[2].rate)
252-
console.log(data)
252+
// console.log(data)
253253
// websocket 返回的数据
254254
this.list = data.data.data
255255
this.listLoading = false
@@ -265,14 +265,14 @@ export default {
265265
this.websock.send(Data)
266266
},
267267
close() { // 关闭
268-
console.log('断开连接')
268+
// console.log('断开连接')
269269
},
270270
download(index, row) {
271271
window.location.href = this.url + row.finish_url
272272
},
273273
download_log(index, row) {
274274
download_log({ id: row.id }).then(res => {
275-
console.log(res)
275+
// console.log(res)
276276
if (res.code === 200) {
277277
window.location.href = this.url + res.data.failed_done_file
278278
}

0 commit comments

Comments
 (0)