严智鑫
2024-07-05 c7093edbf1fb3c91107c457ea13935305e1a9458
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<template>
  <div>
    <el-card style="flex: 1;margin-left: 10px;margin-top: 20px;" v-loading="loading">
      <div style="width: 98%; height: calc(100% - 35px); overflow-y: auto;">
        <el-table height="240" ref="table" 
        @selection-change="handleSelectionChange"
        :data="tableData" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}">
          <el-table-column prop="slot" align="center" :label="$t('sorter.gridnumber')" min-width="80" />
          <el-table-column prop="glass_id" align="center" :label="$t('sorter.glassnumber')" min-width="80" />
          <el-table-column prop="width" align="center" :label="$t('sorter.width')" min-width="120" />
          <el-table-column prop="height" align="center" :label="$t('sorter.height')" min-width="120" />
          <el-table-column
          align="center"
            :label="$t('sorter.startstatus')"
            min-width="80"
            prop="enable_state"
          >
          <template #default="scope">  
          <el-tag  
            :type="scope.row.enable_state === 1 ? 'success' : 'danger'"  
            @click="toggleEnableState(scope.row)"  
          >  
            {{ scope.row.enable_state === 1 ?  $t('sorter.start') : $t('sorter.disable') }}
          </el-tag>  
        </template> 
          <!-- <template #default="scope">
            <el-tag type="success" >{{ scope.row.enable_state==1?"启用":"未启用"  }}</el-tag>
          </template> -->
          </el-table-column>
          <el-table-column fixed="right" :label="$t('sorter.operate')" align="center" width="200">
            <template #default="scope">
              <el-button size="mini" type="text" plain  @click="open(scope.row)">{{ $t('sorter.deficiencieste') }}</el-button>
              <el-button size="mini" type="text" plain  @click="opena(scope.row)">{{ $t('sorter.updown') }}</el-button>
            </template>
        </el-table-column>
        </el-table>
      </div>
    </el-card>
  </div>
  <div id="awatch">
    <img src="../../assets/woshihuancun.png" alt="" style="width: 60%;height: 90%;margin-left: 260px;margin-top: 20px;position: relative;"> 
    <div style="position: absolute; width: 500px;height: 95px;margin-top: -165px;margin-left: 450px;">
    <div  
      v-for="(rect, index) in adjustedRects"  
      :key="rect"  
      :style="{ position: 'absolute', 
       top: `${rect.id}px`, left: `10px`, width: `${rect.width}px`, height: `5px`,
      backgroundColor: '#409EFF'
       }"  
    >
    </div>
  </div>
</div>
</template>
<script setup>
import {Search,Lock,Avatar} from "@element-plus/icons-vue";
import {reactive} from "vue";
import {useRouter} from "vue-router"
const router = useRouter()
const adda = ref(false)
import { WebSocketHost ,host} from '@/utils/constants'
import request from "@/utils/request"
import { ref, onMounted , onBeforeUnmount} from "vue";
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
// import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
//  import LanguageMixin from './lang/LanguageMixin'
 
import { useI18n } from 'vue-i18n'
  const { t } = useI18n()
// import i18n from '@/i18n';
const tableData = ref([])
const slot = ref('')
const adjustedRects = ref([]);
  
