Browse Source

动态更新tcp命令;

zhaowenkang/feature-20251028181547-行情页面
宋杰 4 weeks ago
parent
commit
98a016d957
  1. 66
      pages/home/home.vue

66
pages/home/home.vue

@ -256,6 +256,9 @@ export default {
type: '' type: ''
}, },
// TCP使
currentStockCodes: ['SH.000001', 'SH.000002', 'SH.000003'],
// TCP // TCP
myStocksTcpData: { myStocksTcpData: {
count: 0, count: 0,
@ -341,10 +344,8 @@ export default {
} }
}) })
}) })
// TCP
this.initTcpListeners()
// //
if (this.userStore.userInfo && !this.userStore.userInfo.isVisitor) { if (this.userStore.userInfo && !this.userStore.userInfo.isVisitor) {
console.log('是用户登录,加载自选股数据', this.userStore.userInfo) console.log('是用户登录,加载自选股数据', this.userStore.userInfo)
@ -355,23 +356,26 @@ export default {
}else { }else {
console.log('用户未登录',this.userStore.userInfo) console.log('用户未登录',this.userStore.userInfo)
} }
// TCP
this.initTcpListeners()
// TCP // TCP
// this.$nextTick(() => {
// console.log('TCP...')
// //
// setTimeout(() => {
// // TCPchannel 1
// console.log('TCPchannel 1...')
// this.connectTcp()
this.$nextTick(() => {
console.log('页面渲染完成,开始自动连接TCP服务器...')
//
setTimeout(() => {
// TCPchannel 1
console.log('连接今日市场概览TCP(channel 1)...')
this.connectTcp()
// // TCPchannel 2
// setTimeout(() => {
// console.log('TCPchannel 2...')
// this.connectMyStocksTcp()
// }, 500)
// }, 1000)
// })
// TCPchannel 2
setTimeout(() => {
console.log('连接我的自选TCP(channel 2)...')
this.connectMyStocksTcp()
}, 500)
}, 1000)
})
}, },
// //
@ -576,6 +580,28 @@ export default {
} }
console.log('更新后的自选股数据:', this.myStocks) console.log('更新后的自选股数据:', this.myStocks)
// TCP
this.updateTcpStockCodes()
},
// TCP
updateTcpStockCodes() {
// myStocks3
const stockCodes = this.myStocks.slice(0, 3).map(stock => stock.code).filter(code => code)
console.log('更新TCP消息股票代码:', stockCodes)
// TCP
if (stockCodes.length > 0) {
// 33
while (stockCodes.length < 3) {
stockCodes.push('SH.000001') //
}
// TCP使
this.currentStockCodes = stockCodes
console.log('当前TCP使用的股票代码:', this.currentStockCodes)
}
}, },
// TCP // TCP
@ -1033,7 +1059,7 @@ export default {
// } // }
// {"command": "stock_list"} // {"command": "stock_list"}
// {"command": "batch_real_time", "stock_codes": ["SH.000001"]} // {"command": "batch_real_time", "stock_codes": ["SH.000001"]}
{"command": "batch_real_time", "stock_codes": ["SH.000001","SH.000002","SH.000003"]}
{"command": "batch_real_time", "stock_codes": this.currentStockCodes}
// //
const success = tcpConnection.send(messageData) const success = tcpConnection.send(messageData)
@ -1050,7 +1076,7 @@ export default {
// TCP // TCP
sendMyStocksTcpMessage() { sendMyStocksTcpMessage() {
// - // -
const messageData = {"command": "batch_real_time", "stock_codes": ["SH.000001","SH.000002","SH.000003"]}
const messageData = {"command": "batch_real_time", "stock_codes": this.currentStockCodes}
// channel 2TCP // channel 2TCP
const success = tcpConnection.send(messageData, { channel: '2' }) const success = tcpConnection.send(messageData, { channel: '2' })

Loading…
Cancel
Save