wang
2024-06-04 5649c793fd60cbdae34b2b62a87374a81335fd22
UI-Project/src/views/PurchaseReturn/purchaseReturn.vue
@@ -3,10 +3,10 @@
import {reactive} from "vue";
import {useRouter} from "vue-router"
import request from "@/utils/request"
import { ref, onMounted } from 'vue';
// import { ref } from 'vue'
import { ref, onMounted, onBeforeUnmount } from 'vue';
import { WebSocketHost ,host} from '@/utils/constants'
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
const dialogFormVisible = ref(true)
const dialogFormVisiblea = ref(false)
const dialogFormVisibleb = ref(false)
@@ -16,96 +16,137 @@
const adjustedRectsa = ref([]);
const adjustedRectsb = ref([]);
// 进炉中
onMounted(async () => {
  try {
    const response = await request.get('/temperingGlass/temperingGlassInfo/SelectIntoGlass');
    if (response.code === 200) {
      const rawRects = response.data; // 设置矩形数据
      console.log(response.data);
      const { height: newheight,width: newwidth  } = response.data; // 获取尺寸
      height.value = newheight;
      width.value = newwidth;
      adjustedRects.value = rawRects.map(rect => ({
const socketUrl = `ws://${WebSocketHost}:${host}/api/temperingGlass/api/talk/temperingGlass`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  // 更新 tableData 的数据
  adjustedRects.value =  data.intoGlass[0].map(rect => ({
        ...rect, // 复制原始对象的其他属性
        xcoordinate: rect.xcoordinate, // 将x值除以3
        ycoordinate: rect.ycoordinate,
        width: rect.width ,
        height: rect.height ,
      }));
      adjustedRectsa.value = data.waitingGlass[0].map(rect => ({
        ...rect, // 复制原始对象的其他属性  
        xcoordinate: rect.xcoordinate, // 将x值除以3  
        ycoordinate: rect.ycoordinate,
        width: rect.width ,
        height: rect.height ,
      }));  
        console.log(rect);
      adjustedRectsb.value = data.outGlass[0].map(rect => ({
        ...rect, // 复制原始对象的其他属性
        xcoordinate: rect.xcoordinate, // 将x值除以3
        ycoordinate: rect.ycoordinate,
        width: rect.width ,
        height: rect.height ,
      }));
};
      //   console.log( (rect.width*100) / 300 );
    } else {
      // console.error('Failed to fetch rectangles from API.');
      console.error('Failed to fetch rects from API.');
    }
  } catch (error) {
    // console.error('Error fetching rectangles :', error);
    console.error('Error fetching rects :', error);
  }
});
// 初始化 WebSocket,并传递消息处理函数
onMounted(() => {
  // fetchFlowCardId();
  // fetchTableData(); // 获取数据
  initializeWebSocket(socketUrl, handleMessage);
});
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();
});
// onMounted(async () => {
//   try {
//     const response = await request.get('/temperingGlass/temperingGlassInfo/SelectIntoGlass');
//     if (response.code === 200) {
//       const rawRects = response.data; // 设置矩形数据
//       console.log(response.data);
//       const { height: newheight,width: newwidth  } = response.data; // 获取尺寸
//       height.value = newheight;
//       width.value = newwidth;
//       adjustedRects.value = rawRects.map(rect => ({
//         ...rect, // 复制原始对象的其他属性
//         xcoordinate: rect.xcoordinate, // 将x值除以3
//         ycoordinate: rect.ycoordinate,
//         width: rect.width ,
//         height: rect.height ,
//       }));
//         console.log(rect);
//       //   console.log( (rect.width*100) / 300 );
//     } else {
//       // console.error('Failed to fetch rectangles from API.');
//       console.error('Failed to fetch rects from API.');
//     }
//   } catch (error) {
//     // console.error('Error fetching rectangles :', error);
//     console.error('Error fetching rects :', error);
//   }
// });
// 进炉前
const handleConfirm = async () => {
  try {
    const response = await request.post('/temperingGlass/temperingGlassInfo/SelectWaitingGlass');
    if (response.code === 200) {
      const rawRects = response.data; // 设置矩形数据
      console.log(response.data);
      const { height: newheight,width: newwidth  } = response.data; // 获取尺寸
      height.value = newheight;
      width.value = newwidth;
// const handleConfirm = async () => {
//   try {
//     const response = await request.post('/temperingGlass/temperingGlassInfo/SelectWaitingGlass');
//     if (response.code === 200) {
//       const rawRects = response.data; // 设置矩形数据
//       console.log(response.data);
//       const { height: newheight,width: newwidth  } = response.data; // 获取尺寸
//       height.value = newheight;
//       width.value = newwidth;
      adjustedRectsa.value = rawRects.map(rect => ({
        ...rect, // 复制原始对象的其他属性
        xcoordinate: rect.xcoordinate, // 将x值除以3
        ycoordinate: rect.ycoordinate,
        width: rect.width ,
        height: rect.height ,
      }));
        console.log(rect);
//       adjustedRectsa.value = rawRects.map(rect => ({
//         ...rect, // 复制原始对象的其他属性
//         xcoordinate: rect.xcoordinate, // 将x值除以3
//         ycoordinate: rect.ycoordinate,
//         width: rect.width ,
//         height: rect.height ,
//       }));
//         console.log(rect);
      //   console.log( (rect.width*100) / 300 );
    } else {
      // console.error('Failed to fetch rectangles from API.');
      console.error('Failed to fetch rects from API.');
    }
  } catch (error) {
    // console.error('Error fetching rectangles :', error);
    console.error('Error fetching rects :', error);
  }
};
//       //   console.log( (rect.width*100) / 300 );
//     } else {
//       // console.error('Failed to fetch rectangles from API.');
//       console.error('Failed to fetch rects from API.');
//     }
//   } catch (error) {
//     // console.error('Error fetching rectangles :', error);
//     console.error('Error fetching rects :', error);
//   }
// };
// 已出炉
const handleConfirma = async () => {
  try {
    const response = await request.get('/temperingGlass/temperingGlassInfo/SelectOutGlass');
    if (response.code === 200) {
      const rawRects = response.data; // 设置矩形数据
      console.log(response.data);
      const { height: newheight,width: newwidth  } = response.data; // 获取尺寸
      height.value = newheight;
      width.value = newwidth;
// const handleConfirma = async () => {
//   try {
//     const response = await request.get('/temperingGlass/temperingGlassInfo/SelectOutGlass');
//     if (response.code === 200) {
//       const rawRects = response.data; // 设置矩形数据
//       console.log(response.data);
//       const { height: newheight,width: newwidth  } = response.data; // 获取尺寸
//       height.value = newheight;
//       width.value = newwidth;
      adjustedRectsb.value = rawRects.map(rect => ({
        ...rect, // 复制原始对象的其他属性
        xcoordinate: rect.xcoordinate, // 将x值除以3
        ycoordinate: rect.ycoordinate,
        width: rect.width ,
        height: rect.height ,
      }));
        console.log(rect);
//       adjustedRectsb.value = rawRects.map(rect => ({
//         ...rect, // 复制原始对象的其他属性
//         xcoordinate: rect.xcoordinate, // 将x值除以3
//         ycoordinate: rect.ycoordinate,
//         width: rect.width ,
//         height: rect.height ,
//       }));
//         console.log(rect);
      //   console.log( (rect.width*100) / 300 );
    } else {
      // console.error('Failed to fetch rectangles from API.');
      console.error('Failed to fetch rects from API.');
    }
  } catch (error) {
    // console.error('Error fetching rectangles :', error);
    console.error('Error fetching rects :', error);
  }
};
//       //   console.log( (rect.width*100) / 300 );
//     } else {
//       // console.error('Failed to fetch rectangles from API.');
//       console.error('Failed to fetch rects from API.');
//     }
//   } catch (error) {
//     // console.error('Error fetching rectangles :', error);
//     console.error('Error fetching rects :', error);
//   }
// };
const gridOptions = reactive({
  border:  "full",//表格加边框
  keepSource: true,//保持源数据
@@ -173,7 +214,7 @@
      <el-scrollbar height="630px">
    <div  style="position: relative;width: 1400px;">  
      <div  
      v-for="(rect, index) in adjustedRects"
      v-for="(rect, index) in adjustedRectsa"
      :key="index"  
      class="rect"  
      :style="{ position: 'absolute',  top: `${rect.ycoordinate}px`, left: `${rect.xcoordinate}px`, width: `${rect.width}px`, height: `${rect.height}px`  }"  
@@ -191,7 +232,7 @@
      <el-scrollbar height="630px">
    <div  style="position: relative;width: 1400px;">  
      <div  
      v-for="(rect, index) in adjustedRects"
      v-for="(rect, index) in adjustedRectsb"
      :key="index"  
      class="rect"  
      :style="{ position: 'absolute',  top: `${rect.ycoordinate}px`, left: `${rect.xcoordinate}px`, width: `${rect.width}px`, height: `${rect.height}px`  }"