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