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