|
|
|
@ -36,6 +36,7 @@ import Market from '@/api/market.js'; |
|
|
|
import Exchange from "@/api/exchange"; |
|
|
|
import Order from "@/api/order" |
|
|
|
import Home from "@/api/home"; |
|
|
|
import bus from "@/components/bus.js"; |
|
|
|
export default { |
|
|
|
|
|
|
|
components: { |
|
|
|
@ -48,14 +49,14 @@ export default { |
|
|
|
|
|
|
|
beforeCreate() { |
|
|
|
|
|
|
|
this.ws = new Socket(`${this.Globals.Server.Path.WS}`); |
|
|
|
// this.ws = new Socket(`${this.Globals.Server.Path.WS}`); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
data() { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
isLianjie:false, |
|
|
|
// `btcusdt` 不含`/`的小写 |
|
|
|
symbol: this.$route.params.symbol || null, |
|
|
|
marketId: null, |
|
|
|
@ -407,76 +408,87 @@ export default { |
|
|
|
}, 100); |
|
|
|
}).catch((res) => {}); |
|
|
|
}, |
|
|
|
initWs(){ |
|
|
|
this.ws = new Socket(`${this.Globals.Server.Path.WS}`); |
|
|
|
this.ws.on("open", () => { |
|
|
|
if(this.isLianjie){ |
|
|
|
bus.$emit('sendMsg'); |
|
|
|
this.isLianjie=false |
|
|
|
} |
|
|
|
// 连接成功后 初始化订阅市场信息 |
|
|
|
this.initMarket(); |
|
|
|
// 如果指定了id 订阅该行情的所有其他信息 |
|
|
|
if (this.symbol) this.addSub(); |
|
|
|
}) |
|
|
|
|
|
|
|
this.ws.on("message", (response) => { |
|
|
|
|
|
|
|
let { |
|
|
|
data, // 返回数据 |
|
|
|
sub, // 订阅标签 |
|
|
|
type, // 返回类型 |
|
|
|
msg, // 提示信息 |
|
|
|
code, // 错误代号 |
|
|
|
} = response; |
|
|
|
|
|
|
|
// 答复心跳 保持连接 |
|
|
|
if (type == "ping") this.ws.send({ |
|
|
|
type: "pong" |
|
|
|
}); |
|
|
|
|
|
|
|
switch (sub) { |
|
|
|
|
|
|
|
case "exchangeMarketList": |
|
|
|
|
|
|
|
this.marketList = data; |
|
|
|
|
|
|
|
if (!this.symbol) { // 默认symbol 重新请求数据 |
|
|
|
this.symbol = _.nth(data).marketInfoList[0].symbol; |
|
|
|
} else { // 找出该symbol对应的记录并更新页面 |
|
|
|
this.findMarketBySymbol(); |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case `buyList_${this.symbol}`: |
|
|
|
|
|
|
|
this.buyList = data; |
|
|
|
break; |
|
|
|
|
|
|
|
case `sellList_${this.symbol}`: |
|
|
|
|
|
|
|
this.sellList = data; |
|
|
|
break; |
|
|
|
|
|
|
|
case `tradeList_${this.symbol}`: |
|
|
|
if (type == "history") { // 历史记录 |
|
|
|
this.trade = this.trade.concat(data); |
|
|
|
} else if (type == "dynamic") { // 有更新就推送 |
|
|
|
this.trade.unshift(data); |
|
|
|
} |
|
|
|
// 最新交易 更新用于余额和订单记录 |
|
|
|
this.newTrade = _.nth(this.trade); |
|
|
|
if (this.newTrade && this.newTrade.buy_user_id === this.userInfo.user_id || this.newTrade.sell_user_id == this.userInfo.user_id) this.update(); |
|
|
|
break; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.ws.on("close", () => { |
|
|
|
this.$message({ |
|
|
|
type: "error", |
|
|
|
message: this.$t("nav.b8"), |
|
|
|
duration: 2000, |
|
|
|
}); |
|
|
|
this.isLianjie=true |
|
|
|
this.initWs() |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
created() { |
|
|
|
|
|
|
|
this.ws.on("open", () => { |
|
|
|
// 连接成功后 初始化订阅市场信息 |
|
|
|
this.initMarket(); |
|
|
|
// 如果指定了id 订阅该行情的所有其他信息 |
|
|
|
if (this.symbol) this.addSub(); |
|
|
|
}) |
|
|
|
|
|
|
|
this.ws.on("message", (response) => { |
|
|
|
|
|
|
|
let { |
|
|
|
data, // 返回数据 |
|
|
|
sub, // 订阅标签 |
|
|
|
type, // 返回类型 |
|
|
|
msg, // 提示信息 |
|
|
|
code, // 错误代号 |
|
|
|
} = response; |
|
|
|
|
|
|
|
// 答复心跳 保持连接 |
|
|
|
if (type == "ping") this.ws.send({ |
|
|
|
type: "pong" |
|
|
|
}); |
|
|
|
|
|
|
|
switch (sub) { |
|
|
|
|
|
|
|
case "exchangeMarketList": |
|
|
|
|
|
|
|
this.marketList = data; |
|
|
|
|
|
|
|
if (!this.symbol) { // 默认symbol 重新请求数据 |
|
|
|
this.symbol = _.nth(data).marketInfoList[0].symbol; |
|
|
|
} else { // 找出该symbol对应的记录并更新页面 |
|
|
|
this.findMarketBySymbol(); |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case `buyList_${this.symbol}`: |
|
|
|
|
|
|
|
this.buyList = data; |
|
|
|
break; |
|
|
|
|
|
|
|
case `sellList_${this.symbol}`: |
|
|
|
|
|
|
|
this.sellList = data; |
|
|
|
break; |
|
|
|
|
|
|
|
case `tradeList_${this.symbol}`: |
|
|
|
if (type == "history") { // 历史记录 |
|
|
|
this.trade = this.trade.concat(data); |
|
|
|
} else if (type == "dynamic") { // 有更新就推送 |
|
|
|
this.trade.unshift(data); |
|
|
|
} |
|
|
|
// 最新交易 更新用于余额和订单记录 |
|
|
|
this.newTrade = _.nth(this.trade); |
|
|
|
if (this.newTrade && this.newTrade.buy_user_id === this.userInfo.user_id || this.newTrade.sell_user_id == this.userInfo.user_id) this.update(); |
|
|
|
break; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.ws.on("close", () => { |
|
|
|
this.$message({ |
|
|
|
type: "error", |
|
|
|
message: this.$t("nav.b8"), |
|
|
|
duration: 2000, |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.initWs() |
|
|
|
if (this.symbol) this.getCurrencyExCny(); |
|
|
|
this.indexList() |
|
|
|
// this.update(); |
|
|
|
|