admin
2024-10-15 6d313a4a6f9f9d7ea65ec50ab0d4491e595edb97
提交 | 用户 | 时间
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) {
002c0a 497         self.$message('websocket连接成功!');
2c7661 498       };
A 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,
002c0a 547                     productCode: "PE01B",
A 548                     workOrderNo: "-",
549
768498 550                   }
A 551                   preInstallOut(param).then(response => {});
552                   workpieceRelease(param).then(response => {});
553                   self.formulaChildList = [];
554                   self.headContent.sfcCode = '';
555                 }
556               });
557               addTighteningParameters(param).then(response => {});
2c7661 558             }
A 559           });
560         }
561       };
562     },
563
564
565
566     //接受数据的回调
567     callBack(value) {
568       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
569       else {
570         const scanValue = this.myserialport.hex2atostr(value).replace(/[\r\n]/g, '');
571         console.log("串口收到数据-------------------"+scanValue)
572
573         if(this.headContent.sfcCode !== ''){
a52d08 574           this.$message('预装工位扫描物料编码'+scanValue);
2c7661 575           console.log(scanValue)
A 576           this.serialPortMethod(scanValue)
577         } else {
273d64 578           if(scanValue.includes("P9900183275") || scanValue.includes("P9900173252")){
A 579             this.headContent.sfcCode = scanValue;
580             this.headContent.inboundTime = this.getCurrentTime();
581             this.getList()
582           }else {
583             this.$message.error('总成码扫描错误!');
584           }
585
2c7661 586         }
A 587
588       }
589     },
590     clearHistory() {
591       this.form1.desc = "";
592       this.myserialport.state.readValue = [];
593     },
594     loadHistory() {
595       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
596       else {
597         let temp = this.readLi();
598         if (temp.length > 0) this.form1.desc = temp[temp.length - 1].join("");
599       }
600     },
601     readLi() {
602       let readType = this.readType;
603       return this.myserialport.state.readValue.map((items, index) => {
604         const item = items.value;
605         const type = items.type; // 1接收,2发送
606         let body = [];
607         if (item !== undefined) {
608           let strArr = [];
609           for (let hex of Array.from(item)) {
610             strArr.push(hex.toString(16).toLocaleUpperCase());
611           }
612           if (strArr.includes("D") && strArr.includes("A")) {
613             if (strArr.indexOf("A") - strArr.indexOf("D") === 1) {
614               strArr.splice(strArr.indexOf("D"), 1);
615               strArr.splice(strArr.indexOf("A"), 1, <br key={0} />);
616             }
617           }
618           strArr = strArr.map((item) => {
619             if (typeof item === "string") {
620               if (readType === 1) {
621                 return this.myserialport.hex2a(parseInt(item, 16));
622               } else if (readType === 2) {
623                 return item + " ";
624               }
625             }
626             return item;
627           });
628           if (typeof strArr[strArr.length - 1] === "string") {
629             strArr.push("\r\n");
630           }
631           body.push(strArr.join(""));
632         }
633         return body;
634       });
635     },
636     conCom(){
637       try {
638         this.myserialport.state.baudRate = this.form1.baudRate;
639         this.myserialport.state.dataBits = this.form1.dataBits;
640         this.myserialport.state.stopBits = this.form1.stopBits;
641         this.myserialport.state.parity = this.form1.parity;
642         this.myserialport.state.flowControl = this.form1.flowControl;
643         this.myserialport.openPort(0, true, this.callBack);
644         console.log(this.form1.port)
645       } catch (error) {
646         this.$message.error("串口连接失败!请检查串口是否已被占用");
647       }
648       if (this.myserialport.state.isOpen) {
649         this.$message.success("串口连接成功");
650       }
651     },
652     //连接
653     async connectBtn() {
654       if (this.btnType === "primary") {
655         try {
656           this.myserialport.state.baudRate = this.form1.baudRate;
657           this.myserialport.state.dataBits = this.form1.dataBits;
658           this.myserialport.state.stopBits = this.form1.stopBits;
659           this.myserialport.state.parity = this.form1.parity;
660           this.myserialport.state.flowControl = this.form1.flowControl;
661           await this.myserialport.openPort(this.form1.port, true, this.callBack);
662           console.log(this.form1.port)
663         } catch (error) {
664           this.$message.error("串口连接失败!请检查串口是否已被占用");
665         }
666         if (this.myserialport.state.isOpen) {
667           this.$message.success("串口连接成功");
668           this.open1 = false
669           this.btnType = "danger";
670           this.btnText = "关闭串口";
671         }
672       } else {
673         this.myserialport.openPort(this.form1.port, false, this.callBack);
674         this.$message.success("串口关闭成功");
675         this.btnType = "primary";
676         this.btnText = "连接串口";
677       }
678     },
679     //授权
680     async obtainAuthorization() {
681       if ("serial" in navigator) {
682         console.log("The Web Serial API is supported.");
683         if (!this.myserialport) this.myserialport = new MySerialPort();
684         try {
685           await this.myserialport.handleRequestPort();
686           this.$message.success("串口授权成功");
687           this.getPortInfo(this.myserialport.state.ports);
688         } catch (error) {
689           this.$message.warning("未选择新串口授权!");
690         }
691       } else {
692         this.$message.error(
693           "当前为HTTP模式或者浏览器版本过低,不支持网页连接串口"
694         );
695       }
696     },
697     //串口列表初始化
698     getPortInfo(portList) {
699       this.portsList = [];
700       portList.map((port, index) => {
701         const { usbProductId, usbVendorId } = port.getInfo();
702         if (usbProductId === undefined || usbVendorId === undefined) {
703           this.portsList.push({ label: "未知设备" + index, value: index });
704         } else {
705           const usbVendor = USBDevice.filter(
706             (item) => parseInt(item.vendor, 16) === usbVendorId
707           );
708           let usbProduct = [];
709           if (usbVendor.length === 1) {
710             usbProduct = usbVendor[0].devices.filter(
711               (item) => parseInt(item.devid, 16) === usbProductId
712             );
713           }
714           this.portsList.push({ label: usbProduct[0].devname, value: index });
715         }
716       });
717     },
718     // 发送
719     async sendCommon() {
720       if (this.myserialport.state.isOpen) {
721         if (this.form1.sendMsg.length !== 0) {
722           const writeType = this.form1.type;
723           let value = this.form1.sendMsg;
724           let arr = [];
725           if (writeType === 1) {
726             // ASCII
727             for (let i = 0; i < value.length; i++) {
728               arr.push(this.myserialport.a2hex(value[i]));
729             }
730           } else if (writeType === 2) {
731             // HEX
732             if (/^[0-9A-Fa-f]+$/.test(value) && value.length % 2 === 0) {
733               for (let i = 0; i < value.length; i = i + 2) {
734                 arr.push(parseInt(value.substring(i, i + 2), 16));
735               }
736             } else {
737               this.$message.error("格式错误");
738               return;
739             }
740           }
741           this.myserialport.writeText(arr);
742         } else {
743           this.$message.warning("请输入发送的信息");
744         }
745       } else {
746         this.$message.warning("串口处于关闭状态,请连接串口");
747       }
748     },
749     async getPorts() {
750       await this.myserialport.getPorts();
751       this.getPortInfo(this.myserialport.state.ports);
752     },
753     querySearch(queryString, cb) {
754       var restaurants = this.restaurants;
755       var results = queryString
756         ? restaurants.filter(this.createFilter(queryString))
757         : restaurants;
758       // 调用 callback 返回建议列表的数据
759       cb(results);
760     },
761     createFilter(queryString) {
762       return (restaurant) => {
763         return (
764           restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
765           0
766         );
767       };
768     },
769     loadAll() {
770       return [
771         { value: "110" },
772         { value: "300" },
773         { value: "600" },
774         { value: "1200" },
775         { value: "2400" },
776         { value: "4800" },
777         { value: "7200" },
778         { value: "9600" },
779         { value: "14400" },
780         { value: "19200" },
781         { value: "28800" },
782         { value: "38400" },
783         { value: "56000" },
784         { value: "57600" },
785         { value: "76800" },
786         { value: "115200" },
787         { value: "230400" },
788         { value: "460800" },
789       ];
790     },
791   }
792 }
793
794 </script>
795 <style scoped>
796 .bottom-card{
797   height: 600px;
798 }
799 .circle-button{
800   height: 30px;
801   width: 30px;
802 }
803 .circle-red {
804   background-color: #e01a4f;
805 }
806 .circle-green {
807   background-color: green;
808 }
809 .circle-green-animate {
810   background-color: green;
811   animation: circle-green-animate 2s infinite;
812 }
813   @keyframes circle-green-animate {
814     50% {
815       opacity: 0.6;
816     }
817     0% {
818       opacity: 0.2;
819     }
820   }
821 .head-font{
822   /*font-weight: bold;*/
823   /*font-size: 25px;*/
824 }
825 span{
826   font-size: 15px;
827 }
828 .el-table .warning-row {
829   background: oldlace;
830 }
831
832 .el-table .success-row {
833   background: #f0f9eb;
834 }
835 </style>
836