提交 | 用户 | 时间
|
2c7661
|
1 |
<template> |
A |
2 |
<div class="app-container"> |
|
3 |
<el-row :gutter="5"> |
|
4 |
<el-col :span="7"> |
|
5 |
<el-card shadow="never"> |
|
6 |
<span class="head-font">工位编号 : {{headContent.processesCode}}</span> |
|
7 |
</el-card> |
|
8 |
</el-col> |
|
9 |
<el-col :span="7"> |
|
10 |
<el-card shadow="never"> |
|
11 |
<span class="head-font">工位名称 : {{headContent.processesName}}</span> |
|
12 |
</el-card> |
|
13 |
</el-col> |
|
14 |
<el-col :span="10"> |
|
15 |
<el-card shadow="never"> |
|
16 |
<span class="head-font">产品序列号 : {{headContent.sfcCode}}</span> |
|
17 |
<!-- <el-input v-model="content" style="float: right;width: 150px;" placeholder="请输入内容"></el-input>--> |
|
18 |
<!-- <el-button @click="scanCompleted" style="float: right" type="primary">扫码完成</el-button>--> |
|
19 |
<el-button type="primary" style="float: right" icon="el-icon-search" size="mini" @click="serialLink">串口连接</el-button> |
|
20 |
<el-button @click="clearClick" style="float: right" type="danger" size="mini">清除</el-button> |
|
21 |
</el-card> |
|
22 |
</el-col> |
|
23 |
|
|
24 |
</el-row> |
|
25 |
<el-row :gutter="5" style="margin-top: 5px"> |
|
26 |
<el-col :span="24"> |
|
27 |
<el-tabs type="border-card" style="height: 600px" v-model="activeName" @tab-click="changeMenu"> |
|
28 |
<el-tab-pane name="first"> |
|
29 |
<span slot="label"> <a class="el-icon-date"></a>首页</span> |
|
30 |
<el-col :span="24"> |
|
31 |
<el-table height="500" :cell-style="rowStyle" :data="formulaChildList"> |
|
32 |
<el-table-column label="排序" width="60" align="center" type="index"> |
|
33 |
</el-table-column> |
|
34 |
<el-table-column label="操作内容" :show-overflow-tooltip='true' align="center" prop="operationSteps"> |
|
35 |
</el-table-column> |
|
36 |
<el-table-column label="产品编号" align="center" prop="productCode"> |
|
37 |
</el-table-column> |
|
38 |
<el-table-column label="物料编码" align="center" prop="materialCode"> |
|
39 |
</el-table-column> |
|
40 |
<el-table-column label="采集值" align="center" prop="collectData"> |
|
41 |
</el-table-column> |
|
42 |
<el-table-column label="结果" align="center" prop="results"> |
|
43 |
</el-table-column> |
|
44 |
</el-table> |
|
45 |
</el-col> |
|
46 |
</el-tab-pane> |
|
47 |
</el-tabs> |
|
48 |
</el-col> |
|
49 |
</el-row> |
|
50 |
<el-dialog v-dialogpop-up :title="title" :visible.sync="open1" width="1000" append-to-body> |
|
51 |
<el-row |
|
52 |
type="flex" |
|
53 |
class="row-bg" |
|
54 |
justify="center" |
|
55 |
v-show="portsList.length === 0" |
|
56 |
> |
|
57 |
<el-col :span="7"> |
|
58 |
<div style="margin-top: 400px"> |
|
59 |
<span style="display: block"> |
|
60 |
仅支持Chrome 89+或者Edge 89+浏览器(安全上下文(HTTPS)中可用) |
|
61 |
</span> |
|
62 |
<el-button type="primary" @click="obtainAuthorization">授权</el-button> |
|
63 |
</div> |
|
64 |
</el-col> |
|
65 |
</el-row> |
|
66 |
<el-form |
|
67 |
v-show="portsList.length > 0" |
|
68 |
ref="form1" |
|
69 |
:model="form1" |
|
70 |
label-width="100px"> |
|
71 |
<el-row> |
|
72 |
<el-col :span="24" |
|
73 |
><div> |
|
74 |
<el-form-item label="串口"> |
|
75 |
<el-select |
|
76 |
v-model="form1.port" |
|
77 |
filterable |
|
78 |
placeholder="请选择串口" |
|
79 |
:disabled="isDisable" |
|
80 |
> |
|
81 |
<el-option |
|
82 |
v-for="item in portsList" |
|
83 |
:key="item.value" |
|
84 |
:label="item.label" |
|
85 |
:value="item.value" |
|
86 |
> |
|
87 |
</el-option> |
|
88 |
</el-select> |
|
89 |
</el-form-item> |
|
90 |
<el-form-item label="波特率"> |
|
91 |
<el-autocomplete |
|
92 |
popper-class="my-autocomplete" |
|
93 |
v-model="form1.baudRate" |
|
94 |
:fetch-suggestions="querySearch" |
|
95 |
placeholder="请输入波特率" |
|
96 |
:disabled="isDisable" |
|
97 |
> |
|
98 |
<i class="el-icon-edit el-input__icon" slot="suffix"> </i> |
|
99 |
<template slot-scope="{ item }"> |
|
100 |
<div class="name">{{ item.value }}</div> |
|
101 |
<span class="addr">{{ item.address }}</span> |
|
102 |
</template> |
|
103 |
</el-autocomplete> |
|
104 |
</el-form-item> |
|
105 |
<el-form-item label="数据位"> |
|
106 |
<el-select |
|
107 |
v-model="form1.dataBits" |
|
108 |
placeholder="请选择数据位" |
|
109 |
:disabled="isDisable" |
|
110 |
> |
|
111 |
<el-option label="7" value="7"></el-option> |
|
112 |
<el-option label="8" value="8"></el-option> |
|
113 |
</el-select> |
|
114 |
</el-form-item> |
|
115 |
<el-form-item label="停止位"> |
|
116 |
<el-select |
|
117 |
v-model="form1.stopBits" |
|
118 |
placeholder="请选择停止位" |
|
119 |
:disabled="isDisable" |
|
120 |
> |
|
121 |
<el-option label="1" value="1"></el-option> |
|
122 |
<el-option label="2" value="2"></el-option> |
|
123 |
</el-select> |
|
124 |
</el-form-item> |
|
125 |
|
|
126 |
<el-form-item label="校验位"> |
|
127 |
<el-select |
|
128 |
v-model="form1.parity" |
|
129 |
placeholder="请选择校验位" |
|
130 |
:disabled="isDisable" |
|
131 |
> |
|
132 |
<el-option label="None" value="none"></el-option> |
|
133 |
<el-option label="Even" value="even"></el-option> |
|
134 |
<el-option label="Odd" value="odd"></el-option> |
|
135 |
</el-select> |
|
136 |
</el-form-item> |
|
137 |
|
|
138 |
<el-form-item label="流控制"> |
|
139 |
<el-select |
|
140 |
v-model="form1.flowControl" |
|
141 |
placeholder="请选择流控制" |
|
142 |
:disabled="isDisable" |
|
143 |
> |
|
144 |
<el-option label="None" value="none"></el-option> |
|
145 |
<el-option label="HardWare" value="hardware"></el-option> |
|
146 |
</el-select> |
|
147 |
</el-form-item> |
|
148 |
<el-form-item label="显示历史"> |
|
149 |
<el-switch |
|
150 |
v-model="form1.isShowHistory" |
|
151 |
@change="loadHistory" |
|
152 |
></el-switch> |
|
153 |
<el-button |
|
154 |
type="danger" |
|
155 |
icon="el-icon-delete" |
|
156 |
circle |
|
157 |
title="清空历史" |
|
158 |
@click="clearHistory" |
|
159 |
></el-button> |
|
160 |
</el-form-item> |
|
161 |
<el-form-item label="发送区设置" v-show="isShowSendArea"> |
|
162 |
<el-form-item label="发送格式"> |
|
163 |
<el-radio-group v-model="form1.type"> |
|
164 |
<el-radio label="1">ASCII</el-radio> |
|
165 |
<el-radio label="2">HEX</el-radio> |
|
166 |
</el-radio-group> |
|
167 |
</el-form-item> |
|
168 |
<el-form-item label="发送信息"> |
|
169 |
<el-input type="textarea" v-model="form1.sendMsg"></el-input> |
|
170 |
</el-form-item> |
|
171 |
<el-button type="primary" @click="sendCommon">发送</el-button> |
|
172 |
</el-form-item> |
|
173 |
|
|
174 |
<el-form-item> |
|
175 |
<el-button :type="btnType" @click="connectBtn">{{ |
|
176 |
btnText |
|
177 |
}}</el-button> |
|
178 |
<el-button type="info" @click="obtainAuthorization" |
|
179 |
>新增授权</el-button |
|
180 |
> |
|
181 |
</el-form-item> |
|
182 |
</div> |
|
183 |
</el-col> |
|
184 |
</el-row> |
|
185 |
</el-form> |
|
186 |
</el-dialog> |
|
187 |
</div> |
|
188 |
</template> |
|
189 |
<script> |
6a462f
|
190 |
import {getIpv4, listStationConf} from "@/api/main/sc/stationConf"; |
2c7661
|
191 |
import { |
A |
192 |
noPageListFormulaChild, |
6a462f
|
193 |
workpieceRelease, |
W |
194 |
yzUpdateResults, |
|
195 |
yzUpdateTighteningFormula |
2c7661
|
196 |
} from "@/api/main/bs/formulaChild/formulaChild"; |
A |
197 |
import MySerialPort from "@/utils/MySerialPort"; |
|
198 |
import USBDevice from "@/utils/usb.json"; |
|
199 |
import {addPassingStationCollection} from "@/api/main/da/passingStationCollection/passingStationCollection"; |
|
200 |
import { |
|
201 |
addTighteningParameters, |
6a462f
|
202 |
replaceAssemblyCode, |
2c7661
|
203 |
saveCampaignTimeParameters, |
6a462f
|
204 |
yzAddBasicParameters, |
2c7661
|
205 |
} from "@/api/main/da/paramCollection/paramCollection"; |
A |
206 |
|
|
207 |
export default { |
|
208 |
name: "stationTerminal", |
|
209 |
data() { |
|
210 |
return { |
|
211 |
showInput: true, |
|
212 |
serialPortContent: '', |
|
213 |
// 查询参数 |
|
214 |
formulaChildParams: { |
|
215 |
pageNum: 1, |
|
216 |
pageSize: 10, |
|
217 |
productCode: null, |
|
218 |
processesCode: null, |
|
219 |
}, |
|
220 |
// 配方配置子信息表格数据 |
|
221 |
formulaChildList: [], |
|
222 |
ipAddress: '', |
|
223 |
imgSrc: '', |
|
224 |
headContent: { |
|
225 |
processesCode: 'OP1010', |
|
226 |
processesName: '贴标机-贴码', |
|
227 |
sfcCode: '', |
|
228 |
yzSfcCode: '', |
|
229 |
}, |
|
230 |
workpieceInformation: { |
|
231 |
workOrderNo: null, |
|
232 |
productCode: null, |
|
233 |
productModel: null, |
|
234 |
productName: null, |
|
235 |
beat: null, |
|
236 |
}, |
|
237 |
// 查询参数 |
|
238 |
queryParams: { |
|
239 |
pageNum: 1, |
|
240 |
pageSize: 10, |
|
241 |
sfcCode: null, |
|
242 |
}, |
|
243 |
// 查询参数 |
|
244 |
StationConfQueryParams: { |
|
245 |
pageNum: 1, |
|
246 |
pageSize: 10, |
|
247 |
ipAddress: null, |
|
248 |
}, |
|
249 |
cakeLamp: { |
|
250 |
plcState: 1, //plc |
|
251 |
scannerState: 1, //扫码枪 |
|
252 |
InPlace: 0, //工件到位 |
|
253 |
scanFinish: 0, |
|
254 |
startWork: 0, |
|
255 |
release: 0 //允许放行 |
|
256 |
}, |
|
257 |
content: '', |
|
258 |
activeName: 'first', |
4a5f2a
|
259 |
url: "ws://192.168.2.76:8080/websocket/message/", |
2c7661
|
260 |
message: "", |
A |
261 |
text_content: "", |
|
262 |
ws: null, |
|
263 |
inputValue: '9', |
|
264 |
|
|
265 |
open1: false, |
|
266 |
input: "", |
|
267 |
keepReading: true, |
|
268 |
form1: { |
|
269 |
baudRate: "115200", |
|
270 |
dataBits: "8", |
|
271 |
stopBits: "1", |
|
272 |
parity: "none", |
|
273 |
flowControl: "none", |
|
274 |
desc: "", |
|
275 |
type: "1", |
|
276 |
isShowHistory: false, |
|
277 |
}, |
|
278 |
btnType: "primary", |
|
279 |
btnText: "连接串口", |
|
280 |
restaurants: [], |
|
281 |
portsList: [], |
|
282 |
isShowSendArea: false, |
|
283 |
readType: 1, |
|
284 |
title: "", |
|
285 |
|
|
286 |
passingStationForm: {}, |
|
287 |
originalArray: [], |
|
288 |
} |
|
289 |
}, |
|
290 |
beforeDestroy() { |
|
291 |
this.exit(); |
|
292 |
}, |
|
293 |
created() { |
|
294 |
this.initStation(); |
|
295 |
// this.getStationConfList(); |
|
296 |
// setTimeout(() => { |
|
297 |
// this.connectWebsocket(); |
|
298 |
// }, 3000); |
|
299 |
}, |
|
300 |
mounted() { |
|
301 |
if ("serial" in navigator) { |
|
302 |
this.myserialport = new MySerialPort(); |
|
303 |
this.getPorts(); |
|
304 |
navigator.serial.addEventListener("connect", (e) => { |
|
305 |
this.$message.success("设备已连接"); |
|
306 |
this.getPorts(); |
|
307 |
}); |
|
308 |
navigator.serial.addEventListener("disconnect", (e) => { |
|
309 |
this.$message.error("设备已断开"); |
|
310 |
}); |
|
311 |
this.restaurants = this.loadAll(); |
|
312 |
} else { |
|
313 |
this.$message.error( |
|
314 |
"当前为HTTP模式或者浏览器版本过低,不支持网页连接串口" |
|
315 |
); |
|
316 |
} |
|
317 |
}, |
|
318 |
computed: { |
|
319 |
isDisable() { |
|
320 |
return this.btnType === "danger"; |
|
321 |
}, |
|
322 |
}, |
|
323 |
methods: { |
|
324 |
serialLink() { |
|
325 |
this.open1 = true |
|
326 |
}, |
|
327 |
bindYzSfc(){ |
|
328 |
if(this.headContent.sfcCode!==""&&this.headContent.yzSfcCode!==""){ |
|
329 |
let param = { |
|
330 |
sfcCode: this.headContent.sfcCode, |
|
331 |
locationCode: this.headContent.processesCode, |
|
332 |
yzSfcCode: this.headContent.yzSfcCode |
|
333 |
} |
|
334 |
this.$message('可以绑定!'); |
|
335 |
replaceAssemblyCode(param).then(response => { |
|
336 |
|
|
337 |
}); |
|
338 |
} |
|
339 |
}, |
4a5f2a
|
340 |
|
2c7661
|
341 |
Release(){ |
A |
342 |
// this.$message('portsList!'+this.portsList.length); |
|
343 |
if(this.btnType === "danger"){ |
|
344 |
this.$message('连接了!'); |
|
345 |
|
|
346 |
}else { |
|
347 |
this.$message('mei连接了!'); |
|
348 |
|
|
349 |
} |
|
350 |
|
|
351 |
}, |
|
352 |
serialPortMethod(value){ |
|
353 |
let formulaChildParams = { |
|
354 |
scanBarcode: value, |
|
355 |
sfcBarcode: this.headContent.sfcCode, |
|
356 |
workOrderNo: this.workpieceInformation.workOrderNo, |
|
357 |
productCode: "1P102S", |
|
358 |
locationCode: this.headContent.processesCode, |
|
359 |
collectionTime: new Date() |
|
360 |
} |
|
361 |
yzUpdateResults(formulaChildParams).then(response => { |
|
362 |
this.getListFormulaChild() |
|
363 |
}); |
|
364 |
}, |
|
365 |
rowStyle({ row }) { |
|
366 |
if (row.results === 'OK') { |
|
367 |
return 'background-color: PaleGreen'; |
|
368 |
} else if (row.results === 'NG') { |
|
369 |
return 'background-color: LightSalmon'; |
|
370 |
} |
|
371 |
return ''; |
|
372 |
}, |
|
373 |
/** 查询配方配置子信息列表 */ |
|
374 |
getListFormulaChild() { |
|
375 |
this.formulaChildParams.productCode = "1P102S" |
|
376 |
this.formulaChildParams.processesCode = this.headContent.processesCode |
|
377 |
console.log(this.formulaChildParams) |
|
378 |
noPageListFormulaChild(this.formulaChildParams).then(response => { |
|
379 |
this.formulaChildList = response.rows; |
6a462f
|
380 |
if (this.formulaChildList.length >0){ |
W |
381 |
let pos = 0 |
|
382 |
const tempArr = this.formulaChildList.filter(x=> 'OK' === x.results) |
|
383 |
if (tempArr.length>0){ |
|
384 |
pos = tempArr.length |
|
385 |
this.$nextTick(() => { |
|
386 |
let temp33 = document.getElementsByClassName('el-table__row') |
|
387 |
console.log('temp33',temp33) |
|
388 |
console.log('len',temp33.item(pos)) |
|
389 |
if (temp33.length > 0){ |
|
390 |
console.log('1111111111111111') |
|
391 |
let arr = temp33[pos-1] |
|
392 |
console.log('srr',arr) |
|
393 |
arr.scrollIntoView({ block: 'center' }) |
|
394 |
} |
|
395 |
}) |
|
396 |
} |
|
397 |
|
|
398 |
} |
2c7661
|
399 |
}); |
A |
400 |
}, |
|
401 |
endClear(){ |
|
402 |
|
|
403 |
}, |
|
404 |
changeMenu(tab, event) { |
|
405 |
console.log(tab, event); |
|
406 |
}, |
|
407 |
clearClick(){ |
|
408 |
this.$message('这是一条清除消息提示'); |
|
409 |
this.headContent.sfcCode = null |
|
410 |
}, |
|
411 |
scanCompleted(){ |
|
412 |
this.$message('扫码完成'+this.content); |
|
413 |
this.headContent.sfcCode = this.content |
|
414 |
this.queryParams.sfcCode = this.content |
|
415 |
this.getList() |
|
416 |
this.getListFormulaChild() |
|
417 |
this.cakeLamp.scanFinish = 1 |
|
418 |
this.cakeLamp.startWork = 1 |
|
419 |
|
|
420 |
}, |
|
421 |
/** 查询工单列表 */ |
|
422 |
async getList() { |
|
423 |
this.getListFormulaChild() |
4a5f2a
|
424 |
this.addOverStationCollection() |
2c7661
|
425 |
}, |
A |
426 |
|
|
427 |
/** 入站增加过站采集记录 **/ |
|
428 |
addOverStationCollection(){ |
|
429 |
this.passingStationForm = { |
|
430 |
id: null, |
4a5f2a
|
431 |
// workOrderNo: this.workpieceInformation.workOrderNo, |
A |
432 |
productCode: "1P102S", |
2c7661
|
433 |
locationCode: this.headContent.processesCode, |
4a5f2a
|
434 |
// model: this.workpieceInformation.productModel, |
2c7661
|
435 |
productBarcode: this.headContent.sfcCode, |
A |
436 |
sfcCode: this.headContent.sfcCode, |
|
437 |
inboundTime: new Date() |
|
438 |
} |
|
439 |
addPassingStationCollection(this.passingStationForm).then(response => {}); |
4a5f2a
|
440 |
yzAddBasicParameters(this.passingStationForm).then(response => {}); |
2c7661
|
441 |
}, |
A |
442 |
exit() { |
|
443 |
if (this.ws) { |
|
444 |
this.ws.close(); |
|
445 |
this.ws = null; |
|
446 |
} |
|
447 |
}, |
|
448 |
send() { |
|
449 |
if (this.ws) { |
|
450 |
this.ws.send(this.message); |
|
451 |
} else { |
|
452 |
alert("未连接到服务器"); |
|
453 |
} |
|
454 |
}, |
|
455 |
|
|
456 |
initStation: async function () { |
|
457 |
await getIpv4().then(response => { |
|
458 |
this.StationConfQueryParams.ipAddress = response.msg |
|
459 |
console.log('查询到本工位IP为' + this.StationConfQueryParams.ipAddress) |
|
460 |
}); |
|
461 |
await listStationConf(this.StationConfQueryParams).then(response => { |
|
462 |
let rows = response.rows[0] |
|
463 |
if (response.rows.length === 0) { |
|
464 |
this.$message('该工位没有配置IP,请联系管理员配置IP'); |
|
465 |
return |
|
466 |
} |
|
467 |
this.headContent.processesName = rows.processesName |
|
468 |
this.headContent.processesCode = rows.processesCode |
|
469 |
console.log('设置工位编码' + this.headContent.processesCode) |
|
470 |
|
|
471 |
}); |
|
472 |
this.conCom() |
|
473 |
console.log('websocket连接工位为' + this.headContent.processesCode) |
|
474 |
const wsuri = this.url + this.headContent.processesCode; |
|
475 |
this.ws = new WebSocket(wsuri); |
|
476 |
const self = this; |
|
477 |
this.ws.onopen = function (event) { |
|
478 |
this.$message('websocket连接成功!'); |
|
479 |
}; |
|
480 |
this.ws.onmessage = function (event) { |
|
481 |
if (event.data === "IN") { |
|
482 |
self.cakeLamp.InPlace = 1; |
|
483 |
} else if (event.data === "IN0") { |
|
484 |
self.cakeLamp.InPlace = 0; |
|
485 |
} else if (event.data === "OUT") { |
|
486 |
console.log("out") |
|
487 |
|
|
488 |
const param = { |
|
489 |
workOrderNo: self.workpieceInformation.workOrderNo, |
|
490 |
productCode: "1P102S", |
|
491 |
locationCode: self.headContent.processesCode, |
|
492 |
productBarcode: self.headContent.sfcCode, |
|
493 |
} |
|
494 |
// saveCampaignTimeParameters(param).then(response => {}); |
|
495 |
// self.cakeLamp.release = 1; |
|
496 |
workpieceRelease(param).then(response => {}); |
|
497 |
self.formulaChildList = []; |
|
498 |
self.headContent.sfcCode = ''; |
|
499 |
console.log(self.formulaChildList) |
|
500 |
} else if (event.data === "END") { |
|
501 |
// const param = { |
|
502 |
// workOrderNo: self.workpieceInformation.workOrderNo, |
|
503 |
// productCode: self.workpieceInformation.productCode, |
|
504 |
// locationCode: self.headContent.processesCode, |
|
505 |
// productBarcode: self.headContent.sfcCode, |
|
506 |
// } |
|
507 |
// saveCampaignTimeParameters(param).then(response => {}); |
|
508 |
// self.endClear() |
|
509 |
// workpieceRelease(param).then(response => {}); |
|
510 |
} else if (event.data.includes("[")) { |
|
511 |
let formulaChilds = ""; |
|
512 |
self.formulaChildList.sort((a, b) => a.stepSort - b.stepSort); |
|
513 |
self.formulaChildList |
|
514 |
.filter((formulaChild) => formulaChild.operationType === '1'); |
|
515 |
for (let i = 0; i < self.formulaChildList.length; i++) { |
|
516 |
let formulaChild = self.formulaChildList[i]; |
|
517 |
let results = formulaChild.results; |
|
518 |
if (results === '' || results === null || results === 'NG') { |
|
519 |
formulaChilds = formulaChild; |
|
520 |
break; |
|
521 |
} |
|
522 |
} |
|
523 |
const param = { |
|
524 |
tightenTheArray: event.data, |
|
525 |
paramCode: formulaChilds.paramCode, |
4a5f2a
|
526 |
// workOrderNo: self.workpieceInformation.workOrderNo, |
A |
527 |
productCode: "1P102S", |
2c7661
|
528 |
locationCode: self.headContent.processesCode, |
A |
529 |
productBarcode: self.headContent.sfcCode, |
|
530 |
} |
|
531 |
addTighteningParameters(param).then(response => {}); |
|
532 |
yzUpdateTighteningFormula(param).then(response => { |
|
533 |
console.log(response.msg) |
|
534 |
if(response.msg === "1"){ |
|
535 |
self.getListFormulaChild() |
|
536 |
|
|
537 |
}else { |
|
538 |
const param = { |
|
539 |
workOrderNo: self.workpieceInformation.workOrderNo, |
|
540 |
productCode: "1P102S", |
|
541 |
locationCode: self.headContent.processesCode, |
|
542 |
productBarcode: self.headContent.sfcCode, |
|
543 |
} |
|
544 |
saveCampaignTimeParameters(param).then(response => {}); |
|
545 |
workpieceRelease(param).then(response => {}); |
|
546 |
self.formulaChildList = []; |
|
547 |
self.headContent.sfcCode = ''; |
|
548 |
} |
|
549 |
}); |
|
550 |
} |
|
551 |
}; |
|
552 |
}, |
|
553 |
|
|
554 |
|
|
555 |
|
|
556 |
//接受数据的回调 |
|
557 |
callBack(value) { |
|
558 |
if (this.form1.isShowHistory) this.form1.desc = this.readLi().join(""); |
|
559 |
else { |
|
560 |
const scanValue = this.myserialport.hex2atostr(value).replace(/[\r\n]/g, ''); |
|
561 |
console.log("串口收到数据-------------------"+scanValue) |
|
562 |
|
|
563 |
if(this.headContent.sfcCode !== ''){ |
|
564 |
this.$message('扫描物料编码'+scanValue); |
|
565 |
console.log(scanValue) |
|
566 |
this.serialPortMethod(scanValue) |
|
567 |
} else { |
|
568 |
this.headContent.sfcCode = scanValue; |
|
569 |
this.getList() |
|
570 |
} |
|
571 |
|
|
572 |
} |
|
573 |
}, |
|
574 |
clearHistory() { |
|
575 |
this.form1.desc = ""; |
|
576 |
this.myserialport.state.readValue = []; |
|
577 |
}, |
|
578 |
loadHistory() { |
|
579 |
if (this.form1.isShowHistory) this.form1.desc = this.readLi().join(""); |
|
580 |
else { |
|
581 |
let temp = this.readLi(); |
|
582 |
if (temp.length > 0) this.form1.desc = temp[temp.length - 1].join(""); |
|
583 |
} |
|
584 |
}, |
|
585 |
readLi() { |
|
586 |
let readType = this.readType; |
|
587 |
return this.myserialport.state.readValue.map((items, index) => { |
|
588 |
const item = items.value; |
|
589 |
const type = items.type; // 1接收,2发送 |
|
590 |
let body = []; |
|
591 |
if (item !== undefined) { |
|
592 |
let strArr = []; |
|
593 |
for (let hex of Array.from(item)) { |
|
594 |
strArr.push(hex.toString(16).toLocaleUpperCase()); |
|
595 |
} |
|
596 |
if (strArr.includes("D") && strArr.includes("A")) { |
|
597 |
if (strArr.indexOf("A") - strArr.indexOf("D") === 1) { |
|
598 |
strArr.splice(strArr.indexOf("D"), 1); |
|
599 |
strArr.splice(strArr.indexOf("A"), 1, <br key={0} />); |
|
600 |
} |
|
601 |
} |
|
602 |
strArr = strArr.map((item) => { |
|
603 |
if (typeof item === "string") { |
|
604 |
if (readType === 1) { |
|
605 |
return this.myserialport.hex2a(parseInt(item, 16)); |
|
606 |
} else if (readType === 2) { |
|
607 |
return item + " "; |
|
608 |
} |
|
609 |
} |
|
610 |
return item; |
|
611 |
}); |
|
612 |
if (typeof strArr[strArr.length - 1] === "string") { |
|
613 |
strArr.push("\r\n"); |
|
614 |
} |
|
615 |
body.push(strArr.join("")); |
|
616 |
} |
|
617 |
return body; |
|
618 |
}); |
|
619 |
}, |
|
620 |
conCom(){ |
|
621 |
try { |
|
622 |
this.myserialport.state.baudRate = this.form1.baudRate; |
|
623 |
this.myserialport.state.dataBits = this.form1.dataBits; |
|
624 |
this.myserialport.state.stopBits = this.form1.stopBits; |
|
625 |
this.myserialport.state.parity = this.form1.parity; |
|
626 |
this.myserialport.state.flowControl = this.form1.flowControl; |
|
627 |
this.myserialport.openPort(0, true, this.callBack); |
|
628 |
console.log(this.form1.port) |
|
629 |
} catch (error) { |
|
630 |
this.$message.error("串口连接失败!请检查串口是否已被占用"); |
|
631 |
} |
|
632 |
if (this.myserialport.state.isOpen) { |
|
633 |
this.$message.success("串口连接成功"); |
|
634 |
} |
|
635 |
}, |
|
636 |
//连接 |
|
637 |
async connectBtn() { |
|
638 |
if (this.btnType === "primary") { |
|
639 |
try { |
|
640 |
this.myserialport.state.baudRate = this.form1.baudRate; |
|
641 |
this.myserialport.state.dataBits = this.form1.dataBits; |
|
642 |
this.myserialport.state.stopBits = this.form1.stopBits; |
|
643 |
this.myserialport.state.parity = this.form1.parity; |
|
644 |
this.myserialport.state.flowControl = this.form1.flowControl; |
|
645 |
await this.myserialport.openPort(this.form1.port, true, this.callBack); |
|
646 |
console.log(this.form1.port) |
|
647 |
} catch (error) { |
|
648 |
this.$message.error("串口连接失败!请检查串口是否已被占用"); |
|
649 |
} |
|
650 |
if (this.myserialport.state.isOpen) { |
|
651 |
this.$message.success("串口连接成功"); |
|
652 |
this.open1 = false |
|
653 |
this.btnType = "danger"; |
|
654 |
this.btnText = "关闭串口"; |
|
655 |
} |
|
656 |
} else { |
|
657 |
this.myserialport.openPort(this.form1.port, false, this.callBack); |
|
658 |
this.$message.success("串口关闭成功"); |
|
659 |
this.btnType = "primary"; |
|
660 |
this.btnText = "连接串口"; |
|
661 |
} |
|
662 |
}, |
|
663 |
//授权 |
|
664 |
async obtainAuthorization() { |
|
665 |
if ("serial" in navigator) { |
|
666 |
console.log("The Web Serial API is supported."); |
|
667 |
if (!this.myserialport) this.myserialport = new MySerialPort(); |
|
668 |
try { |
|
669 |
await this.myserialport.handleRequestPort(); |
|
670 |
this.$message.success("串口授权成功"); |
|
671 |
this.getPortInfo(this.myserialport.state.ports); |
|
672 |
} catch (error) { |
|
673 |
this.$message.warning("未选择新串口授权!"); |
|
674 |
} |
|
675 |
} else { |
|
676 |
this.$message.error( |
|
677 |
"当前为HTTP模式或者浏览器版本过低,不支持网页连接串口" |
|
678 |
); |
|
679 |
} |
|
680 |
}, |
|
681 |
//串口列表初始化 |
|
682 |
getPortInfo(portList) { |
|
683 |
this.portsList = []; |
|
684 |
portList.map((port, index) => { |
|
685 |
const { usbProductId, usbVendorId } = port.getInfo(); |
|
686 |
if (usbProductId === undefined || usbVendorId === undefined) { |
|
687 |
this.portsList.push({ label: "未知设备" + index, value: index }); |
|
688 |
} else { |
|
689 |
const usbVendor = USBDevice.filter( |
|
690 |
(item) => parseInt(item.vendor, 16) === usbVendorId |
|
691 |
); |
|
692 |
let usbProduct = []; |
|
693 |
if (usbVendor.length === 1) { |
|
694 |
usbProduct = usbVendor[0].devices.filter( |
|
695 |
(item) => parseInt(item.devid, 16) === usbProductId |
|
696 |
); |
|
697 |
} |
|
698 |
this.portsList.push({ label: usbProduct[0].devname, value: index }); |
|
699 |
} |
|
700 |
}); |
|
701 |
}, |
|
702 |
// 发送 |
|
703 |
async sendCommon() { |
|
704 |
if (this.myserialport.state.isOpen) { |
|
705 |
if (this.form1.sendMsg.length !== 0) { |
|
706 |
const writeType = this.form1.type; |
|
707 |
let value = this.form1.sendMsg; |
|
708 |
let arr = []; |
|
709 |
if (writeType === 1) { |
|
710 |
// ASCII |
|
711 |
for (let i = 0; i < value.length; i++) { |
|
712 |
arr.push(this.myserialport.a2hex(value[i])); |
|
713 |
} |
|
714 |
} else if (writeType === 2) { |
|
715 |
// HEX |
|
716 |
if (/^[0-9A-Fa-f]+$/.test(value) && value.length % 2 === 0) { |
|
717 |
for (let i = 0; i < value.length; i = i + 2) { |
|
718 |
arr.push(parseInt(value.substring(i, i + 2), 16)); |
|
719 |
} |
|
720 |
} else { |
|
721 |
this.$message.error("格式错误"); |
|
722 |
return; |
|
723 |
} |
|
724 |
} |
|
725 |
this.myserialport.writeText(arr); |
|
726 |
} else { |
|
727 |
this.$message.warning("请输入发送的信息"); |
|
728 |
} |
|
729 |
} else { |
|
730 |
this.$message.warning("串口处于关闭状态,请连接串口"); |
|
731 |
} |
|
732 |
}, |
|
733 |
async getPorts() { |
|
734 |
await this.myserialport.getPorts(); |
|
735 |
this.getPortInfo(this.myserialport.state.ports); |
|
736 |
}, |
|
737 |
querySearch(queryString, cb) { |
|
738 |
var restaurants = this.restaurants; |
|
739 |
var results = queryString |
|
740 |
? restaurants.filter(this.createFilter(queryString)) |
|
741 |
: restaurants; |
|
742 |
// 调用 callback 返回建议列表的数据 |
|
743 |
cb(results); |
|
744 |
}, |
|
745 |
createFilter(queryString) { |
|
746 |
return (restaurant) => { |
|
747 |
return ( |
|
748 |
restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === |
|
749 |
0 |
|
750 |
); |
|
751 |
}; |
|
752 |
}, |
|
753 |
loadAll() { |
|
754 |
return [ |
|
755 |
{ value: "110" }, |
|
756 |
{ value: "300" }, |
|
757 |
{ value: "600" }, |
|
758 |
{ value: "1200" }, |
|
759 |
{ value: "2400" }, |
|
760 |
{ value: "4800" }, |
|
761 |
{ value: "7200" }, |
|
762 |
{ value: "9600" }, |
|
763 |
{ value: "14400" }, |
|
764 |
{ value: "19200" }, |
|
765 |
{ value: "28800" }, |
|
766 |
{ value: "38400" }, |
|
767 |
{ value: "56000" }, |
|
768 |
{ value: "57600" }, |
|
769 |
{ value: "76800" }, |
|
770 |
{ value: "115200" }, |
|
771 |
{ value: "230400" }, |
|
772 |
{ value: "460800" }, |
|
773 |
]; |
|
774 |
}, |
|
775 |
} |
|
776 |
} |
|
777 |
|
|
778 |
</script> |
|
779 |
<style scoped> |
|
780 |
.bottom-card{ |
|
781 |
height: 600px; |
|
782 |
} |
|
783 |
.circle-button{ |
|
784 |
height: 30px; |
|
785 |
width: 30px; |
|
786 |
} |
|
787 |
.circle-red { |
|
788 |
background-color: #e01a4f; |
|
789 |
} |
|
790 |
.circle-green { |
|
791 |
background-color: green; |
|
792 |
} |
|
793 |
.circle-green-animate { |
|
794 |
background-color: green; |
|
795 |
animation: circle-green-animate 2s infinite; |
|
796 |
} |
|
797 |
@keyframes circle-green-animate { |
|
798 |
50% { |
|
799 |
opacity: 0.6; |
|
800 |
} |
|
801 |
0% { |
|
802 |
opacity: 0.2; |
|
803 |
} |
|
804 |
} |
|
805 |
.head-font{ |
|
806 |
/*font-weight: bold;*/ |
|
807 |
/*font-size: 25px;*/ |
|
808 |
} |
|
809 |
span{ |
|
810 |
font-size: 15px; |
|
811 |
} |
|
812 |
.el-table .warning-row { |
|
813 |
background: oldlace; |
|
814 |
} |
|
815 |
|
|
816 |
.el-table .success-row { |
|
817 |
background: #f0f9eb; |
|
818 |
} |
|
819 |
</style> |
|
820 |
|