huang
2025-05-20 2c2413760b6467bf62402dba7338bd3bbcbd7341
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<!--  打标机  -->
<script setup>
import request from "@/utils/request";
import { ElMessage, ElMessageBox } from "element-plus";
import { reactive, ref, onMounted, onBeforeUnmount, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { WebSocketHost, host } from '@/utils/constants'
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
 
import {gridDateFormatter} from '@/stores/tool';
 
let language = ref(localStorage.getItem('lang') || 'zh')
const { t } = useI18n()
const requestData = reactive({
  account: '',
  password: '',
});
const blind = ref(false)
const errorInfo = ref(true)
const loadData = ref([]);
const findMachine = ref([]);
const sendRecords = ref([]);
const downLineTask = ref([]);
 
const userInfo=JSON.parse(window.localStorage.getItem('userInfo'));
const pageParams=userInfo.user.menus[0].pages[2].params;
const pageParamsJson=JSON.parse(pageParams);
const machineId = pageParamsJson.machineId;//当前页面的设备ID
console.log(machineId);
//const machineId = 26;//当前页面的设备ID
var errorScanId;
var errorOpen=false;
//使用WebSocket方式展示数据
let socket = null;
let socketDownLineTask = null;
const socketUrl = `ws://${WebSocketHost}:${host}/api/deviceInteraction/api/talk/flipSlice`;
const socketDownLineTaskUrl = `ws://${WebSocketHost}:${host}/api/deviceInteraction/api/talk/downLineTask`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  // 更新 tableData 的数据
  let dataJson = data[""+machineId][0];
 
  loadData.value = dataJson.taskingList[0];
  findMachine.value = dataJson.machine[0];
  sendRecords.value = dataJson.sendRecords[0].reverse();
  if(findMachine.value.remark.toString()!=errorScanId&&findMachine.value.remark.toString()!=""&&findMachine.value.remark.toString()!=undefined){
    //有数据就弹窗 
    if(errorOpen){
      ElMessageBox.close();
    }
    errorScanId=findMachine.value.remark.toString();
    errorInfoFuntion(findMachine.value.remark.toString());
    errorOpen=true;
  }else if(findMachine.value.remark.toString()==""&&errorOpen){
    ElMessageBox.close();
    errorOpen=false;
  }
   
};
// 定义消息处理函数,更新 receivedData 变量
const handleMessage2 = (data) => {
  downLineTask.value = data.downLineTask[0];
  // console.log(data);
};
onUnmounted(() => {
  if (socket) {
    closeWebSocket(socket);
  }
  if (socketDownLineTask) {
    closeWebSocket(socketDownLineTask);
  }
});
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();
});
 
