严智鑫
2024-05-29 62c74409a587d9921df1a2248ce23b3b0375fbd1
UI-Project/src/views/UnLoadGlass/Landingindicationtwo.vue
@@ -32,10 +32,12 @@
</template>
<script setup>
import { ref, watchEffect } from 'vue';
import { ref, watchEffect ,onMounted} from 'vue';
import Swal from 'sweetalert2'
import request from "@/utils/request";
import { initializeWebSocket } from '@/utils/WebSocketService';
 import { WebSocketHost } from '@/utils/constants';
const racks = ref([
  { x: 50, y: 100, height: 100, width: 60, fillColor: '#6a6da9', item: { height: 90, width: 10, fillColor: 'yellow', content: 'NG123456' } },
 
@@ -110,7 +112,41 @@
  }
};
fetchFlowCardId()
const socketUrl = `ws://${WebSocketHost}:8085/api/talk/unloadglass3`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  // 更新 tableData 的数据
  data.glassinfo2[0].forEach((itemData, index) => {
  if (index < racks.value.length) {
    const rack = racks.value[index];
    const newItem = {
      content: itemData.item.content,
      fillColor: itemData.item.fillColor,
      width: itemData.item.width === 0 ? "" : 10,
      height: itemData.item.height === 0 ? "" : 90
    };
    if (index === 2 && itemData.item.width > 0) {
      newItem.width = 100;
      newItem.height = 20;
    }
    rack.item = newItem;
    //console.log("显示图2",racks.value); // 打印更新后的 racks 值
  }
});
};
// 初始化 WebSocket,并传递消息处理函数
onMounted(() => {
  fetchFlowCardId(); // 获取数据
  initializeWebSocket(socketUrl, handleMessage);
});
// const showCustomAlert = (content) => {
//   var str="架号   :      111\n" +