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