onMounted(async () => {
  //使用WebSocket方式展示数据
  socket = initializeWebSocket(socketUrl, handleMessage);// 初始化 WebSocket,并传递消息处理函数
  //使用WebSocket方式展示数据
  socketDownLineTask = initializeWebSocket(socketDownLineTaskUrl, handleMessage2);// 初始化 WebSocket,并传递消息处理函数
});
//报警提示
const errorInfoFuntion = async (info) => {
  let infoScancode=info;
  ElMessageBox.confirm(
    infoScancode,
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sureStart'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
//修改工作状态 【失败/正在工作/完工】
const workStatus = async (row, state) => {
  let url;
  if (state == "重发") {
    url = "/deviceInteraction/tasking/loseMachineTask";
  } else if (state == "正在工作") {
    url = "/deviceInteraction/tasking/startMachineTask";
  } else if (state == "完工") {
    url = "/deviceInteraction/tasking/finishMachineTask";
  } else {
    return;
  }
  ElMessageBox.confirm(
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //开始修改
      request.post(url,
        {
          "id": machineId
        }).then((res) => { // 替换为你的API端点  
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {
            ElMessage.warning(res.message)
          }
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
 
}
 
//开工/暂停
const machineStatus = async (state) => {
  ElMessageBox.confirm(
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //下线接口
      request.post("/deviceInteraction/machine/updateMachineState",
        {
          "id": machineId,
          "state": state
        }).then((res) => { // 替换为你的API端点  
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {
            ElMessage.warning(res.message)
          }
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
//定制/标准
const machineMode = async (mode) => {
  ElMessageBox.confirm(
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //下线接口
      request.post("/deviceInteraction/machine/toggleModeMachine",
        {
          "id": machineId,
          "mode": mode
        }).then((res) => { // 替换为你的API端点  
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {
            ElMessage.warning(res.message)
          }
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
//破损
const damagedTask = async (row) => {
  ElMessageBox.confirm(
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //下线接口
      request.post("/deviceInteraction/tasking/damagedTask",
        {
          "glassId": row.glassId
        }).then((res) => { // 替换为你的API端点  
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {
            ElMessage.warning(res.message)
          }
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
//下线(拿走)
const glassDownLine = async (row) => {
  ElMessageBox.confirm(
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //下线接口
      request.post("/deviceInteraction/tasking/glassDownLine",
        {
          "glassId": row.glassId,
        }).then((res) => { // 替换为你的API端点  
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {
            ElMessage.warning(res.message)
          }
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
const topLineShow = async () => {
  blind.value = true; 
}
//上线
const topLine = async (row) => {
  ElMessageBox.confirm(
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //上线接口
      request.post("/deviceInteraction/tasking/glassTopLine",
        {
          "glassId": row.glassId,
          "lineConfigurationId": machineId
        }).then((res) => { // 替换为你的API端点  
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {n
            ElMessage.warning(res.message)
          }
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
const handleDialogClose = () => {  
    
}
</script>
<template>
  <div ref="content" style="padding:0 20px;">
    <div id="div-title" style="font-size: 20px; font-weight: bold; margin:10px 0 10px 0;padding-left: 20px;">
      {{ $t('machine.flipSlice') }}
    </div>
    <el-dialog v-model="blind" top="30vh" style="text-align: center;" @close="handleDialogClose">
        <!-- 线下玻璃 -->
      <el-table :data="downLineTask" stripe :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129', textAlign: 'center' }" :cell-style="{ textAlign: 'center' }">
        <!-- <el-table-column type="selection" min-width="30" /> -->
        <el-table-column type="index" :label="$t('glassInfo.number')" min-width="30" />
        <el-table-column prop="batchNumber" :label="$t('glassInfo.batchNumber')" />
        <el-table-column prop="taskType" :label="$t('glassInfo.taskType')" />
        <el-table-column prop="scanId" :label="$t('glassInfo.scanId')" />
        <el-table-column prop="length" :label="$t('glassInfo.length')" />
        <el-table-column prop="width" :label="$t('glassInfo.width')" />
        <el-table-column prop="thickness" :label="$t('glassInfo.thickness')" />
        <el-table-column prop="workState" :label="$t('glassInfo.workState')" />
        <el-table-column fixed="right" :label="$t('productStock.operate')" align="center" width="70">
          <template #default="scope">
            <el-button size="mini" link type="primary" plain @click="topLine(scope.row)">{{
              $t('functionState.topLine') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <hr />
    <br>
    <div id="search">
      <!-- 功能 -->
      <el-button :type="(findMachine['state'] == '暂停' ? 'danger' : 'success')" id="ButtonMachineStatus"
        @click="machineStatus((findMachine['state'] == '暂停' ? '开工' : '暂停'))">{{ findMachine['state'] == '开工' ?
          $t('functionState.start') : $t('functionState.stop') }}</el-button>
 
      <el-button :type="(findMachine['mode'] == '定制' ? 'danger' : 'success')" id="ButtonMachineMode"
        @click="machineMode((findMachine['mode'] == 0 ? 1 : 0))">{{ findMachine['mode'] == 0 ?
         $t('functionState.modeD') : $t('functionState.modeB') }}</el-button>
         
      <el-button type="primary" id="ButtonTopLine" @click="topLineShow">{{ $t('functionState.topLine') }}</el-button>
      <!-- <el-button type="primary" id="searchButton" @click="downLine('下线')">下线</el-button>
      <el-button type="primary" id="searchButton" @click="workStatus('破损')">破损</el-button>
      <el-button type="primary" id="searchButton" @click="workStatus('完工')">完工</el-button> -->
    </div>
    <div id="main-body">
      <!-- 表格内容 -->
      <el-table :data="loadData" stripe style="height:260px"
        :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129', textAlign: 'center' }"
        :cell-style="{ textAlign: 'center' }">
        <!-- <el-table-column type="selection" min-width="30" /> -->
        <el-table-column type="index" :label="$t('glassInfo.number')" min-width="30" />
        <el-table-column prop="batchNumber" :label="$t('glassInfo.batchNumber')" />
        <el-table-column prop="taskType" :label="$t('glassInfo.taskType')" />
        <el-table-column prop="glassId" :label="$t('glassInfo.glassId')" />
        <el-table-column prop="scanId" :label="$t('glassInfo.scanId')" />
        <el-table-column prop="length" :label="$t('glassInfo.length')" />
        <el-table-column prop="width" :label="$t('glassInfo.width')" />
        <el-table-column prop="thickness" :label="$t('glassInfo.thickness')" />
        <el-table-column prop="workState" :label="$t('glassInfo.workState')" />
        <el-table-column prop="operationRecordTime" :formatter="gridDateFormatter" :label="$t('glassInfo.operationRecordTime')" width="180"/>
        <el-table-column fixed="right" :label="$t('productStock.operate')" align="center" width="270">
          <template #default="scope">
            <el-button size="mini" link type="primary" plain @click="workStatus(scope.row, '重发')">{{
              $t('functionState.anew') }}</el-button>
            <el-button size="mini" link type="primary" plain @click="workStatus(scope.row, '完工')">{{
              $t('functionState.finish') }}</el-button>
            <el-button size="mini" link type="primary" plain @click="damagedTask(scope.row)">{{ $t('functionState.lose')
              }}</el-button>
            <el-button size="mini" link type="primary" plain @click="glassDownLine(scope.row)">{{
              $t('functionState.downLine') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
 
    <div id="main-body" style="width: 100%; height: 460px;min-width: 1200px;">
      <img style="width: 70%;min-width: 900px; height: 460px;float: left;" src="../../assets/翻片台.png">
      <!-- <el-image style="width: 70%;min-width: 900px; height: 460px;float: left;" src="../../src/assets/翻片台.png"></el-image> -->
      <!-- <div style="width: 70%;min-width: 900px; height: 460px;background-image: url(../../src/assets/翻片台.png) ;background-size: 100% 100%;float: left;">
 
      </div> -->
      <div style="width: 30%;min-width: 300px; height: 460px;float: left;padding: 20px;;">
        <el-table :data="sendRecords" stripe
          :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129', textAlign: 'center', height: '30px' }"
          :cell-style="{ textAlign: 'center' }">
          <el-table-column prop="sendContent" :label="$t('glassInfo.sendContent')" />
        </el-table>
      </div>
      <div style="clear:both"></div>
      <!-- 画图内容 -->
      <!-- <div :style="{
        width: loadData.length > 0 ? loadData[0]['length'] + 'px' : '200px',
        height: loadData.length > 0 ? loadData[0]['width'] + 'px' : '100px',
        backgroundColor: 'red',
        position: 'relative',
        top: '110px', 
        left: '28px',
        textAlign: 'center'
      }">
        <p v-if="loadData.length > 0">{{ loadData[0]['scanId'] }}</p>
        <p v-if="loadData.length > 0">
          {{ loadData[0]['length'] }} * {{ loadData[0]['width'] }}
        </p>
        <p v-else>暂无数据</p> 
      </div>
      <div :style="{
        width: loadData.length > 0 ? loadData[1]['length'] + 'px' : '200px',
        height: loadData.length > 0 ? loadData[1]['width'] + 'px' : '100px',
        backgroundColor: 'red',
        position: 'relative',
        top: '-70px',
        left: '878px',
        textAlign: 'center'
      }">
        <p v-if="loadData.length > 0">{{ loadData[1]['scanId'] }}</p>
        <p v-if="loadData.length > 0">
          {{ loadData[1]['length'] }} * {{ loadData[1]['width'] }}
        </p>
        <p v-else>暂无数据</p> 
      </div> -->
    </div>
  </div>
</template>
 
<style scoped>
table {
  text-align: center;
  width: 100%;
  height: 100%;
  border-collapse: collapse;
  border-spacing: 0;
}
 
table td {
  text-align: center;
}
 
#main-body {
  width: 100%;
  height: 100%;
  border: 1px solid #ccc;
  margin-top: 25px;
}
 
#searchButton {
  width: 100px;
  height: 40px;
  font-size: 16px;
  border-radius: 5px;
  background-color: #409EFF;
  color: #fff;
  border: none;
  cursor: pointer;
}
.dotClass {
  width:10px;
  height:10px;
  border-radius: 50%;
  display: block;
  margin-left: 10px; 
}
</style>