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