wangfei
2024-07-22 e90b0a04595e4de46802572bd5d7c6d9293ce2f2
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<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 的数据
  if(data.overGlass!=null){
    adjustedRects.value =  data.overGlass[0].map(rect => {  
  let adjustedWidth, adjustedHeight, adjustedWidtha, adjustedHeighta;
  if (rect.angle === 90) {  
    adjustedWidth = rect.height * 0.2;  
    adjustedHeight = rect.width * 0.2;  
    adjustedWidtha = rect.height;  
    adjustedHeighta = rect.width;  
  } else {  
    adjustedWidth = rect.width * 0.2;  
    adjustedHeight = rect.height * 0.2;  
    adjustedWidtha = rect.width;  
    adjustedHeighta = rect.height;  
  }  
  return {  
    ...rect, // 复制原始对象的其他属性  
    xcoordinate: rect.xCoordinate * 0.2, 
    ycoordinate: rect.yCoordinate * 0.2,
    width: adjustedWidth,  
    height: adjustedHeight,  
    widtha: adjustedWidtha, 
    heighta: adjustedHeighta,
  };  
});
  }
};
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">
      <div v-if="adjustedRects.length > 0">
    <div style="text-align: center;">流程卡: {{ adjustedRects[0].flowCardId }}</div>  
    <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.glassId }}</div>  
    <div style="margin-top: 50px;margin-left: -85px;">{{ rect.widtha }}*{{ rect.heighta }}</div>  
  </div>
  </div> 
   </div>
   </el-scrollbar>
   </div>
    </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>