From 376d8b559bf1ca2aa641213181cd763c3438e1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=9D=B0?= Date: Tue, 28 Oct 2025 17:57:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=8A=E6=97=A5=E5=B8=82=E5=9C=BA=E6=A6=82?= =?UTF-8?q?=E8=A7=88=E8=BF=9E=E6=8E=A5tcp=E6=88=90=E5=8A=9F=EF=BC=9B?= =?UTF-8?q?=E5=85=88=E6=96=AD=E5=BC=80=E5=86=8D=E8=BF=9E=E6=8E=A5=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/tcpConnection.js | 21 ++ components/MarketOverview.vue | 50 ++- pages/home/home.vue | 705 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 759 insertions(+), 17 deletions(-) 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 @@