onMounted(async () => {  
  try {  
    const response = await request.get('/unLoadGlass/downStorage/selectStorageCage'); // 替换为你的API端点  
    if (response.code === 200) {  
      const rawRects = response.data; // 设置矩形数据  
          tableData.value = response.data
          console.log(response.data);
          adjustedRects.value = rawRects.map(rect => ({  
            ...rect, // 复制原始对象的其他属性  
            width: rect.width * 0.5 ,
            id: rect.id * 10,
          })); 
          console.log(adjustedRects.value);
    } else {  
      ElMessage.warning(res.msg)
    }  
  } catch (error) {  
    // console.error('Error fetching rects :', error);  
  }  
}); 
const open = async(row) => {
  try {
    const confirmResult = await ElMessageBox.confirm(  
      t('sorter.information'), 
      t('sorter.prompt'),  
      {  
        confirmButtonText: t('sorter.yes'), 
        cancelButtonText: t('sorter.cancel'),
        type: 'warning',  
      } 
    );  
    if (confirmResult === 'confirm') {  
      // 用户点击了“是”,现在调用删除接口  
      var url="/unLoadGlass/downStorage/deleteDownStorageCage?downStorageCageId="+row.id;
      console.log(url);
      const response = await request.post(url, {
        esdId: row.esdId
    })
    if (response.code === 200) {
      ElMessage.success(response.message);
      } else {  
        // 删除失败,您可以处理错误或显示错误信息给用户  
      ElMessage.error(response.message);
        // alert('删除失败:' + deleteResponse.message); 
      }  
    }  
  } 
  catch (error) {  
    // 处理可能出现的错误,比如 ElMessageBox 抛出的异常等  
    console.error('发生错误:', error);  
  }  
};  
// 人工下片
const opena = async(row) => {
  try {
    const confirmResult = await ElMessageBox.confirm(  
      t('sorter.infor'), 
      t('sorter.prompt'),  
      {  
        confirmButtonText: t('sorter.yes'), 
        cancelButtonText: t('sorter.cancel'),
        type: 'warning',  
      } 
    );  
    if (confirmResult === 'confirm') {
      const response = await request.post("/unLoadGlass/downGlassTask/generateOutGlassTask", {
        glassId: row.glass_id
      })
    if (response.code === 200) {
      ElMessage.success(response.message);
      } else {  
        // 删除失败,您可以处理错误或显示错误信息给用户  
      ElMessage.error(response.message);
        // alert('删除失败:' + deleteResponse.message); 
      }  
    }  
  } 
  catch (error) {  
    // 处理可能出现的错误,比如 ElMessageBox 抛出的异常等  
    console.error('发生错误:', error);  
  }  
};  
// const open = async(row) => {
// const { t } = useI18n();
//   try {
//     const confirmMessage = t('sorter.prompt'); // 使用 $t 翻译文本
//     const confirmResult = await ElMessageBox.confirm(  
//       confirmMessage,  
//       t('sorter.information'), 
//       {  
//         confirmButtonText: t('sorter.yes'), 
//         cancelButtonText: t('sorter.cancel'),
//         type: 'warning',  
//       } 
//     );  
//     if (confirmResult === 'confirm') {  
//       // 用户点击了“是”,现在调用删除接口  
//       var url="/cacheGlass/edgStorageCage/edgStorageCageGlass?edgStorageCageId="+row.id;
//       console.log(url);
//       const response = await request.post(url, {
//         esdId: row.esdId
//     })
//     if (response.code === 200) {
//       ElMessage.success(response.message);
//       } else {  
//         // 删除失败,您可以处理错误或显示错误信息给用户  
//       ElMessage.error(response.msg);
//         // alert('删除失败:' + deleteResponse.message); 
//       }  
//     }  
//   } 
  
  
//   catch (error) {  
//     // 处理可能出现的错误,比如 ElMessageBox 抛出的异常等  
//     console.error('发生错误:', error);  
//   }  
// };   
const toggleEnableState = async (row) => {  
  const newState = row.enable_state === 1 ? 0 : 1;  
  // 发送请求到后端更新状态(这里省略了实际的请求逻辑)  
  const response = await request.post('/unLoadGlass/downStorage/updateDownStorageCage', { id: row.id, enablestate: newState });  
  if (response.code === 200) {
      ElMessage.success(response.message);
      } else {  
      ElMessage.error(response.message);
      }  
  row.enable_state = newState;  
};
const socketUrl = `ws://${WebSocketHost}:${host}/api/unLoadGlass/api/talk/unloadglass`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  // 更新 tableData 的数据
  tableData.splice(0, tableData.length, ...data.params[0]);
  // tableData.value = data.params[0]
  // adjustedRects.value = data.EdgStorageCageinfos[0]
  adjustedRects.value = data.params[0].map(rect => ({  
            ...rect, // 复制原始对象的其他属性  
            width: rect.width * 0.5 ,
            id: rect.id * 10,
          })); 
 
};
// 初始化 WebSocket,并传递消息处理函数
onMounted(() => {
  // fetchFlowCardId();
  // fetchTableData(); // 获取数据
  initializeWebSocket(socketUrl, handleMessage);
});
 
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();
});
</script>
<style scoped>
 
#dt { display:block; float:left;line-height: 20px;margin-left: 100px;}
#dta { display:block; float:left;line-height: 20px;margin-left: 80%;}
#dialog-footer{
  text-align: center;
  margin-top: -15px;
}
#message{
  text-align: center;
  align-items: center;
  color: black;
   width: 200px;
   height: 100px;
   background-color: #337ecc;
   margin-left: 28%;
}
#awatch{
  height: 460px;
  width: 1500px;
  /* margin-top: -60px; */
}
</style>