From 5bf14aed888cd0e258e325c65f14022dad02985b Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期四, 17 七月 2025 15:32:01 +0800
Subject: [PATCH] 更改为通过websocket获取数据

---
 src/components/TableDisplay.vue |   42 ++++--------------------------------------
 1 files changed, 4 insertions(+), 38 deletions(-)

diff --git a/src/components/TableDisplay.vue b/src/components/TableDisplay.vue
index 1a11ada..9e6eb01 100644
--- a/src/components/TableDisplay.vue
+++ b/src/components/TableDisplay.vue
@@ -1,10 +1,6 @@
 <script setup lang="ts">
 import { ref, onMounted, onUnmounted } from 'vue';
-import { sendToPipe } from '../pipe_client';
-
-const props = defineProps<{
-  pipeName: string;
-}>();
+import { createDataReceiver } from '../utils/dataFetcher';
 
 interface ForceData {
   timestamp: string;
@@ -42,44 +38,14 @@
   }
 }
 
-// 鐘舵�佸彉閲忥紝鐢ㄤ簬鎺у埗閿欒鏄剧ず棰戠巼
-const errorCount = ref(0);
-const maxConsecutiveErrors = 5;
-const showingError = ref(false);
 
-// 鎺ユ敹绠¢亾鏁版嵁鐨勫嚱鏁�
-async function receiveData() {
-  try {
-    const response = await sendToPipe(props.pipeName, 'GET_FORCE_DATA');
-    
-    // 閲嶇疆閿欒璁℃暟
-    errorCount.value = 0;
-    showingError.value = false;
-    
-    // 瑙f瀽鏁版嵁
-    try {
-      const forceData = JSON.parse(response);
-      if (Array.isArray(forceData) && forceData.length === 6) {
-        updateTable(forceData);
-      }
-    } catch (parseErr) {
-      console.error('鏁版嵁瑙f瀽閿欒:', parseErr);
-    }
-  } catch (err) {
-    // 澧炲姞閿欒璁℃暟
-    errorCount.value++;
-    
-    // 鍙湪杩炵画閿欒杈惧埌闃堝�间笖灏氭湭鏄剧ず閿欒鏃舵樉绀�
-    if (errorCount.value >= maxConsecutiveErrors && !showingError.value) {
-      console.error('绠¢亾閫氫俊澶辫触:', err);
-      showingError.value = true;
-    }
-  }
-}
 
 let dataInterval: number | null = null;
 
 onMounted(() => {
+  const receiveData = createDataReceiver( (forceData) => {
+    updateTable(forceData);
+  });
   // 姣�500ms鑾峰彇涓�娆℃暟鎹�
   dataInterval = window.setInterval(receiveData, 500);
 });

--
Gitblit v1.9.3