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