|
|
@ -122,9 +122,30 @@ data() { |
|
|
sub: "", |
|
|
sub: "", |
|
|
isCreateSocket: false, |
|
|
isCreateSocket: false, |
|
|
page: {}, |
|
|
page: {}, |
|
|
|
|
|
tt:undefined |
|
|
}; |
|
|
}; |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
|
|
|
reconnect() { |
|
|
|
|
|
if(this.isCreateSocket) { |
|
|
|
|
|
return; |
|
|
|
|
|
}; |
|
|
|
|
|
let msgObj = { |
|
|
|
|
|
cmd: "sub", |
|
|
|
|
|
msg: this.sub, |
|
|
|
|
|
}; |
|
|
|
|
|
this.isCreateSocket = true; |
|
|
|
|
|
//没连接上会一直重连,设置延迟避免请求过多 |
|
|
|
|
|
this.tt && clearTimeout(this.tt); |
|
|
|
|
|
let th=this |
|
|
|
|
|
th.tt = setTimeout(function () { |
|
|
|
|
|
th.isCreateSocket = false; |
|
|
|
|
|
th.linkSocket(() => { |
|
|
|
|
|
th.ws.send(msgObj); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}, 4000); |
|
|
|
|
|
}, |
|
|
// 链接socket |
|
|
// 链接socket |
|
|
linkSocket(call) { |
|
|
linkSocket(call) { |
|
|
const ws = new Socket(this.wsUrl); |
|
|
const ws = new Socket(this.wsUrl); |
|
|
@ -132,10 +153,12 @@ methods: { |
|
|
this.ws = ws; |
|
|
this.ws = ws; |
|
|
call && call(); |
|
|
call && call(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
ws.on("message", (res) => { |
|
|
ws.on("message", (res) => { |
|
|
let { data, msg, code, sub, type, status, req, cmd } = res; |
|
|
let { data, msg, code, sub, type, status, req, cmd } = res; |
|
|
if (sub == this.sub && this.onRealtimeCallback) { |
|
|
if (sub == this.sub && this.onRealtimeCallback) { |
|
|
this.onRealtimeCallback(this.getMap(data)); |
|
|
this.onRealtimeCallback(this.getMap(data)); |
|
|
|
|
|
// console.info(data) |
|
|
bus.$emit('collapse', data); |
|
|
bus.$emit('collapse', data); |
|
|
} else if (type == "ping" || cmd == "ping") { |
|
|
} else if (type == "ping" || cmd == "ping") { |
|
|
this.ws.send({ |
|
|
this.ws.send({ |
|
|
@ -143,6 +166,15 @@ methods: { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
ws.on('close',()=>{ |
|
|
|
|
|
console.log('链接关闭'); |
|
|
|
|
|
this.reconnect(); |
|
|
|
|
|
}) |
|
|
|
|
|
ws.on('error',()=>{ |
|
|
|
|
|
console.log('发生异常了'); |
|
|
|
|
|
this.reconnect(); |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
// 取消订阅 |
|
|
// 取消订阅 |
|
|
unsub(pair_id, timer) { |
|
|
unsub(pair_id, timer) { |
|
|
@ -207,7 +239,6 @@ methods: { |
|
|
onErrorCallback |
|
|
onErrorCallback |
|
|
) { |
|
|
) { |
|
|
// handleClick |
|
|
// handleClick |
|
|
console.info(resolution) |
|
|
|
|
|
this.page[this.symbol] = this.page[this.symbol] || 1; |
|
|
this.page[this.symbol] = this.page[this.symbol] || 1; |
|
|
let page = this.page[this.symbol] > 3 ? 3 : this.page[this.symbol]; |
|
|
let page = this.page[this.symbol] > 3 ? 3 : this.page[this.symbol]; |
|
|
let data = { |
|
|
let data = { |
|
|
@ -289,7 +320,6 @@ methods: { |
|
|
initView() { |
|
|
initView() { |
|
|
let _this = this; |
|
|
let _this = this; |
|
|
let Tdata = new VDatafeed(this); |
|
|
let Tdata = new VDatafeed(this); |
|
|
console.info(Tdata) |
|
|
|
|
|
let widget=(_this.TView = new TradingView.widget({ |
|
|
let widget=(_this.TView = new TradingView.widget({ |
|
|
width: "100%", |
|
|
width: "100%", |
|
|
height: 590, |
|
|
height: 590, |
|
|
|