Browse Source

优化

master
ltlzx 4 years ago
parent
commit
266457a2a6
  1. 14
      src/api/custom/Model.js
  2. 3
      src/api/custom/Socket.js
  3. 2
      src/api/server/Socket.js
  4. 7
      src/components/KLine.vue
  5. 14
      src/views/exchange/index.vue
  6. 2
      src/views/exchange/make-deal.vue
  7. 2
      src/views/exchange/symbols.vue

14
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('<<<<<<<<<New');
// 检测是否已经加载历史数据

3
src/api/custom/Socket.js

@ -2,7 +2,6 @@
class Socket {
constructor(ws, ...args) {
// 初始化socket
if (ws.constructor == WebSocket) {
this.socket = ws;
@ -14,7 +13,7 @@ class Socket {
this.doOpen();
this.readyState = 0;
this.readyState = this.socket.readyState;
// 订阅/发布模型
this._events = {

2
src/api/server/Socket.js

@ -1,7 +1,6 @@
class Socket {
constructor(link, ...args) {
// 初始化socket
if (link.constructor === WebSocket) {
this.socket = link;
@ -15,7 +14,6 @@ class Socket {
// 连接状态的标识符
this.readyState = this.socket.readyState;
// 订阅/发布模型
this._events = {
// 订阅的事件 : 发布的方法

7
src/components/KLine.vue

@ -363,21 +363,26 @@ export default {
// symbol getSymbolgetBar
this.model.setSymbol(newVal);
}
}
},
},
created() {
bus.$on('sendMsg', msg => {
// 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);

14
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()
});
}

2
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{

2
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()

Loading…
Cancel
Save