严智鑫
2024-08-05 00c4dfc5ac687c93e0b7abafc33abb693b38edd6
UI-Project/src/views/StockBasicData/stockBasicDatatwo.vue
@@ -6,7 +6,7 @@
const adda = ref(false)
import { WebSocketHost ,host} from '@/utils/constants'
import request from "@/utils/request"
import { ref, onMounted , onBeforeUnmount} from "vue";
import { ref, onMounted , onBeforeUnmount,onUnmounted} from "vue";
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
// import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
@@ -50,7 +50,9 @@
      // 用户点击了“是”,现在调用删除接口  
      const response = await request.post("/cacheGlass/edgStorageCage/edgReportStatus", {
        glassId: row.GlassId,
        controlsId: 300
        controlsId: 300,
        line: 2002,
        machine: '冷加工',
    })
    if (response.code === 200) {
      ElMessage.success(response.message);
@@ -81,7 +83,9 @@
      // 用户点击了“是”,现在调用删除接口  
      const response = await request.post("/cacheGlass/edgStorageCage/edgReportStatus", {
        glassId: row.GlassId,
        controlsId: 301
        controlsId: 301,
        line: 2002,
        machine: '冷加工',
    })
    if (response.code === 200) {
      ElMessage.success(response.message);
@@ -96,21 +100,21 @@
    console.error('发生错误:', error);  
  }  
};   
let socket = null;
const socketUrl = `ws://${WebSocketHost}:${host}/api/cacheGlass/api/talk/cacheGlass`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  // 更新 tableData 的数据
  tableData.value = data.EdgTasks2[0]
};
// 初始化 WebSocket,并传递消息处理函数
onMounted(() => {
  // fetchFlowCardId();
  // fetchTableData(); // 获取数据
  initializeWebSocket(socketUrl, handleMessage);
  socket = initializeWebSocket(socketUrl, handleMessage);
});
  onUnmounted(() => {
    if (socket) {
    closeWebSocket(socket);
    }
    });
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();