wujian
2024-05-13 6a462fcca2e65cc3a38ed79522d966306756341f
提交 | 用户 | 时间
06713a 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>
1c84ae 9      <el-col :span="17">
06713a 10        <el-card shadow="never">
A 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>
1c84ae 16 <!--     <el-col :span="10">-->
A 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>-->
06713a 25
A 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,
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,
1c84ae 273   replaceAssemblyCode, jrmSaveCampaignTimeParameters,
06713a 274 } from "@/api/main/da/paramCollection/paramCollection";
A 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',
334       url: "ws://192.168.2.76:8080/websocket/message/",
335       message: "",
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     bindYzSfc(){
413       if(this.headContent.sfcCode!==""&&this.headContent.yzSfcCode!==""){
414         let param = {
415           sfcCode: this.headContent.sfcCode,
416           locationCode: this.headContent.processesCode,
417           yzSfcCode: this.headContent.yzSfcCode
418         }
419         this.$message('可以绑定!');
420         replaceAssemblyCode(param).then(response => {
421
422         });
423       }
424     },
425     Release(){
426       // this.$message('portsList!'+this.portsList.length);
427       if(this.btnType === "danger"){
428         this.$message('连接了!');
429
430       }else {
431         this.$message('mei连接了!');
432
433       }
434     },
435     serialPortMethod(value){
436       let formulaChildParams = {
437         scanBarcode: value,
438         sfcBarcode: this.headContent.moduleA+','+this.headContent.moduleB,
439         // workOrderNo: this.workpieceInformation.workOrderNo,
440         productCode: '1P102S',
441         locationCode: this.headContent.processesCode,
442         collectionTime: new Date()
443       }
444       jrmUpdateResults(formulaChildParams).then(response => {
445         console.log(response)
446         if(response.msg === "3"){
447           this.cakeLamp.release= 1 //允许放行
448         }
449         this.getListFormulaChild()
450       });
451     },
452     rowStyle({ row }) {
453       if (row.results === 'OK') {
454         return 'background-color: PaleGreen';
455       } else if (row.results === 'NG') {
456         return 'background-color: LightSalmon';
457       }
458       return '';
459     },
6a462f 460     getElement() {
W 461       let temp33 = document.getElementsByClassName('el-table__row')
462       console.log('temp33',temp33)
463       console.log('len',temp33.item(12))
464       if (temp33.length > 0){
465         console.log('1111111111111111')
466         let arr = temp33[12]
467         console.log('srr',arr)
468         arr.scrollIntoView({ block: 'center' })
469       }
470     },
06713a 471     /** 查询配方配置子信息列表 */
A 472     getListFormulaChild() {
1c84ae 473       console.log('getListFormulaChild')
06713a 474       // this.formulaChildList = []
A 475       this.formulaChildParams.productCode = '1P102S'
476       this.formulaChildParams.processesCode = this.headContent.processesCode
477       console.log(this.formulaChildParams)
478       noPageListFormulaChild(this.formulaChildParams).then(response => {
479         this.formulaChildList = response.rows;
6a462f 480         if (this.formulaChildList.length >0){
W 481           let pos = 0
482           const tempArr = this.formulaChildList.filter(x=> 'OK' === x.results)
483           if (tempArr.length>0){
484             pos = tempArr.length
485             this.$nextTick(() => {
486               let temp33 = document.getElementsByClassName('el-table__row')
487               console.log('temp33',temp33)
488               console.log('len',temp33.item(pos))
489               if (temp33.length > 0){
490                 console.log('1111111111111111')
491                 let arr = temp33[pos-1]
492                 console.log('srr',arr)
493                 arr.scrollIntoView({ block: 'center' })
494               }
495             })
496           }
497
498         }
499
06713a 500       });
A 501     },
502     endClear(){
503       this.cakeLamp.InPlace= 0 //工件到位
504       this.cakeLamp.scanFinish= 0
505       this.cakeLamp.startWork= 0
506       this.cakeLamp.release= 0 //允许放行
507
508       this.formulaChildList = []
509       this.workpieceInformation.productCode = null;
510       this.workpieceInformation.workOrderNo = null;
511       this.workpieceInformation.productModel = null;
512       this.workpieceInformation.productName = null;
513       this.headContent.sfcCode = '';
514     },
515     changeMenu(tab, event) {
516       console.log(tab, event);
517     },
518     clearClick(){
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(){
1c84ae 540       console.log('addOverStationCollection')
06713a 541       this.passingStationForm = {
A 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: self.workpieceInformation.productCode,
609             locationCode: self.headContent.processesCode,
610             productBarcode: self.headContent.sfcCode,
611           }
1c84ae 612           jrmSaveCampaignTimeParameters(param).then(response => {});
06713a 613           self.cakeLamp.release = 1;
A 614           self.endClear()
615           workpieceRelease(param).then(response => {});
616         } else if (event.data.includes("[")) {
617           let formulaChilds = "";
618           self.formulaChildList.sort((a, b) => a.stepSort - b.stepSort);
619           self.formulaChildList
620             .filter((formulaChild) => formulaChild.operationType === '1');
621           for (let i = 0; i < self.formulaChildList.length; i++) {
622             let formulaChild = self.formulaChildList[i];
623             let results = formulaChild.results;
624             if (results === '' || results === null || results === 'NG') {
625               formulaChilds = formulaChild;
626               break;
627             }
628           }
629           const param = {
630             tightenTheArray: event.data,
631             paramCode: formulaChilds.paramCode,
1c84ae 632             // workOrderNo: self.workpieceInformation.workOrderNo,
A 633             productCode: '1P102S',
06713a 634             locationCode: self.headContent.processesCode,
A 635             productBarcode: self.headContent.sfcCode,
636           }
637           addTighteningParameters(param).then(response => {});
638           updateTighteningFormula(param).then(response => {
639             self.getListFormulaChild()
640           }).catch(error =>{
641             self.getListFormulaChild()
642           });
643         }
644       };
645     },
646
647
648
649     //接受数据的回调
650     callBack(value) {
651       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
652       else {
653         const scanValue = this.myserialport.hex2atostr(value).replace(/[\r\n]/g, '');
654         console.log("串口收到数据-------------------"+scanValue)
655
656         if(this.headContent.moduleA !== '' && this.headContent.moduleB !== '' ){
657           this.serialPortMethod(scanValue)
658         } else {
659           if(scanValue.includes("9900168135")){
660             this.headContent.moduleA = scanValue;
661           }
662           if(scanValue.includes("9900168136")){
663             this.headContent.moduleB = scanValue;
664             this.$message('扫码识别产品序列号'+scanValue);
665             this.getList()
666             this.cakeLamp.InPlace = 1
667             this.cakeLamp.scanFinish = 1
668             this.cakeLamp.startWork = 1
669           }
670         }
671       }
672     },
673     clearHistory() {
674       this.form1.desc = "";
675       this.myserialport.state.readValue = [];
676     },
677     loadHistory() {
678       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
679       else {
680         let temp = this.readLi();
681         if (temp.length > 0) this.form1.desc = temp[temp.length - 1].join("");
682       }
683     },
684     readLi() {
685       let readType = this.readType;
686       return this.myserialport.state.readValue.map((items, index) => {
687         const item = items.value;
688         const type = items.type; // 1接收,2发送
689         let body = [];
690         if (item !== undefined) {
691           let strArr = [];
692           for (let hex of Array.from(item)) {
693             strArr.push(hex.toString(16).toLocaleUpperCase());
694           }
695           if (strArr.includes("D") && strArr.includes("A")) {
696             if (strArr.indexOf("A") - strArr.indexOf("D") === 1) {
697               strArr.splice(strArr.indexOf("D"), 1);
698               strArr.splice(strArr.indexOf("A"), 1, <br key={0} />);
699             }
700           }
701           strArr = strArr.map((item) => {
702             if (typeof item === "string") {
703               if (readType === 1) {
704                 return this.myserialport.hex2a(parseInt(item, 16));
705               } else if (readType === 2) {
706                 return item + " ";
707               }
708             }
709             return item;
710           });
711           if (typeof strArr[strArr.length - 1] === "string") {
712             strArr.push("\r\n");
713           }
714           body.push(strArr.join(""));
715         }
716         return body;
717       });
718     },
719     conCom(){
720       try {
721         this.myserialport.state.baudRate = this.form1.baudRate;
722         this.myserialport.state.dataBits = this.form1.dataBits;
723         this.myserialport.state.stopBits = this.form1.stopBits;
724         this.myserialport.state.parity = this.form1.parity;
725         this.myserialport.state.flowControl = this.form1.flowControl;
726         this.myserialport.openPort(0, true, this.callBack);
727         console.log(this.form1.port)
728       } catch (error) {
729         this.$message.error("串口连接失败!请检查串口是否已被占用");
730       }
731       if (this.myserialport.state.isOpen) {
732         this.$message.success("串口连接成功");
733       }
734     },
735     //连接
736     async connectBtn() {
737       if (this.btnType === "primary") {
738         try {
739           this.myserialport.state.baudRate = this.form1.baudRate;
740           this.myserialport.state.dataBits = this.form1.dataBits;
741           this.myserialport.state.stopBits = this.form1.stopBits;
742           this.myserialport.state.parity = this.form1.parity;
743           this.myserialport.state.flowControl = this.form1.flowControl;
744           await this.myserialport.openPort(this.form1.port, true, this.callBack);
745           console.log(this.form1.port)
746         } catch (error) {
747           this.$message.error("串口连接失败!请检查串口是否已被占用");
748         }
749         if (this.myserialport.state.isOpen) {
750           this.$message.success("串口连接成功");
751           this.open1 = false
752           this.btnType = "danger";
753           this.btnText = "关闭串口";
754         }
755       } else {
756         this.myserialport.openPort(this.form1.port, false, this.callBack);
757         this.$message.success("串口关闭成功");
758         this.btnType = "primary";
759         this.btnText = "连接串口";
760       }
761     },
762     //授权
763     async obtainAuthorization() {
764       if ("serial" in navigator) {
765         console.log("The Web Serial API is supported.");
766         if (!this.myserialport) this.myserialport = new MySerialPort();
767         try {
768           await this.myserialport.handleRequestPort();
769           this.$message.success("串口授权成功");
770           this.getPortInfo(this.myserialport.state.ports);
771         } catch (error) {
772           this.$message.warning("未选择新串口授权!");
773         }
774       } else {
775         this.$message.error(
776           "当前为HTTP模式或者浏览器版本过低,不支持网页连接串口"
777         );
778       }
779     },
780     //串口列表初始化
781     getPortInfo(portList) {
782       this.portsList = [];
783       portList.map((port, index) => {
784         const { usbProductId, usbVendorId } = port.getInfo();
785         if (usbProductId === undefined || usbVendorId === undefined) {
786           this.portsList.push({ label: "未知设备" + index, value: index });
787         } else {
788           const usbVendor = USBDevice.filter(
789             (item) => parseInt(item.vendor, 16) === usbVendorId
790           );
791           let usbProduct = [];
792           if (usbVendor.length === 1) {
793             usbProduct = usbVendor[0].devices.filter(
794               (item) => parseInt(item.devid, 16) === usbProductId
795             );
796           }
797           this.portsList.push({ label: usbProduct[0].devname, value: index });
798         }
799       });
800     },
801     // 发送
802     async sendCommon() {
803       if (this.myserialport.state.isOpen) {
804         if (this.form1.sendMsg.length !== 0) {
805           const writeType = this.form1.type;
806           let value = this.form1.sendMsg;
807           let arr = [];
808           if (writeType === 1) {
809             // ASCII
810             for (let i = 0; i < value.length; i++) {
811               arr.push(this.myserialport.a2hex(value[i]));
812             }
813           } else if (writeType === 2) {
814             // HEX
815             if (/^[0-9A-Fa-f]+$/.test(value) && value.length % 2 === 0) {
816               for (let i = 0; i < value.length; i = i + 2) {
817                 arr.push(parseInt(value.substring(i, i + 2), 16));
818               }
819             } else {
820               this.$message.error("格式错误");
821               return;
822             }
823           }
824           this.myserialport.writeText(arr);
825         } else {
826           this.$message.warning("请输入发送的信息");
827         }
828       } else {
829         this.$message.warning("串口处于关闭状态,请连接串口");
830       }
831     },
832     async getPorts() {
833       await this.myserialport.getPorts();
834       this.getPortInfo(this.myserialport.state.ports);
835     },
836     querySearch(queryString, cb) {
837       var restaurants = this.restaurants;
838       var results = queryString
839         ? restaurants.filter(this.createFilter(queryString))
840         : restaurants;
841       // 调用 callback 返回建议列表的数据
842       cb(results);
843     },
844     createFilter(queryString) {
845       return (restaurant) => {
846         return (
847           restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
848           0
849         );
850       };
851     },
852     loadAll() {
853       return [
854         { value: "110" },
855         { value: "300" },
856         { value: "600" },
857         { value: "1200" },
858         { value: "2400" },
859         { value: "4800" },
860         { value: "7200" },
861         { value: "9600" },
862         { value: "14400" },
863         { value: "19200" },
864         { value: "28800" },
865         { value: "38400" },
866         { value: "56000" },
867         { value: "57600" },
868         { value: "76800" },
869         { value: "115200" },
870         { value: "230400" },
871         { value: "460800" },
872       ];
873     },
874   }
875 }
876
877 </script>
878 <style scoped>
879 .bottom-card{
880   height: 600px;
881 }
882 .circle-button{
883   height: 30px;
884   width: 30px;
885 }
886 .circle-red {
887   background-color: #e01a4f;
888 }
889 .circle-green {
890   background-color: green;
891 }
892 .circle-green-animate {
893   background-color: green;
894   animation: circle-green-animate 2s infinite;
895 }
896   @keyframes circle-green-animate {
897     50% {
898       opacity: 0.6;
899     }
900     0% {
901       opacity: 0.2;
902     }
903   }
904 .head-font{
905   /*font-weight: bold;*/
906   /*font-size: 25px;*/
907 }
908 span{
909   font-size: 15px;
910 }
911 .el-table .warning-row {
912   background: oldlace;
913 }
914
915 .el-table .success-row {
916   background: #f0f9eb;
917 }
918 </style>
919