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