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