wangfei
2025-01-07 e875c70fea51ffafd689fd0d5f8b51bd3df40de0
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
<template>
  <div style="height: 500px;">
    <el-card style="flex: 1;margin-left: 10px;margin-top: 10px;margin-right: 10px;height: 800px;" v-loading="loading">
      <el-scrollbar height="750px" width="1400px" style="background-color: #e9e9eb;">
        <div style="position: relative;">
          <div
              v-for="(rect, index) in adjustedRects"
              :key="rect.glassId"
              class="rect"
              @click="showDialog(rect.glassId)"
              :style="{ position: 'absolute',
              top: `${rect.yAxisa}px`, left: `${rect.xAxisa}px`, width: `${rect.width}px`, height: `${rect.height}px`,
              backgroundColor: rect.isActive ? '#ADFF2F' : getRectColor(rect.state)
               }">
            <div class="centered-text">
              <div style="font-size: 20px;font-weight: bold;">{{ rect.glassId }}</div>
              <div style="font-size: 20px;font-weight: bold;">{{ rect.flowCardId }}</div>
              <div style="font-size: 30px;font-weight: bold;">{{ rect.widtha }}*{{ rect.heighta }}</div>
            </div>
          </div>
        </div>
      </el-scrollbar>
      <el-dialog v-model="blind" top="30vh" width="15%" style="text-align: center;" @close="handleDialogClose">
        <el-button :disabled="currentGlassRect?.state === 8 || currentGlassRect?.state === 9" type="warning"
                   plain :icon="Delete" @click="handleDamage(currentGlassId)" style="width: 140px;margin-left: 10px;">
          {{ $t('order.dilapidation') }}
        </el-button>
        <el-button :disabled="currentGlassRect?.state === 9 || currentGlassRect?.state === 8" type="danger"
                   plain @click="handleManualTake(currentGlassId)" style="width: 140px;margin-top: 10px;">
          <el-icon class="el-icon--right">
            <Upload/>
          </el-icon>
          {{ $t('order.takeaway') }}
        </el-button>
      </el-dialog>
    </el-card>
  </div>
</template>
<script setup lang="ts">
import {ElMessage} from 'element-plus'
import {onBeforeUnmount, computed, onMounted, onUnmounted, ref} from 'vue';
import request from "@/utils/request"
import {host, WebSocketHost} from '@/utils/constants'
import {closeWebSocket, initializeWebSocket} from '@/utils/WebSocketService';
import {useI18n} from 'vue-i18n'
const {t} = useI18n()
let language = ref(localStorage.getItem('lang') || 'zh')
const blind = ref(false)
const currentGlassId = ref(null);
const adjustedRects = ref([]);
let socket = null;
const currentGlassRect = computed(() => {
  return adjustedRects.value.find(rect => rect.glassId === currentGlassId.value);
});
function showDialog(glassId: number) {
  currentGlassId.value = glassId;
  blind.value = true;
  adjustedRects.value = adjustedRects.value.map(rect =>
      rect.glassId === glassId ? {...rect, isActive: true} : rect
  );
}
const handleDialogClose = () => {
  adjustedRects.value = adjustedRects.value.map(rect => ({
    ...rect,
    isActive: false
  }));
}
// 破损
const handleDamage = async () => {
  try {
    const response = await request.post('/cacheGlass/taskCache/identControls', {
      glassId: currentGlassId.value,
      state: 8,
      line: 1,
      remark: '掰片',
      workingProcedure: '切割',
    })
    if (response.code == 200) {
      ElMessage.success(response.message);
      blind.value = false;
      updateRectStatus(currentGlassId.value, 8);
    } else {
      ElMessage.error(response.msg);
    }
  } catch (error) {
    console.error(error);
  }
}
// 人工拿走
const handleManualTake = async () => {
  try {
    const response = await request.post('/cacheGlass/taskCache/identControls', {
      glassId: currentGlassId.value,
      state: 9,
      line: 1,
      workingProcedure: '切割',
      remark: '掰片',
    })
    if (response.code == 200) {
      ElMessage.success(response.message);
      blind.value = false;
      updateRectStatus(currentGlassId.value, 9);
    } else {
      ElMessage.error(response.msg);
    }
  } catch (error) {
    console.error(error);
  }
}
function getRectColor(state: number): string {
  switch (state) {
    case 0:
      return '#e1f3d8';
    case 100:
      return '#c8c9cc';
    case 110:
      return '#b3e19d';
    case 120:
      return '#f89898';
    case 8:
      return '#911005';
    case 9:
      return '#f3d19e';
  }
}
// 更新矩形状态
function updateRectStatus(glassId: string, status: number) {
  adjustedRects.value.forEach(rect => {
    if (rect.glassId === glassId) {
      rect.state = status; // 更新矩形的状态  
    }
  });
}
const socketUrl = `ws://${WebSocketHost}:${host}/api/cacheGlass/api/talk/currentCutDrawingOne`;
const handleMessage = (data: any) => {
      const scaleFactor = 1621.78 / 6000;
      const scaleFactory = 750 / 3300;
      if (data.currentCutTerritory && data.currentCutTerritory.length > 0) {
        const newRects = data.currentCutTerritory[0].map(rect => {
          const existingRect = adjustedRects.value.find(r => r.glassId === rect.glassId);
          if (existingRect) {
            return {
              ...existingRect,
              xAxisa: (6000 - (rect.xAxis + rect.width)) * scaleFactor * 1.1,
              yAxisa: rect.yAxis * scaleFactory * 1.1,
              width: rect.edgWidth * scaleFactor * 1.1,
              height: rect.edgHeight * scaleFactory * 1.1,
              widtha: rect.edgWidth,
              heighta: rect.edgHeight,
              state: rect.state,
              // 保持 isActive 状态不变
            };
          } else {
            // 如果不存在,则添加新矩形,默认 isActive 为 false
            return {
              ...rect,
              xAxisa: (6000 - (rect.xAxis + rect.width)) * scaleFactor * 1.1,
              yAxisa: rect.yAxis * scaleFactory * 1.1,
              width: rect.edgWidth * scaleFactor * 1.1,
              height: rect.edgHeight * scaleFactory * 1.1,
              widtha: rect.edgWidth,
              heighta: rect.edgHeight,
              state: rect.state,
              isActive: false,
              glassId: rect.glassId,
            };
          }
        });
        adjustedRects.value = newRects;
      } else if (data.currentCutTerritory == '') {
        adjustedRects.value = [];
      }
}
onMounted(() => {
  socket = initializeWebSocket(socketUrl, handleMessage);
});
onBeforeUnmount(() => {
  closeWebSocket();
});
</script>
<style scoped>
.rect {
  border: 1px solid black; /* 设置矩形的边框 */
  /* background-color: lightblue; 设置矩形的背景色   */
}
.centered-text {
  /* 设置文字居中样式 */
  /* display: flex; */
  justify-content: center;
  align-items: center;
  height: 100%; /* 确保div占据整个矩形的高度 */
  /* font-size: large; */
}
#line {
  position: absolute;
  top: 70%; /* 直线位于矩形中间 */
  left: 210px; /* 直线在箭头右侧一些距离 */
  transform: translateY(-50%); /* 垂直居中 */
  height: 2px; /* 直线的高度 */
  width: 240px; /* 直线的长度,根据需要调整 */
  background-color: #911005; /* 直线的颜色 */
}
</style>