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 取消订阅的参数 * @param {Object} unsub_params 取消订阅的参数
*/ */
constructor(link, view) { constructor(link, view) {
this.socket = new Socket(link); this.socket = new Socket(link);
this.view = view; this.view = view;
@ -82,7 +81,11 @@ class Model {
this.widget = new TradingView.widget(servlet(settings)); 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 所有订阅参数 * @param {Array|Object} sub_params 所有订阅参数
@ -102,12 +105,12 @@ class Model {
sendMessage(data) { sendMessage(data) {
// debugger // debugger
console.log(">>>>>>>>>>" + JSON.stringify(data)); console.log(">>>>>>>>>>" + JSON.stringify(data));
// 已经open状态 // 已经open状态
if (this.socket.checkOpen()) this.socket.send(data); if (this.socket.checkOpen()) this.socket.send(data);
else { else{
// 先open 再send // 先open 再send
this.socket.on('open', (evt) => { this.socket.on('open', (evt) => {
console.info(this.socket)
this.socket.send(data); this.socket.send(data);
}) })
} }
@ -119,7 +122,7 @@ class Model {
// 处理历史数据和动态更新的数据 // 处理历史数据和动态更新的数据
handleMessage(response) { handleMessage(response) {
// if (response.sub != "history" && response.sub != "dynamic") return; // if (response.sub != "history" && response.sub != "dynamic") return;
let { data = null, sub = null, type = null } = response; let { data = null, sub = null, type = null } = response;
@ -156,7 +159,6 @@ class Model {
this.lastTime = list[list.length - 1].time; this.lastTime = list[list.length - 1].time;
} else if (type == "dynamic") { } else if (type == "dynamic") {
// 最新的数据值 // 最新的数据值
// console.log('<<<<<<<<<New'); // console.log('<<<<<<<<<New');
// 检测是否已经加载历史数据 // 检测是否已经加载历史数据

3
src/api/custom/Socket.js

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

2
src/api/server/Socket.js

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

7
src/components/KLine.vue

@ -363,21 +363,26 @@ export default {
// symbol getSymbolgetBar // symbol getSymbolgetBar
this.model.setSymbol(newVal); this.model.setSymbol(newVal);
} }
} },
}, },
created() { created() {
bus.$on('sendMsg', msg => { bus.$on('sendMsg', msg => {
// console.info(msg)
// this.model = new Model(msg, this);
this.model.conglian(msg)
this.model.subscribe([ this.model.subscribe([
{ {
cmd: "sub", cmd: "sub",
msg: `Kline_${this.symbol}_${this.interval}min` msg: `Kline_${this.symbol}_${this.interval}min`
} }
]); ]);
}); });
}, },
mounted() { mounted() {
console.info(this.socket)
// ws // ws
this.model = new Model(this.socket, this); 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 = new Socket(`${this.Globals.Server.Path.WS}`);
this.ws.on("open", () => { this.ws.on("open", () => {
if(this.isLianjie){ if(this.isLianjie){
bus.$emit('sendMsg'); bus.$emit('sendMsg',this.ws.socket);
this.isLianjie=false this.isLianjie=false
} }
// //
@ -474,13 +474,15 @@ export default {
}); });
this.ws.on("close", () => { this.ws.on("close", () => {
this.$message({ // this.$message({
type: "error", // type: "error",
message: this.$t("nav.b8"), // message: this.$t("nav.b8"),
duration: 2000, // duration: 2000,
}); // });
this.isLianjie=true this.isLianjie=true
this.initWs() this.initWs()
// if (this.symbol) this.getCurrencyExCny();
// this.indexList()
}); });
} }

2
src/views/exchange/make-deal.vue

@ -417,7 +417,7 @@ export default {
methods: { methods: {
getCoinInfo(){ getCoinInfo(){
console.log(this.symbol.indexOf('usdt')!=-1) // console.log(this.symbol.indexOf('usdt')!=-1)
if(this.symbol.indexOf('usdt')!=-1){ if(this.symbol.indexOf('usdt')!=-1){
var market=this.symbol.substring(0,this.symbol.length-4); var market=this.symbol.substring(0,this.symbol.length-4);
}else{ }else{

2
src/views/exchange/symbols.vue

@ -219,7 +219,7 @@ export default {
this.cacheMarketList = data; this.cacheMarketList = data;
}).catch(err => {}); }).catch(err => {});
console.log(this.isLogin) // console.log(this.isLogin)
// //
if (this.isLogin) { if (this.isLogin) {
this.getCollect() this.getCollect()

Loading…
Cancel
Save