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