jiaxiaoqiang 3 mēneši atpakaļ
vecāks
revīzija
6cf9e9e542

+ 0 - 2
src/views/modules/runTest/components/tit-header.vue

@@ -1,6 +1,4 @@
 <script setup lang="ts">
-import { defineProps } from "vue";
-
 const props = defineProps({
   iconClass: {
     type: String,

+ 28 - 1
src/views/modules/runTest/run-test.vue

@@ -2,7 +2,7 @@
 import { ref } from "vue";
 import titHeader from "./components/tit-header.vue";
 import ConfigDataAndDevice from "./components/configDataAndDevice.vue";
-
+import { useWebSocket } from "@vueuse/core";
 import { useCommonStoreHook } from "@/store";
 import { getTestProjectList } from "@/api/project";
 import { CheckboxValueType } from "element-plus";
@@ -158,6 +158,33 @@ const getSattisticData = () => {
   );
 };
 
+// ===== websocket ====
+const wsClient = useWebSocket(import.meta.env.VITE_WEBSOCKET_URL as string, {
+  autoReconnect: {
+    retries: 300,
+    delay: 3000,
+    onFailed() {
+      console.log("长链接失败");
+    },
+  },
+  heartbeat: {
+    message: "ping",
+    interval: 1000,
+    pongTimeout: 1000,
+  },
+  onMessage: (msg) => {
+    console.log("长链接的消息", msg);
+  },
+});
+
+// onMounted(() => {
+//
+// });
+
+onBeforeUnmount(() => {
+  wsClient.close();
+});
+
 const checkStartEnable = (): boolean => {
   let enable = true;