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