|
|
@ -223,6 +223,259 @@ |
|
|
</div> |
|
|
</div> |
|
|
</template> |
|
|
</template> |
|
|
<script> |
|
|
<script> |
|
|
|
|
|
// import kline from "../option/kline"; |
|
|
|
|
|
// import handicap from "./handicap.vue"; |
|
|
|
|
|
// import account from "./account.vue"; |
|
|
|
|
|
// import exchangeStore from "./exchange-store.vue"; |
|
|
|
|
|
// import pageBottom from "./page-bottom.vue"; |
|
|
|
|
|
// import Contract from "../../api/contract"; |
|
|
|
|
|
// import Socket from "@/api/server/Socket.js"; |
|
|
|
|
|
// import Home from "@/api/home"; |
|
|
|
|
|
// import bus from "@/components/bus.js"; |
|
|
|
|
|
// export default { |
|
|
|
|
|
// components: { |
|
|
|
|
|
// kline, |
|
|
|
|
|
// handicap, |
|
|
|
|
|
// account, |
|
|
|
|
|
// exchangeStore, |
|
|
|
|
|
// pageBottom |
|
|
|
|
|
// }, |
|
|
|
|
|
// data() { |
|
|
|
|
|
// return { |
|
|
|
|
|
// contractList: [], |
|
|
|
|
|
// activeSymbol: "", |
|
|
|
|
|
// holdPositionAll: false, |
|
|
|
|
|
// holdPositionList: [], |
|
|
|
|
|
// newPriceObj: {}, |
|
|
|
|
|
// pcBannerList:[], |
|
|
|
|
|
// accountInfo: {}, |
|
|
|
|
|
// defaultPrice: "", |
|
|
|
|
|
// wsUrl: this.Globals.Server.Path.WS1, |
|
|
|
|
|
// ws: new Socket(this.Globals.Server.Path.WS1), |
|
|
|
|
|
// _time: null, |
|
|
|
|
|
// contractOpen: false, |
|
|
|
|
|
// contractAgreement: {}, |
|
|
|
|
|
// symbolDetail:{}, |
|
|
|
|
|
// currentIcon: '', |
|
|
|
|
|
// filterCoin: "", |
|
|
|
|
|
// contractListFilter: [], |
|
|
|
|
|
// price1:0, |
|
|
|
|
|
// intervalId:'' |
|
|
|
|
|
// }; |
|
|
|
|
|
// }, |
|
|
|
|
|
// computed: { |
|
|
|
|
|
// activeContract(val) { |
|
|
|
|
|
// let contractList=this.contractList |
|
|
|
|
|
// .map(item => item.marketInfoList) |
|
|
|
|
|
// .flat() |
|
|
|
|
|
// .find(item => item.symbol == this.activeSymbol) || {} |
|
|
|
|
|
// if(val.price){ |
|
|
|
|
|
// delete contractList.price |
|
|
|
|
|
// } |
|
|
|
|
|
// return contractList; |
|
|
|
|
|
// }, |
|
|
|
|
|
// isLogin() { |
|
|
|
|
|
// return Boolean(localStorage.token); |
|
|
|
|
|
// }, |
|
|
|
|
|
// // contractListFilter(){ |
|
|
|
|
|
// // return this.contractList.map((item1, index1)=>{ |
|
|
|
|
|
// // item1.marketInfoList.filter(item2=>{ |
|
|
|
|
|
// // return item2.symbol.indexOf(this.filterCoin)!=-1 |
|
|
|
|
|
// // }) |
|
|
|
|
|
// // return item1; |
|
|
|
|
|
// // }) |
|
|
|
|
|
// // } |
|
|
|
|
|
// }, |
|
|
|
|
|
// watch: { |
|
|
|
|
|
// activeSymbol() { |
|
|
|
|
|
// this.holdPosition(); |
|
|
|
|
|
// }, |
|
|
|
|
|
// // filterCoin: { |
|
|
|
|
|
// // handler(n,o){ |
|
|
|
|
|
// // if(!n){ |
|
|
|
|
|
// // this.contractListFilter = this.contractList; |
|
|
|
|
|
// // }else{ |
|
|
|
|
|
// // this.contractListFilter = this.contractList.map((item1, index1)=>{ |
|
|
|
|
|
// // let arr = item1; |
|
|
|
|
|
// // arr.marketInfoList = item1.marketInfoList.filter(item2=>{ |
|
|
|
|
|
// // return item2.symbol.indexOf(n.toUpperCase())!=-1 |
|
|
|
|
|
// // }) |
|
|
|
|
|
// // return arr; |
|
|
|
|
|
// // }) |
|
|
|
|
|
// // } |
|
|
|
|
|
// // }, |
|
|
|
|
|
// // immediate: true |
|
|
|
|
|
// // } |
|
|
|
|
|
// }, |
|
|
|
|
|
// destroyed() { |
|
|
|
|
|
// clearInterval(this._time); |
|
|
|
|
|
// }, |
|
|
|
|
|
// created() { |
|
|
|
|
|
// // this.openStatus(); |
|
|
|
|
|
// this.getMarketList(); |
|
|
|
|
|
// this.holdPosition(); |
|
|
|
|
|
// this.indexList(); |
|
|
|
|
|
// this._time = setInterval(() => { |
|
|
|
|
|
// if (this.contractOpen) { |
|
|
|
|
|
// this.holdPosition(); |
|
|
|
|
|
// } |
|
|
|
|
|
// }, 3000); |
|
|
|
|
|
// this.ws.on("open", () => { |
|
|
|
|
|
// this.swapMarketList(); |
|
|
|
|
|
// }); |
|
|
|
|
|
// // console.info(this.$refs) |
|
|
|
|
|
// bus.$on('collapse', msg => { |
|
|
|
|
|
// this.activeContract.price =this.activeContract.symbol=='BTC'? (msg.close).toFixed(1):(msg.close).toFixed(3); |
|
|
|
|
|
// this.holdPositionList.map(item=>{ |
|
|
|
|
|
// if(item.symbol==this.activeContract.symbol) item.realtimePrice=this.activeContract.price |
|
|
|
|
|
// }) |
|
|
|
|
|
// }); |
|
|
|
|
|
// this.startWatchingPrice(); |
|
|
|
|
|
// }, |
|
|
|
|
|
// //三秒更新一次数据 |
|
|
|
|
|
// mounted: function () { |
|
|
|
|
|
// setInterval(() => { |
|
|
|
|
|
// this.holdPosition(); |
|
|
|
|
|
// }, 2000) |
|
|
|
|
|
// }, |
|
|
|
|
|
// methods: { |
|
|
|
|
|
// startWatchingPrice(){ |
|
|
|
|
|
// this.intervalId = setInterval(() => { |
|
|
|
|
|
// let newPrice = localStorage.getItem('price'); |
|
|
|
|
|
// this.price1 = newPrice; |
|
|
|
|
|
// }, 10); // 每秒检查一次 |
|
|
|
|
|
// }, |
|
|
|
|
|
// ispopover1(item){ |
|
|
|
|
|
// this.activeSymbol=item; |
|
|
|
|
|
// // this.$refs.popover.showPopper = false; |
|
|
|
|
|
// this.getMarketList(); |
|
|
|
|
|
// }, |
|
|
|
|
|
// swapMarketList() { |
|
|
|
|
|
// let msg = "swapMarketList"; |
|
|
|
|
|
// this.ws.send({ |
|
|
|
|
|
// cmd: "sub", |
|
|
|
|
|
// msg: msg |
|
|
|
|
|
// }); |
|
|
|
|
|
// this.ws.on("message", res => { |
|
|
|
|
|
// let { data, sub,cmd } = res; |
|
|
|
|
|
|
|
|
|
|
|
// if (sub == msg) { |
|
|
|
|
|
// if( data.symbol=='BTC' )(data.price).toFixed(1) |
|
|
|
|
|
// this.contractList = data; |
|
|
|
|
|
// if(this.filterCoin==''){ |
|
|
|
|
|
// this.contractListFilter = data; |
|
|
|
|
|
// } |
|
|
|
|
|
// }else if (cmd == "ping") { |
|
|
|
|
|
// this.ws.send({ |
|
|
|
|
|
// cmd: "pong" |
|
|
|
|
|
// }); |
|
|
|
|
|
// } |
|
|
|
|
|
// }); |
|
|
|
|
|
// this.ws.on('close',()=>{ |
|
|
|
|
|
// this.ws= new Socket(this.Globals.Server.Path.WS1), |
|
|
|
|
|
// console.log('链接关闭'); |
|
|
|
|
|
// this.wsOpen(); |
|
|
|
|
|
// }) |
|
|
|
|
|
// }, |
|
|
|
|
|
// wsOpen(){ |
|
|
|
|
|
// this.ws.on("open", () => { |
|
|
|
|
|
// this.swapMarketList(); |
|
|
|
|
|
// this.$refs.handicap.linkSocket() |
|
|
|
|
|
// }); |
|
|
|
|
|
// }, |
|
|
|
|
|
// // 获取合约市场 |
|
|
|
|
|
// getMarketList() { |
|
|
|
|
|
// this.currentIcon = ""; |
|
|
|
|
|
// Contract.getMarketList().then(res => { |
|
|
|
|
|
// if(this.activeSymbol==''){ |
|
|
|
|
|
// // 页面初始获取 |
|
|
|
|
|
// this.contractList = res; |
|
|
|
|
|
// if(this.filterCoin==''){ |
|
|
|
|
|
// this.contractListFilter = res; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// // 默认值 |
|
|
|
|
|
// let firstParent = res[0]; |
|
|
|
|
|
// if (firstParent) { |
|
|
|
|
|
// let first = firstParent.marketInfoList[0]; |
|
|
|
|
|
// if (first) this.activeSymbol = first.symbol; |
|
|
|
|
|
// this.currentIcon = res[0].marketInfoList[0].icon; |
|
|
|
|
|
// } |
|
|
|
|
|
// }else{ |
|
|
|
|
|
// // 币种切换获取icon |
|
|
|
|
|
// for(let item of res[0].marketInfoList){ |
|
|
|
|
|
// if(this.activeSymbol==item.symbol){ |
|
|
|
|
|
// this.currentIcon = item.icon; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// }); |
|
|
|
|
|
// }, |
|
|
|
|
|
// // 获取持仓 |
|
|
|
|
|
// holdPosition() { |
|
|
|
|
|
// if (!this.isLogin) return; |
|
|
|
|
|
// let data = { |
|
|
|
|
|
// symbol: (this.holdPositionAll && this.activeSymbol) || "" |
|
|
|
|
|
// }; |
|
|
|
|
|
// Contract.holdPosition(data, { loading: false }).then(res => { |
|
|
|
|
|
// // console.info(res) |
|
|
|
|
|
// res.map(item=>{ |
|
|
|
|
|
// if(item.symbol==this.activeContract.symbol) item.realtimePrice=this.activeContract.price |
|
|
|
|
|
// }) |
|
|
|
|
|
// this.holdPositionList = res; |
|
|
|
|
|
// }); |
|
|
|
|
|
// }, |
|
|
|
|
|
// // 获取永续合约开通状态 |
|
|
|
|
|
// openStatus() { |
|
|
|
|
|
// if(!this.isLogin) return; |
|
|
|
|
|
// Contract.openStatus().then(res => { |
|
|
|
|
|
// this.contractOpen = res.open; |
|
|
|
|
|
// if (!this.contractOpen) { |
|
|
|
|
|
// this.contractAgreement = res.contractAgreement; |
|
|
|
|
|
// $("#openContract").modal("show"); |
|
|
|
|
|
// } |
|
|
|
|
|
// }); |
|
|
|
|
|
// }, |
|
|
|
|
|
// // 开通永续合约 |
|
|
|
|
|
// opening() { |
|
|
|
|
|
// Contract.opening().then(res => { |
|
|
|
|
|
// $("#openContract").modal("hide"); |
|
|
|
|
|
// this.contractOpen = true; |
|
|
|
|
|
// this.$message.success(this.$t('contract.j9')); |
|
|
|
|
|
// }); |
|
|
|
|
|
// }, |
|
|
|
|
|
// indexList() { |
|
|
|
|
|
// Home.indexList().then((res) => { |
|
|
|
|
|
// this.pcBannerList = res.pcBannerList |
|
|
|
|
|
// setTimeout(() => { |
|
|
|
|
|
// this.skroll(); |
|
|
|
|
|
// }, 100); |
|
|
|
|
|
// }).catch((res) => {}); |
|
|
|
|
|
// }, |
|
|
|
|
|
// //获取某一个持仓订单的数据 |
|
|
|
|
|
// setactiveItem(index=0){ |
|
|
|
|
|
// this.accountInfo=this.holdPositionList[index] |
|
|
|
|
|
// }, |
|
|
|
|
|
// enterFilter(){ |
|
|
|
|
|
|
|
|
|
|
|
// }, |
|
|
|
|
|
// // 搜索关键字 |
|
|
|
|
|
// isShow(symbol) { |
|
|
|
|
|
// const reg = new RegExp(this.filterCoin, "gi"); |
|
|
|
|
|
// if (!this.filterCoin) return true; |
|
|
|
|
|
// else { |
|
|
|
|
|
// // let name = symbol.coinName || symbol.pair; |
|
|
|
|
|
// // return name.search(reg) >= 0; |
|
|
|
|
|
// let name = symbol.pair_name || symbol.symbol; |
|
|
|
|
|
// return name.search(reg) >= 0; |
|
|
|
|
|
// } |
|
|
|
|
|
// // return !this.keyword || symbol.coinName.concat(symbol.pair).search(reg) >= 0; |
|
|
|
|
|
// }, |
|
|
|
|
|
// } |
|
|
|
|
|
// }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import kline from "../option/kline"; |
|
|
import kline from "../option/kline"; |
|
|
import handicap from "./handicap.vue"; |
|
|
import handicap from "./handicap.vue"; |
|
|
import account from "./account.vue"; |
|
|
import account from "./account.vue"; |
|
|
@ -232,6 +485,7 @@ import Contract from "../../api/contract"; |
|
|
import Socket from "@/api/server/Socket.js"; |
|
|
import Socket from "@/api/server/Socket.js"; |
|
|
import Home from "@/api/home"; |
|
|
import Home from "@/api/home"; |
|
|
import bus from "@/components/bus.js"; |
|
|
import bus from "@/components/bus.js"; |
|
|
|
|
|
|
|
|
export default { |
|
|
export default { |
|
|
components: { |
|
|
components: { |
|
|
kline, |
|
|
kline, |
|
|
@ -250,17 +504,32 @@ export default { |
|
|
pcBannerList:[], |
|
|
pcBannerList:[], |
|
|
accountInfo: {}, |
|
|
accountInfo: {}, |
|
|
defaultPrice: "", |
|
|
defaultPrice: "", |
|
|
|
|
|
|
|
|
|
|
|
// 保证全局唯一 Socket 实例 |
|
|
wsUrl: this.Globals.Server.Path.WS1, |
|
|
wsUrl: this.Globals.Server.Path.WS1, |
|
|
ws: new Socket(this.Globals.Server.Path.WS1), |
|
|
ws: null, |
|
|
|
|
|
|
|
|
_time: null, |
|
|
_time: null, |
|
|
|
|
|
holdTimer: null, // 新增:保存挂载时的持仓定时器 |
|
|
contractOpen: false, |
|
|
contractOpen: false, |
|
|
contractAgreement: {}, |
|
|
contractAgreement: {}, |
|
|
symbolDetail:{}, |
|
|
symbolDetail:{}, |
|
|
currentIcon: '', |
|
|
currentIcon: '', |
|
|
filterCoin: "", |
|
|
filterCoin: "", |
|
|
contractListFilter: [], |
|
|
contractListFilter: [], |
|
|
|
|
|
Liste:[], |
|
|
price1:0, |
|
|
price1:0, |
|
|
intervalId:'' |
|
|
intervalId:'', |
|
|
|
|
|
|
|
|
|
|
|
// ✅ 防内存泄漏:保存事件函数引用 |
|
|
|
|
|
swapMarketHandler: null, |
|
|
|
|
|
wsOpenHandler: null, |
|
|
|
|
|
collapseHandler: null, |
|
|
|
|
|
|
|
|
|
|
|
// 🔥 看门狗机制:监控左侧市场列表的数据流 |
|
|
|
|
|
lastMessageTime: 0, |
|
|
|
|
|
watchdogTimer: null, |
|
|
|
|
|
watchdogTimeout: 15000 // 15秒没收到数据判定为后端假死 |
|
|
}; |
|
|
}; |
|
|
}, |
|
|
}, |
|
|
computed: { |
|
|
computed: { |
|
|
@ -277,141 +546,203 @@ export default { |
|
|
isLogin() { |
|
|
isLogin() { |
|
|
return Boolean(localStorage.token); |
|
|
return Boolean(localStorage.token); |
|
|
}, |
|
|
}, |
|
|
// contractListFilter(){ |
|
|
set_price() { |
|
|
// return this.contractList.map((item1, index1)=>{ |
|
|
return this.$store.getters.set_price; |
|
|
// item1.marketInfoList.filter(item2=>{ |
|
|
} |
|
|
// return item2.symbol.indexOf(this.filterCoin)!=-1 |
|
|
|
|
|
// }) |
|
|
|
|
|
// return item1; |
|
|
|
|
|
// }) |
|
|
|
|
|
// } |
|
|
|
|
|
}, |
|
|
}, |
|
|
watch: { |
|
|
watch: { |
|
|
activeSymbol() { |
|
|
activeSymbol() { |
|
|
this.holdPosition(); |
|
|
this.holdPosition(); |
|
|
}, |
|
|
}, |
|
|
// filterCoin: { |
|
|
|
|
|
// handler(n,o){ |
|
|
|
|
|
// if(!n){ |
|
|
|
|
|
// this.contractListFilter = this.contractList; |
|
|
|
|
|
// }else{ |
|
|
|
|
|
// this.contractListFilter = this.contractList.map((item1, index1)=>{ |
|
|
|
|
|
// let arr = item1; |
|
|
|
|
|
// arr.marketInfoList = item1.marketInfoList.filter(item2=>{ |
|
|
|
|
|
// return item2.symbol.indexOf(n.toUpperCase())!=-1 |
|
|
|
|
|
// }) |
|
|
|
|
|
// return arr; |
|
|
|
|
|
// }) |
|
|
|
|
|
// } |
|
|
|
|
|
// }, |
|
|
|
|
|
// immediate: true |
|
|
|
|
|
// } |
|
|
|
|
|
}, |
|
|
|
|
|
destroyed() { |
|
|
|
|
|
clearInterval(this._time); |
|
|
|
|
|
}, |
|
|
}, |
|
|
created() { |
|
|
created() { |
|
|
// this.openStatus(); |
|
|
// 实例化底层的 Socket,让子组件共享 |
|
|
|
|
|
this.ws = new Socket(this.wsUrl); |
|
|
|
|
|
|
|
|
this.getMarketList(); |
|
|
this.getMarketList(); |
|
|
this.holdPosition(); |
|
|
this.holdPosition(); |
|
|
this.indexList(); |
|
|
this.indexList(); |
|
|
|
|
|
|
|
|
this._time = setInterval(() => { |
|
|
this._time = setInterval(() => { |
|
|
if (this.contractOpen) { |
|
|
if (this.contractOpen) { |
|
|
this.holdPosition(); |
|
|
this.holdPosition(); |
|
|
} |
|
|
} |
|
|
}, 3000); |
|
|
}, 3000); |
|
|
this.ws.on("open", () => { |
|
|
|
|
|
this.swapMarketList(); |
|
|
// 绑定全局价格变动事件 |
|
|
}); |
|
|
this.collapseHandler = msg => { |
|
|
// console.info(this.$refs) |
|
|
this.activeContract.price = this.activeContract.symbol=='BTC'? (msg.close).toFixed(1):(msg.close).toFixed(3); |
|
|
bus.$on('collapse', msg => { |
|
|
|
|
|
this.activeContract.price =this.activeContract.symbol=='BTC'? (msg.close).toFixed(1):(msg.close).toFixed(3); |
|
|
|
|
|
this.holdPositionList.map(item=>{ |
|
|
this.holdPositionList.map(item=>{ |
|
|
if(item.symbol==this.activeContract.symbol) item.realtimePrice=this.activeContract.price |
|
|
if(item.symbol==this.activeContract.symbol) item.realtimePrice=this.activeContract.price |
|
|
}) |
|
|
}) |
|
|
}); |
|
|
}; |
|
|
|
|
|
bus.$on('collapse', this.collapseHandler); |
|
|
|
|
|
|
|
|
|
|
|
// 🔥 定义 WebSocket 的 Open 回调,让底层重连时自动恢复市场订阅 |
|
|
|
|
|
this.wsOpenHandler = () => { |
|
|
|
|
|
console.log("PC主页面 WebSocket 连上/重连成功,请求市场列表..."); |
|
|
|
|
|
this.swapMarketList(); |
|
|
|
|
|
}; |
|
|
|
|
|
this.ws.on("open", this.wsOpenHandler); |
|
|
|
|
|
|
|
|
this.startWatchingPrice(); |
|
|
this.startWatchingPrice(); |
|
|
|
|
|
this.startWatchdog(); // 启动看门狗 |
|
|
}, |
|
|
}, |
|
|
//三秒更新一次数据 |
|
|
|
|
|
mounted: function () { |
|
|
mounted() { |
|
|
setInterval(() => { |
|
|
// ✅ 修复:必须把这个定时器存起来,否则组件销毁时内存会泄漏 |
|
|
|
|
|
this.holdTimer = setInterval(() => { |
|
|
this.holdPosition(); |
|
|
this.holdPosition(); |
|
|
}, 2000) |
|
|
}, 2000); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// ✅ 核心重构:在组件卸载时,杀掉所有后台偷跑的定时器和事件监听! |
|
|
|
|
|
beforeDestroy() { |
|
|
|
|
|
clearInterval(this._time); |
|
|
|
|
|
clearInterval(this.intervalId); |
|
|
|
|
|
if (this.holdTimer) clearInterval(this.holdTimer); |
|
|
|
|
|
|
|
|
|
|
|
this.stopWatchdog(); |
|
|
|
|
|
|
|
|
|
|
|
if (this.collapseHandler) { |
|
|
|
|
|
bus.$off('collapse', this.collapseHandler); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.ws) { |
|
|
|
|
|
if (this.wsOpenHandler) this.ws.off("open", this.wsOpenHandler); |
|
|
|
|
|
if (this.swapMarketHandler) this.ws.off("message", this.swapMarketHandler); |
|
|
|
|
|
|
|
|
|
|
|
this.ws.send({ cmd: "unsub", msg: "swapMarketList" }); |
|
|
|
|
|
this.ws.destroy(); |
|
|
|
|
|
this.ws = null; |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
methods: { |
|
|
methods: { |
|
|
startWatchingPrice(){ |
|
|
startWatchingPrice(){ |
|
|
|
|
|
// ⚠️ 性能优化:把 10 毫秒改成了 100 毫秒。肉眼看不出延迟,但极大释放了电脑 CPU 性能! |
|
|
this.intervalId = setInterval(() => { |
|
|
this.intervalId = setInterval(() => { |
|
|
let newPrice = localStorage.getItem('price'); |
|
|
let newPrice = localStorage.getItem('price'); |
|
|
this.price1 = newPrice; |
|
|
this.price1 = newPrice; |
|
|
}, 10); // 每秒检查一次 |
|
|
}, 100); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
ispopover1(item){ |
|
|
ispopover1(item){ |
|
|
this.activeSymbol=item; |
|
|
this.activeSymbol=item; |
|
|
// this.$refs.popover.showPopper = false; |
|
|
|
|
|
this.getMarketList(); |
|
|
this.getMarketList(); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 🔥 暴力强杀重连看门狗 |
|
|
|
|
|
startWatchdog() { |
|
|
|
|
|
this.stopWatchdog(); |
|
|
|
|
|
this.lastMessageTime = Date.now(); |
|
|
|
|
|
|
|
|
|
|
|
this.watchdogTimer = setInterval(() => { |
|
|
|
|
|
if (Date.now() - this.lastMessageTime > this.watchdogTimeout) { |
|
|
|
|
|
console.error("[PC市场列表看门狗] 超过15秒未收到推送数据,判定后端假死!正在强行掐断并新建 WS..."); |
|
|
|
|
|
|
|
|
|
|
|
// 保底拉一下 HTTP 数据 |
|
|
|
|
|
this.getMarketList(); |
|
|
|
|
|
|
|
|
|
|
|
// 强行掐断并重启 |
|
|
|
|
|
if (this.ws) { |
|
|
|
|
|
if (this.ws.socket) this.ws.socket.close(); |
|
|
|
|
|
this.ws.isReconnecting = false; |
|
|
|
|
|
this.ws.manualClose = false; |
|
|
|
|
|
this.ws.reconnect(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.lastMessageTime = Date.now(); // 喂狗,防止疯狂重启 |
|
|
|
|
|
} |
|
|
|
|
|
}, 5000); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
stopWatchdog() { |
|
|
|
|
|
if (this.watchdogTimer) { |
|
|
|
|
|
clearInterval(this.watchdogTimer); |
|
|
|
|
|
this.watchdogTimer = null; |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
swapMarketList() { |
|
|
swapMarketList() { |
|
|
let msg = "swapMarketList"; |
|
|
let msg = "swapMarketList"; |
|
|
this.ws.send({ |
|
|
|
|
|
cmd: "sub", |
|
|
// 如果已连接,则发送订阅 |
|
|
msg: msg |
|
|
if (this.ws && this.ws.checkOpen()) { |
|
|
}); |
|
|
this.ws.send({ cmd: "sub", msg: msg }); |
|
|
this.ws.on("message", res => { |
|
|
} |
|
|
let { data, sub,cmd } = res; |
|
|
|
|
|
|
|
|
// 清理旧监听器,防止多次触发重复渲染 |
|
|
|
|
|
if (this.swapMarketHandler) { |
|
|
|
|
|
this.ws.off("message", this.swapMarketHandler); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 声明并绑定最新的接收方法 |
|
|
|
|
|
this.swapMarketHandler = res => { |
|
|
|
|
|
let { data, sub, cmd } = res; |
|
|
|
|
|
|
|
|
|
|
|
// 只要收到消息就“喂狗”,刷新活跃时间 |
|
|
|
|
|
if (sub == msg || cmd == "ping") { |
|
|
|
|
|
this.lastMessageTime = Date.now(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (sub == msg) { |
|
|
if (sub == msg) { |
|
|
if( data.symbol=='BTC' )(data.price).toFixed(1) |
|
|
if( data.symbol=='BTC' )(data.price).toFixed(1) |
|
|
this.contractList = data; |
|
|
this.contractList = data; |
|
|
if(this.filterCoin==''){ |
|
|
if(this.filterCoin==''){ |
|
|
this.contractListFilter = data; |
|
|
this.contractListFilter = data; |
|
|
|
|
|
this.Listes(); |
|
|
} |
|
|
} |
|
|
}else if (cmd == "ping") { |
|
|
} else if (cmd == "ping") { |
|
|
this.ws.send({ |
|
|
this.ws.send({ cmd: "pong" }); |
|
|
cmd: "pong" |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}; |
|
|
this.ws.on('close',()=>{ |
|
|
|
|
|
this.ws= new Socket(this.Globals.Server.Path.WS1), |
|
|
this.ws.on("message", this.swapMarketHandler); |
|
|
console.log('链接关闭'); |
|
|
|
|
|
this.wsOpen(); |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
wsOpen(){ |
|
|
|
|
|
this.ws.on("open", () => { |
|
|
|
|
|
this.swapMarketList(); |
|
|
|
|
|
this.$refs.handicap.linkSocket() |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 获取合约市场 |
|
|
// 获取合约市场 |
|
|
getMarketList() { |
|
|
getMarketList() { |
|
|
this.currentIcon = ""; |
|
|
this.currentIcon = ""; |
|
|
Contract.getMarketList().then(res => { |
|
|
Contract.getMarketList().then(res => { |
|
|
if(this.activeSymbol==''){ |
|
|
if(this.activeSymbol==''){ |
|
|
// 页面初始获取 |
|
|
|
|
|
this.contractList = res; |
|
|
this.contractList = res; |
|
|
if(this.filterCoin==''){ |
|
|
if(this.filterCoin==''){ |
|
|
this.contractListFilter = res; |
|
|
this.contractListFilter = res; |
|
|
|
|
|
this.Listes(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 默认值 |
|
|
|
|
|
let firstParent = res[0]; |
|
|
let firstParent = res[0]; |
|
|
if (firstParent) { |
|
|
if (firstParent) { |
|
|
let first = firstParent.marketInfoList[0]; |
|
|
let first = firstParent.marketInfoList[0]; |
|
|
if (first) this.activeSymbol = first.symbol; |
|
|
if (first) this.activeSymbol = first.symbol; |
|
|
this.currentIcon = res[0].marketInfoList[0].icon; |
|
|
this.currentIcon = res[0].marketInfoList[0].icon; |
|
|
} |
|
|
} |
|
|
}else{ |
|
|
} else { |
|
|
// 币种切换获取icon |
|
|
if (res && res[0]) { |
|
|
for(let item of res[0].marketInfoList){ |
|
|
for(let item of res[0].marketInfoList){ |
|
|
if(this.activeSymbol==item.symbol){ |
|
|
if(this.activeSymbol==item.symbol){ |
|
|
this.currentIcon = item.icon; |
|
|
this.currentIcon = item.icon; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
Listes(){ |
|
|
|
|
|
this.Liste = []; |
|
|
|
|
|
if (!this.contractListFilter || !this.contractListFilter[0] || !this.contractListFilter[0].marketInfoList) return; |
|
|
|
|
|
|
|
|
|
|
|
this.contractListFilter[0].marketInfoList.map(item => { |
|
|
|
|
|
this.Liste.push({ |
|
|
|
|
|
pair_name: item.pair_name, |
|
|
|
|
|
symbol: item.symbol, |
|
|
|
|
|
icon: item.icon |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 获取持仓 |
|
|
// 获取持仓 |
|
|
holdPosition() { |
|
|
holdPosition() { |
|
|
if (!this.isLogin) return; |
|
|
if (!this.isLogin) return; |
|
|
@ -419,14 +750,13 @@ export default { |
|
|
symbol: (this.holdPositionAll && this.activeSymbol) || "" |
|
|
symbol: (this.holdPositionAll && this.activeSymbol) || "" |
|
|
}; |
|
|
}; |
|
|
Contract.holdPosition(data, { loading: false }).then(res => { |
|
|
Contract.holdPosition(data, { loading: false }).then(res => { |
|
|
// console.info(res) |
|
|
|
|
|
res.map(item=>{ |
|
|
res.map(item=>{ |
|
|
if(item.symbol==this.activeContract.symbol) item.realtimePrice=this.activeContract.price |
|
|
if(item.symbol==this.activeContract.symbol) item.realtimePrice=this.activeContract.price |
|
|
}) |
|
|
}) |
|
|
this.holdPositionList = res; |
|
|
this.holdPositionList = res; |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
// 获取永续合约开通状态 |
|
|
|
|
|
openStatus() { |
|
|
openStatus() { |
|
|
if(!this.isLogin) return; |
|
|
if(!this.isLogin) return; |
|
|
Contract.openStatus().then(res => { |
|
|
Contract.openStatus().then(res => { |
|
|
@ -437,7 +767,7 @@ export default { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
// 开通永续合约 |
|
|
|
|
|
opening() { |
|
|
opening() { |
|
|
Contract.opening().then(res => { |
|
|
Contract.opening().then(res => { |
|
|
$("#openContract").modal("hide"); |
|
|
$("#openContract").modal("hide"); |
|
|
@ -445,35 +775,32 @@ export default { |
|
|
this.$message.success(this.$t('contract.j9')); |
|
|
this.$message.success(this.$t('contract.j9')); |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
indexList() { |
|
|
indexList() { |
|
|
Home.indexList().then((res) => { |
|
|
Home.indexList().then((res) => { |
|
|
this.pcBannerList = res.pcBannerList |
|
|
this.pcBannerList = res.pcBannerList |
|
|
setTimeout(() => { |
|
|
|
|
|
this.skroll(); |
|
|
|
|
|
}, 100); |
|
|
|
|
|
}).catch((res) => {}); |
|
|
}).catch((res) => {}); |
|
|
}, |
|
|
}, |
|
|
//获取某一个持仓订单的数据 |
|
|
|
|
|
setactiveItem(index=0){ |
|
|
setactiveItem(index=0){ |
|
|
this.accountInfo=this.holdPositionList[index] |
|
|
this.accountInfo = this.holdPositionList[index]; |
|
|
}, |
|
|
}, |
|
|
enterFilter(){ |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
// 搜索关键字 |
|
|
|
|
|
isShow(symbol) { |
|
|
isShow(symbol) { |
|
|
const reg = new RegExp(this.filterCoin, "gi"); |
|
|
const reg = new RegExp(this.filterCoin, "gi"); |
|
|
if (!this.filterCoin) return true; |
|
|
if (!this.filterCoin) return true; |
|
|
else { |
|
|
else { |
|
|
// let name = symbol.coinName || symbol.pair; |
|
|
|
|
|
// return name.search(reg) >= 0; |
|
|
|
|
|
let name = symbol.pair_name || symbol.symbol; |
|
|
let name = symbol.pair_name || symbol.symbol; |
|
|
return name.search(reg) >= 0; |
|
|
return name.search(reg) >= 0; |
|
|
} |
|
|
} |
|
|
// return !this.keyword || symbol.coinName.concat(symbol.pair).search(reg) >= 0; |
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
enterFilter(){ |
|
|
|
|
|
// 此方法原来为空,保持即可 |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
</script> |
|
|
</script> |
|
|
<style lang="scss" scoped> |
|
|
<style lang="scss" scoped> |
|
|
.justify-content-between ::v-deep .dark-app .theme-switch .theme-switch-button .left, .dark-app .theme-switch .theme-switch-button .right{ |
|
|
.justify-content-between ::v-deep .dark-app .theme-switch .theme-switch-button .left, .dark-app .theme-switch .theme-switch-button .right{ |
|
|
|