diff --git a/api/tcpConnection.js b/api/tcpConnection.js index 6dcc539..ffe9d88 100644 --- a/api/tcpConnection.js +++ b/api/tcpConnection.js @@ -30,6 +30,26 @@ class TCPConnection { * @param {Function} callback - 连接状态回调函数 */ connect(config = {}, callback = null) { + // 如果已经连接,先断开现有连接 + if (this.isConnected) { + console.log('检测到现有TCP连接,先断开...'); + this.disconnect(config); + // 等待断开完成后再连接 + setTimeout(() => { + this._performConnect(config, callback); + }, 300); + } else { + // 直接连接 + this._performConnect(config, callback); + } + } + + /** + * 执行TCP连接 + * @param {Object} config - 连接配置 + * @param {Function} callback - 连接状态回调函数 + */ + _performConnect(config = {}, callback = null) { const connectionConfig = { channel: config.channel || TCP_CONFIG.channel, ip: config.ip || TCP_CONFIG.ip, @@ -41,6 +61,7 @@ class TCPConnection { connectionConfig.charsetname = config.charsetname || TCP_CONFIG.charsetname; } + console.log('开始建立TCP连接:', connectionConfig); TCPSocket.connect( connectionConfig, result => { diff --git a/components/MarketOverview.vue b/components/MarketOverview.vue index d04fa4a..627abae 100644 --- a/components/MarketOverview.vue +++ b/components/MarketOverview.vue @@ -18,20 +18,13 @@ - - 美元/日元 - 151.13 - +1.62% - - - 美元/韩元 - 1424.900 - -2.92% - - - 美元/英镑 - 0.730 - +2.92% + + {{ stock.stock_name }} + {{ stock.current_price }} + {{ stock.change }} @@ -94,6 +87,35 @@