wu
2024-06-04 36c8b97ef1d250e724696cae846a754d48a92512
UI-Project/src/views/Identify/identify.vue
@@ -42,8 +42,10 @@
<script setup lang="ts">  
import { Delete, Upload } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, onMounted } from 'vue';
import { ref, onMounted, onBeforeUnmount } from 'vue';
import request from "@/utils/request"
import { WebSocketHost } from '@/utils/constants'
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
const blind = ref(false)
const olWidth = ref(); 
const olHeight = ref();
@@ -83,8 +85,8 @@
        height:( rect.height*100) * 0.004 ,
        glass_state: rect.glass_state
      }));  
      console.log(adjustedRects.value);
      
        console.log(rect);
      //   console.log( (rect.width*100) / 300 );
    } else {  
@@ -174,6 +176,38 @@
    }  
  });  
}
const socketUrl = `ws://${WebSocketHost}:88/api/cacheGlass/api/talk/cacheGlass`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  // 更新 tableData 的数据
  // adjustedRects.value = data.currentCutTerritory[0]
  adjustedRects.value = data.currentCutTerritory[0].map(rect => ({
        ...rect, // 复制原始对象的其他属性
        x_axis: (rect.x_axis*100) * 0.005, // 将x值除以3
        y_axis: (rect.y_axis*100) * 0.005,
        width: (rect.width*100) * 0.004 ,
        widtha: rect.width ,
        heighta: rect.height ,
        height:( rect.height*100) * 0.004 ,
        glass_state: rect.glass_state
      }));
 // console.log("更新后数据", tableData);
};
// 初始化 WebSocket,并传递消息处理函数
onMounted(() => {
  // fetchFlowCardId();
  // fetchTableData(); // 获取数据
  initializeWebSocket(socketUrl, handleMessage);
});
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();
});
</script>  
  
<style scoped>