严智鑫
2024-08-05 00c4dfc5ac687c93e0b7abafc33abb693b38edd6
UI-Project/src/views/GlassStorage/MaterialRackManagement.vue
@@ -330,7 +330,7 @@
<script setup>
import { ref, onMounted, onBeforeUnmount } from "vue"; // 导入 Vue 3 的模块
import { ref, onMounted, onBeforeUnmount,onUnmounted } from "vue"; // 导入 Vue 3 的模块
//import * as echarts from 'echarts';
import { ElMessage, ElMessageBox } from "element-plus";
// import {tableData} from '@/stores/tableData.js';
@@ -393,6 +393,7 @@
  row.enableState = 1 - row.enableState; // Toggle between 0 and 1
  // 此处可以添加保存状态的逻辑,比如调用 API 更新数据
};
let socket = null;
const socketUrl = `ws://${WebSocketHost}:${host}/api/glassStorage/api/talk/storageTask`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
@@ -429,15 +430,14 @@
    // 替换原来的 createTime 字段为格式化后的日期时间字符串
    item.startTime = formattedDateTime;
  });
};
onMounted(() => {
  initializeWebSocket(socketUrl, handleMessage);
  socket = initializeWebSocket(socketUrl, handleMessage);
});
  onUnmounted(() => {
    if (socket) {
    closeWebSocket(socket);
    }
});
onBeforeUnmount(() => {
  console.log("关闭了");