zhoushihao
2024-06-26 5a84728f49a5c708d21212b1a395bd62684efd48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<script setup>
import {Search} from "@element-plus/icons-vue";
import {reactive} from "vue";
import {useRouter} from "vue-router"
 
import { ref, onMounted, onBeforeUnmount } from 'vue';  
import { WebSocketHost ,host} from '@/utils/constants'
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
const adjustedRects = ref([]);
 
const dialogFormVisible = ref(true)
const dialogFormVisiblea = ref(false)
 
const getTableRow = (row,type) =>{
  switch (type) {
    case 'edit' :{
      //alert('我接收到子组件传送的编辑信息')
      router.push({path: '/main/returns/createReturns', query: { ReturnID: 'TH24010101' }})
      break
    }
    case 'delete':{
      alert('我接收到子组件传送的删除信息')
      break
    }
  }
}
 
const socketUrl = `ws://${WebSocketHost}:${host}/api/temperingGlass/api/talk/temperingGlass`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  // 更新 tableData 的数据
  adjustedRects.value =  data.overGlass[0].map(rect => ({  
        ...rect, // 复制原始对象的其他属性  
        xcoordinate: rect.xCoordinate * 0.5, // 将x值除以3  
        ycoordinate: rect.ycoordinate * 0.5,
        width: rect.width * 0.4,
        height: rect.height * 0.4,
        widtha: rect.width,
        heighta: rect.height,
      })); 
      console.log(data.intoGlass[0]);
};
onMounted(() => {
  // fetchFlowCardId();
  // fetchTableData(); // 获取数据
  initializeWebSocket(socketUrl, handleMessage);
});
 
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();
});
</script>
 
<template>
  <div style="margin-top: 10px;">
<div>
    <el-card style="margin-left: 10px;margin-top: 10px;margin-right: 10px;" v-loading="loading">
    <el-scrollbar height="600px">
    <div  style="position: relative;width: 1400px;">  
      <div  
      v-for="(rect, index) in adjustedRects"
      :key="index"  
      class="rect"  
      :style="{ position: 'absolute',  top: `${rect.ycoordinate}px`, left: `${rect.xcoordinate}px`,
       width: `${rect.width}px`, height: `${rect.height}px`,
       backgroundColor: rect.state === 4 ? '#d1edc4' : '#f8e3c5' }">
     <div  class="centered-text">
    <div >{{ rect.flowcardId }}</div>  
    <div style="margin-top: 50px;margin-left: -50px;">{{ rect.widtha }}*{{ rect.heighta }}</div>  
  </div>
  </div> 
   </div>
   </el-scrollbar>
    </el-card>
    </div>
  </div>
 
</template>
 
<style scoped>
#boxa{
  border: 1px solid rgb(119, 116, 116);
  background-color:  #529b2e;
  text-align: center;
  display: inline-block;
  margin-left: 20px;
  margin-top: 70px;
  margin-bottom: 50px;
}
.rect {  
  border: 1px solid black; /* 设置矩形的边框 */  
  background-color: lightblue; /* 设置矩形的背景色 */  
.centered-text {
  /* 设置文字居中样式 */  
  display: flex;  
  justify-content: center;  
  align-items: center;  
  height: 100%; /* 确保div占据整个矩形的高度 */  
</style>