diff --git a/src/api/custom/Model.js b/src/api/custom/Model.js index 25f3119..be8b105 100644 --- a/src/api/custom/Model.js +++ b/src/api/custom/Model.js @@ -15,7 +15,6 @@ class Model { * @param {Object} unsub_params 取消订阅的参数 */ constructor(link, view) { - this.socket = new Socket(link); this.view = view; @@ -82,7 +81,11 @@ class Model { this.widget = new TradingView.widget(servlet(settings)); } - + //重连WS后的操作 + conglian(link){ + this.socket = new Socket(link); + this.socket.on('message', this.handleMessage.bind(this)); + } /** * 发起订阅新的数据 * @param {Array|Object} sub_params 所有订阅参数 @@ -102,12 +105,12 @@ class Model { sendMessage(data) { // debugger console.log(">>>>>>>>>>" + JSON.stringify(data)); - // 已经open状态 if (this.socket.checkOpen()) this.socket.send(data); - else { + else{ // 先open 再send this.socket.on('open', (evt) => { + console.info(this.socket) this.socket.send(data); }) } @@ -119,7 +122,7 @@ class Model { // 处理历史数据和动态更新的数据 handleMessage(response) { - + // if (response.sub != "history" && response.sub != "dynamic") return; let { data = null, sub = null, type = null } = response; @@ -156,7 +159,6 @@ class Model { this.lastTime = list[list.length - 1].time; } else if (type == "dynamic") { - // 最新的数据值 // console.log('<<<<<<<< { + // console.info(msg) + // this.model = new Model(msg, this); + this.model.conglian(msg) this.model.subscribe([ { cmd: "sub", msg: `Kline_${this.symbol}_${this.interval}min` } ]); + }); }, mounted() { + console.info(this.socket) // 初始化模型对象 建立ws连接 this.model = new Model(this.socket, this); diff --git a/src/views/exchange/index.vue b/src/views/exchange/index.vue index 6566c1f..c714728 100644 --- a/src/views/exchange/index.vue +++ b/src/views/exchange/index.vue @@ -412,7 +412,7 @@ export default { this.ws = new Socket(`${this.Globals.Server.Path.WS}`); this.ws.on("open", () => { if(this.isLianjie){ - bus.$emit('sendMsg'); + bus.$emit('sendMsg',this.ws.socket); this.isLianjie=false } // 连接成功后 初始化订阅市场信息 @@ -474,13 +474,15 @@ export default { }); this.ws.on("close", () => { - this.$message({ - type: "error", - message: this.$t("nav.b8"), - duration: 2000, - }); + // this.$message({ + // type: "error", + // message: this.$t("nav.b8"), + // duration: 2000, + // }); this.isLianjie=true this.initWs() + // if (this.symbol) this.getCurrencyExCny(); + // this.indexList() }); } diff --git a/src/views/exchange/make-deal.vue b/src/views/exchange/make-deal.vue index a064ac3..4d2f233 100644 --- a/src/views/exchange/make-deal.vue +++ b/src/views/exchange/make-deal.vue @@ -417,7 +417,7 @@ export default { methods: { getCoinInfo(){ - console.log(this.symbol.indexOf('usdt')!=-1) + // console.log(this.symbol.indexOf('usdt')!=-1) if(this.symbol.indexOf('usdt')!=-1){ var market=this.symbol.substring(0,this.symbol.length-4); }else{ diff --git a/src/views/exchange/symbols.vue b/src/views/exchange/symbols.vue index e641802..56d67df 100644 --- a/src/views/exchange/symbols.vue +++ b/src/views/exchange/symbols.vue @@ -219,7 +219,7 @@ export default { this.cacheMarketList = data; }).catch(err => {}); - console.log(this.isLogin) + // console.log(this.isLogin) // 如果已登陆 则写入收藏交易对 if (this.isLogin) { this.getCollect()