huang
4 天以前 9dcde5b27b70a4b0c0885347af5405eb2d1ef089
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<script setup lang="ts">
import {onBeforeUnmount, onMounted, ref} from "vue";
import {ElMessage} from 'element-plus'
import {closeWebSocket, initializeWebSocket} from '@/utils/WebSocketService';
import {useI18n} from 'vue-i18n'
import {useRouter} from 'vue-router'
import {fetchAllMessage, updateTempQueueState} from '@/api/tempering'
 
const { t } = useI18n()
const router = useRouter()
const adjustedTemper = ref([])
const dialogBaked = ref(false)
const cantakeBaked = ref(true)
const canSelectProjectOut = ref(true)
const currentRect = ref(null)
const currentGlassId = ref(null)
const currenttemperingFeedSequence = ref(null)
const activeRectId = ref(null) // 新增:专门跟踪激活的矩形 ID
// 获取数据
const fetchData = async () => {
  try {
    const result = await fetchAllMessage()
    const firstKey = Object.keys(result.data.tempBeforeQueueInfo)[0]
    if (firstKey && result.data.tempBeforeQueueInfo[firstKey]) {
      processTemperData(result.data.tempBeforeQueueInfo[firstKey])
    }
  } catch (error) {
  }
}
// 处理钢化数据
const processTemperData = (data) => {
  adjustedTemper.value = data.map(rect => {
    // 保留现有的 isActive 状态(如果存在)
    const existingRect = adjustedTemper.value.find(r => r.id === rect.id)
    const isActive = existingRect ? existingRect.isActive : false
 
    const scaleFactor = 1621.78 / 6000
    const scaleFactorY = 700 / 2800
    let adjustedWidth, adjustedHeight, widtha, heighta
    if (rect.width < rect.height) {
      widtha = rect.height
      heighta = rect.width
    } else {
      widtha = rect.width
      heighta = rect.height
    }
    // 计算位置和尺寸
    let newX = rect.ycoordinate
    if (rect.angle === 0) {
      adjustedWidth = widtha * scaleFactor
      adjustedHeight = heighta * scaleFactorY
      newX = 6000 - (rect.ycoordinate + widtha)
    } else {
      adjustedWidth = heighta * scaleFactor
      adjustedHeight = widtha * scaleFactorY
      newX = 6000 - (rect.ycoordinate + heighta)
    }
    return {
      ...rect,
      x: newX * scaleFactor,
      y: rect.xcoordinate * scaleFactorY,
      width: adjustedWidth,
      height: adjustedHeight,
      widtha: rect.width,
      heighta: rect.height,
      isActive: activeRectId.value === rect.id ? true : isActive // 从外部状态设置
    }
  })
}
// WebSocket 消息处理
const socketUrl = `ws://${window.ipConfig.serverUrl}/temperingGlass/webSocket/tempGlass`
const handleMessage = (data) => {
  if (data?.tempBeforeQueueInfo) {
    const firstKey = Object.keys(data.tempBeforeQueueInfo)[0]
    if (firstKey && data.tempBeforeQueueInfo[firstKey]) {
      processTemperData(data.tempBeforeQueueInfo[firstKey])
    }
  }
}
// 显示对话框
function showDialogOut(rect) {
  activeRectId.value = rect.id // 只存储 ID 而不是整个对象
  const index = adjustedTemper.value.findIndex(r => r.id === rect.id)
  if (index !== -1) {
    // 重置所有矩形的激活状态
    adjustedTemper.value.forEach(r => { r.isActive = false })
    adjustedTemper.value[index].isActive = true
    currentGlassId.value = rect.id
    currenttemperingFeedSequence.value = rect.temperingFeedSequence
    dialogBaked.value = true
    currentRect.value = rect
    // 更新按钮状态
    canSelectProjectOut.value = rect.state !== 8
  }
}
// 关闭对话框
const handleDialogCloseOut = () => {
  activeRectId.value = null
  adjustedTemper.value.forEach(rect => {  
    rect.isActive = false  
  })  
  dialogBaked.value = false 
}
// 破损处理
const handleDamageOut = async () => {
  if (!currentGlassId.value) {
    return
  }
  try {
    await updateTempQueueState(currentGlassId.value, 8)
    ElMessage.success('操作成功!')
    dialogBaked.value = false
    updateRectColorsOut()
  } catch (error) {
  }
}
onMounted(() => {
  fetchData()
  initializeWebSocket(socketUrl, handleMessage)
})
// 更新矩形颜色状态
function updateRectColorsOut() {
  adjustedTemper.value.forEach(rect => {  
    if (rect.id === currentGlassId.value) {  
      rect.state = 8
    }
  })  
}
// 获取矩形颜色
function getRectColorOut(state) {  
  switch (state) {  
    case 3: return '#eebe77'  
    case 4: return '#CD6090'
    case 8: return '#911005' 
    case 9: return '#4682B4' 
    default: return '#CDAF95' 
  }  
}
onBeforeUnmount(() => {
  closeWebSocket()
})
</script>
<template>
  <div style="height: 870px;">
    <div style="margin-top: 10px; height: 100%; display: flex; flex-direction: column;">
      <el-card style="margin-left: 10px; margin-right: 10px; margin-top: 10px;">
        <div style="height: 100%;">
          <el-scrollbar height="800px" style="background-color: #e9e9eb; height: 100%;">
            <div style="position: relative; max-width: 1400px; height: 100%;">
              <div  
                v-for="(rect, index) in adjustedTemper"
                :key="index"  
                @click="showDialogOut(rect)"  
                class="rect"  
                :style="{ 
                  position: 'absolute',
                  top: `${rect.y}px`,
                  left: `${rect.x}px`,
                  width: `${rect.width}px`, 
                  height: `${rect.height}px`,
                  backgroundColor: rect.isActive ? '#ADFF2F' : getRectColorOut(rect.state),
                  cursor: 'pointer'
                }">
                <div class="centered-text">
                  <div style="font-size: 10px;font-weight: bold;">{{ rect.glassId }}</div>  
                  <div style="font-size: 10px;font-weight: bold;">{{ rect.flowCardId }}</div>  
                  <div style="font-size: 15px;font-weight: bold;">{{ rect.widtha }}*{{ rect.heighta }}</div>  
                </div>
              </div> 
            </div>
          </el-scrollbar>
        </div>
      </el-card>
      <el-dialog 
        v-model="dialogBaked" 
        top="30vh" 
        width="15%" 
        style="text-align: center;" 
        @close="handleDialogCloseOut"
      >
        <el-button 
          :disabled="!canSelectProjectOut" 
          type="warning" 
          plain 
          @click="handleDamageOut"
          style="width: 150px;margin-left: 10px;"
        >
          {{ $t('Mounting.dilapidation') }}
        </el-button>
      </el-dialog> 
    </div>
  </div>
</template>
<style scoped>
.rect {  
  border: 1px solid black;
  transition: background-color 0.3s ease;
.rect:hover {
  opacity: 0.8;
}
.centered-text {
  display: flex;
  flex-direction: column;
  justify-content: center;  
  align-items: center; 
  height: 100%;
  text-align: center;
</style>