懒羊羊
2024-03-15 b77c7b1843b5c8e0dc7079de00a4e3592806c236
提交 | 用户 | 时间
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">
110                <el-table-column label="排序" width="60" align="center" prop="stepSort">
111                </el-table-column>
112                <el-table-column label="操作内容" :show-overflow-tooltip='true' align="center" prop="operationSteps">
113                </el-table-column>
b77c7b 114                <el-table-column label="产品编号" width="150" align="center" prop="productCode">
115                </el-table-column>
116                <el-table-column label="采集值" width="150" align="center" prop="productCode">
117                </el-table-column>
118                <el-table-column label="结果" width="150" align="center" prop="results">
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";
295 import {listFormulaChild, releaseCheck, updateResults, workpieceRelease} from "@/api/main/bs/formulaChild/formulaChild";
c2944a 296 import MySerialPort from "@/utils/MySerialPort";
297 import USBDevice from "@/utils/usb.json";
b64ed2 298 import {listProductionOrde} from "@/api/main/om/productionOrde/productionOrde";
299 import {addPassingStationCollection} from "@/api/main/da/passingStationCollection/passingStationCollection";
49c784 300 import {
301   addBasicParameters,
302   addParamCollection,
303   addTighteningParameters
304 } from "@/api/main/da/paramCollection/paramCollection";
e57a89 305
306 export default {
307   name: "stationTerminal",
308   data() {
309     return {
310       serialPortContent: '',
311       // 查询参数
312       formulaChildParams: {
313         pageNum: 1,
314         pageSize: 10,
315         productCode: null,
316         processesCode: null,
317       },
318       // 配方配置子信息表格数据
319       formulaChildList: [],
320       ipAddress: '',
321       imgSrc: '',
322       headContent: {
323         processesCode: 'OP1010',
324         processesName: '贴标机-贴码',
49c784 325         sfcCode: '',
e57a89 326       },
327       workpieceInformation: {
b64ed2 328         workOrderNo: null,
e57a89 329         productCode: null,
330         productModel: null,
331         productName: null,
332         beat: null,
333       },
334       // 查询参数
335       queryParams: {
336         pageNum: 1,
337         pageSize: 10,
338         sfcCode: null,
339       },
340       // 查询参数
341       StationConfQueryParams: {
342         pageNum: 1,
343         pageSize: 10,
344         ipAddress: null,
345       },
346       cakeLamp: {
347         plcState: 1, //plc
348         scannerState: 1, //扫码枪
349         InPlace: 0, //工件到位
350         scanFinish: 0,
351         startWork: 0,
352         release: 0 //允许放行
353       },
354       content: '',
355       activeName: 'first',
49c784 356       url: "ws://192.168.11.76:8080/websocket/message/",
e57a89 357       message: "",
358       text_content: "",
359       ws: null,
c2944a 360       inputValue: '9',
361
362       open1: false,
363       input: "",
364       keepReading: true,
365       form1: {
366         baudRate: "9600",
367         dataBits: "8",
368         stopBits: "1",
369         parity: "none",
370         flowControl: "none",
371         desc: "",
372         type: "1",
373         isShowHistory: false,
374       },
375       btnType: "primary",
376       btnText: "连接串口",
377       restaurants: [],
378       portsList: [],
379       isShowSendArea: false,
380       readType: 1,
381       title: "",
b64ed2 382
383       passingStationForm: {},
49c784 384       originalArray: [],
e57a89 385     }
386   },
387   beforeDestroy() {
388     this.exit();
389   },
390   created() {
391     this.initStation();
392     // this.getStationConfList();
393     // setTimeout(() => {
394     //   this.connectWebsocket();
395     // }, 3000);
396   },
397   mounted() {
c2944a 398     if ("serial" in navigator) {
399       this.myserialport = new MySerialPort();
400       this.getPorts();
401       navigator.serial.addEventListener("connect", (e) => {
402         this.$message.success("设备已连接");
403         this.getPorts();
404       });
405       navigator.serial.addEventListener("disconnect", (e) => {
406         this.$message.error("设备已断开");
407       });
408       this.restaurants = this.loadAll();
409     } else {
410       this.$message.error(
411         "当前为HTTP模式或者浏览器版本过低,不支持网页连接串口"
412       );
413     }
414   },
415   computed: {
416     isDisable() {
417       return this.btnType === "danger";
418     },
e57a89 419   },
420   methods: {
c2944a 421     serialLink() {
422       this.open1 = true
423     },
e57a89 424     Release(){
93feb8 425       // this.$message('portsList!'+this.portsList.length);
426       if(this.btnType === "danger"){
427         this.$message('连接了!');
428
429       }else {
430         this.$message('mei连接了!');
431
e57a89 432       }
93feb8 433
434       // //判断是否可以释放
435       // let formulaChildParams = {
436       //   productCode: this.workpieceInformation.productCode,
437       //   processesCode: this.headContent.processesCode
438       // }
439       // releaseCheck(formulaChildParams).then(response => {
440       //   if(response.data === 0){
441       //     //改变状态
442       //     workpieceRelease(formulaChildParams).then(response => {
443       //     });
444       //     this.$message('放行成功!');
445       //     this.formulaChildList = []
446       //     this.getListFormulaChild()
447       //     // this.resetting()
448       //   }else {
449       //     this.$message('步骤未完成不许放行!');
450       //   }
451       // });
e57a89 452     },
c2944a 453     serialPortMethod(value){
b77c7b 454       console.log(value.includes('C'));
455       let formulaChilds = '';
456       console.log(this.formulaChildList)
457       this.formulaChildList.forEach((formulaChild) => {
458         formulaChilds = formulaChild;
459         let operationType = formulaChild.operationType;
460         let results = formulaChild.results;
461         let materialCode = formulaChild.materialCode;
462         if(operationType === '2' && value.includes(materialCode) && (results === '' || results === null || results === 'NG')){
463           return; // 使用return代替break
464         }
e57a89 465       });
b77c7b 466       console.log(formulaChilds)
467       // let formulaChildParams = {
468       //   scanBarcode: value,
469       //   sfcBarcode: this.headContent.sfcCode,
470       //   workOrderNo: this.workpieceInformation.workOrderNo,
471       //   productCode: this.workpieceInformation.productCode,
472       //   locationCode: this.headContent.processesCode,
473       //   collectionTime: new Date()
474       // }
475       // updateResults(formulaChildParams).then(response => {
476       //   this.getListFormulaChild()
477       // });
e57a89 478     },
479     rowStyle({ row }) {
480       if (row.results === 'OK') {
481         return 'background-color: PaleGreen';
482       } else if (row.results === 'NG') {
483         return 'background-color: LightSalmon';
484       }
485       return '';
486     },
487     /** 查询配方配置子信息列表 */
488     getListFormulaChild() {
489       this.formulaChildParams.productCode = this.workpieceInformation.productCode
490       this.formulaChildParams.processesCode = this.headContent.processesCode
491       listFormulaChild(this.formulaChildParams).then(response => {
492         this.formulaChildList = response.rows;
b77c7b 493         console.log(this.formulaChildList)
e57a89 494       });
495     },
b77c7b 496
e57a89 497     changeMenu(tab, event) {
498       console.log(tab, event);
499     },
500     clearClick(){
501       this.$message('这是一条清除消息提示');
502       this.headContent.sfcCode = null
503     },
504     scanCompleted(){
505       this.$message('扫码完成'+this.content);
506       this.headContent.sfcCode = this.content
507       this.queryParams.sfcCode = this.content
508       this.getList()
509       this.getListFormulaChild()
510       this.cakeLamp.scanFinish = 1
511       this.cakeLamp.startWork = 1
512
513     },
b64ed2 514     /** 查询工单列表 */
e57a89 515     async getList() {
b64ed2 516       await listProductionOrde(this.queryParams).then(response => {
e57a89 517         let rowsData = response.rows[0];
518         console.log(rowsData)
b64ed2 519         this.workpieceInformation.workOrderNo = rowsData.workOrderNo;
e57a89 520         this.workpieceInformation.productCode = rowsData.productCode;
521         this.workpieceInformation.productModel = rowsData.productModel;
522         this.workpieceInformation.productName = rowsData.productName;
523         this.timer = setInterval(() => {
524           this.workpieceInformation.beat++;
525         }, 1000);
526       });
527       this.getListFormulaChild()
b64ed2 528       this.addOverStationCollection()
529     },
530
531     /** 入站增加过站采集记录 **/
532     addOverStationCollection(){
533       this.passingStationForm = {
534         id: null,
535         workOrderNo: this.workpieceInformation.workOrderNo,
536         productCode: this.workpieceInformation.productCode,
537         locationCode: this.headContent.processesCode,
538         model: this.workpieceInformation.productModel,
539         productBarcode: this.headContent.sfcCode,
540         inboundTime: new Date()
541       }
b77c7b 542       addPassingStationCollection(this.passingStationForm).then(response => {});
543       addBasicParameters(this.passingStationForm).then(response => {});
e57a89 544     },
545     allowRelease(){
546       clearInterval(this.timer);
547       this.$message('保存节拍为'+this.workpieceInformation.beat+'秒');
548     },
549     /** 查询工位终端配置列表 */
550     // async getStationConfList() {
551     //   await getIpv4().then(response => {
552     //     this.StationConfQueryParams.ipAddress = response.msg
553     //     console.log('查询到本工位IP为'+this.StationConfQueryParams.ipAddress)
554     //   });
555     //   listStationConf(this.StationConfQueryParams).then(response => {
556     //     let rows = response.rows[0]
557     //     if(response.rows.length===0){
558     //       this.$message('该工位没有配置IP,请联系管理员配置IP');
559     //       return
560     //     }
561     //     this.headContent.processesName = rows.processesName
562     //     this.headContent.processesCode = rows.processesCode
563     //     console.log('设置工位编码'+this.headContent.processesCode)
564     //
565     //   });
566     // },
567     // connectWebsocket() {
568     //   console.log('websocket连接工位为'+this.headContent.processesCode)
569     //   const wsuri = this.url + this.headContent.processesCode;
570     //   this.ws = new WebSocket(wsuri);
571     //   const self = this;
572     //   this.ws.onopen = function (event) {
573     //     // self.text_content = self.text_content + "已经打开连接!" + "\n";
574     //     this.$message('websocket连接成功!');
575     //   };
576     //   this.ws.onmessage = function (event) {
577     //     self.text_content = event.data + "\n";
578     //     console.log(event.data)
579     //     if(event.data === "IN"){
580     //       self.cakeLamp.InPlace = "1"
581     //     }else if(event.data === "OUT"){
582     //       self.cakeLamp.outRsSign = "1"
583     //     }
584     //   };
585     // },
586     exit() {
587       if (this.ws) {
588         this.ws.close();
589         this.ws = null;
590       }
591     },
592     send() {
593       if (this.ws) {
594         this.ws.send(this.message);
595       } else {
596         alert("未连接到服务器");
597       }
598     },
49c784 599     initStation: async function () {
e57a89 600       await getIpv4().then(response => {
601         this.StationConfQueryParams.ipAddress = response.msg
49c784 602         console.log('查询到本工位IP为' + this.StationConfQueryParams.ipAddress)
e57a89 603       });
604       await listStationConf(this.StationConfQueryParams).then(response => {
605         let rows = response.rows[0]
49c784 606         if (response.rows.length === 0) {
e57a89 607           this.$message('该工位没有配置IP,请联系管理员配置IP');
608           return
609         }
610         this.headContent.processesName = rows.processesName
611         this.headContent.processesCode = rows.processesCode
49c784 612         console.log('设置工位编码' + this.headContent.processesCode)
e57a89 613
614       });
49c784 615       console.log('websocket连接工位为' + this.headContent.processesCode)
e57a89 616       const wsuri = this.url + this.headContent.processesCode;
617       this.ws = new WebSocket(wsuri);
618       const self = this;
619       this.ws.onopen = function (event) {
620         this.$message('websocket连接成功!');
621       };
622       this.ws.onmessage = function (event) {
c2944a 623         const DELAY_TIME = 2000;
49c784 624         if (event.data === "IN") {
625           self.cakeLamp.InPlace = 1;
626         } else if (event.data === "IN0") {
627           self.cakeLamp.InPlace = 0;
628         } else if (event.data === "OUT") {
629           self.cakeLamp.release = 1;
630           setTimeout(() => {
c2944a 631             self.cakeLamp.InPlace = 0;
49c784 632             self.cakeLamp.release = 0;
633             self.cakeLamp.startWork = 0;
634             self.cakeLamp.scanFinish = 0;
635             self.Release();
636           }, DELAY_TIME);
637         } else if (event.data === "TIGHTEN") {
638           this.formulaChildList = [];
639           self.getListFormulaChild();
640         } else if (event.data.includes("[")) {
b77c7b 641           let formulaChilds = "";
642           // for(let i=0;i<self.formulaChildList.length;i++){
643           //   formulaChilds = self.formulaChildList[i];
644           //   let operationType = formulaChild.operationType;
645           //   let results = formulaChild.results;
646           //   if(operationType === '1' &&
647           //     (results === '' || results === null ||results === 'NG')){
648           //         break;
649           //   }
650           // }
651           self.formulaChildList.forEach((formulaChild) => {
652             formulaChilds = formulaChild;
653             let operationType = formulaChild.operationType;
654             let results = formulaChild.results;
655             if(operationType === '1' && (results === '' || results === null || results === 'NG')){
656               return; // 使用return代替break
657             }
658             // 执行其他操作
659           });
660           console.log(formulaChilds)
661           console.log(formulaChilds.paramCode)
49c784 662           const param = {
663             tightenTheArray: event.data,
b77c7b 664             paramCode: formulaChilds.paramCode,
49c784 665             workOrderNo: self.workpieceInformation.workOrderNo,
666             productCode: self.workpieceInformation.productCode,
667             locationCode: self.headContent.processesCode,
668             productBarcode: self.headContent.sfcCode,
669           }
670           addTighteningParameters(param).then(response => {});
e57a89 671         }
672       };
673     },
c2944a 674
675     //接受数据的回调
676     callBack(value) {
677       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
678       else {
679         const scanValue = this.myserialport.hex2atostr(value).replace(/[\r\n]/g, '');
680         this.$message('扫码完成'+this.content);
b77c7b 681
682         if(this.headContent.sfcCode !== ''){
683           console.log(scanValue)
c2944a 684           this.serialPortMethod(scanValue)
b77c7b 685         }else {
c2944a 686           this.headContent.sfcCode = scanValue;
49c784 687           this.queryParams.productNum = scanValue;
c2944a 688           this.getList()
689           // this.getListFormulaChild()
690           this.cakeLamp.scanFinish = 1
691           this.cakeLamp.startWork = 1
692         }
e57a89 693       }
c2944a 694     },
695     clearHistory() {
696       this.form1.desc = "";
697       this.myserialport.state.readValue = [];
698     },
699     loadHistory() {
700       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
701       else {
702         let temp = this.readLi();
703         if (temp.length > 0) this.form1.desc = temp[temp.length - 1].join("");
704       }
705     },
706     readLi() {
707       let readType = this.readType;
708       return this.myserialport.state.readValue.map((items, index) => {
709         const item = items.value;
710         const type = items.type; // 1接收,2发送
711         let body = [];
712         if (item !== undefined) {
713           let strArr = [];
714           for (let hex of Array.from(item)) {
715             strArr.push(hex.toString(16).toLocaleUpperCase());
716           }
717           if (strArr.includes("D") && strArr.includes("A")) {
718             if (strArr.indexOf("A") - strArr.indexOf("D") === 1) {
719               strArr.splice(strArr.indexOf("D"), 1);
720               strArr.splice(strArr.indexOf("A"), 1, <br key={0} />);
721             }
722           }
723           strArr = strArr.map((item) => {
724             if (typeof item === "string") {
725               if (readType === 1) {
726                 return this.myserialport.hex2a(parseInt(item, 16));
727               } else if (readType === 2) {
728                 return item + " ";
729               }
730             }
731             return item;
732           });
733           if (typeof strArr[strArr.length - 1] === "string") {
734             strArr.push("\r\n");
735           }
736           body.push(strArr.join(""));
737         }
738         return body;
739       });
740     },
741     //连接
742     async connectBtn() {
743       if (this.btnType === "primary") {
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           await this.myserialport.openPort(this.form1.port, true, this.callBack);
751         } catch (error) {
752           this.$message.error("串口连接失败!请检查串口是否已被占用");
753         }
754         if (this.myserialport.state.isOpen) {
755           this.$message.success("串口连接成功");
756           this.open1 = false
757           this.btnType = "danger";
758           this.btnText = "关闭串口";
759         }
760       } else {
761         this.myserialport.openPort(this.form1.port, false, this.callBack);
762         this.$message.success("串口关闭成功");
763         this.btnType = "primary";
764         this.btnText = "连接串口";
765       }
766     },
767     //授权
768     async obtainAuthorization() {
769       if ("serial" in navigator) {
770         console.log("The Web Serial API is supported.");
771         if (!this.myserialport) this.myserialport = new MySerialPort();
772         try {
773           await this.myserialport.handleRequestPort();
774           this.$message.success("串口授权成功");
775           this.getPortInfo(this.myserialport.state.ports);
776         } catch (error) {
777           this.$message.warning("未选择新串口授权!");
778         }
779       } else {
780         this.$message.error(
781           "当前为HTTP模式或者浏览器版本过低,不支持网页连接串口"
782         );
783       }
784     },
785     //串口列表初始化
786     getPortInfo(portList) {
787       this.portsList = [];
788       portList.map((port, index) => {
789         const { usbProductId, usbVendorId } = port.getInfo();
790         if (usbProductId === undefined || usbVendorId === undefined) {
791           this.portsList.push({ label: "未知设备" + index, value: index });
792         } else {
793           const usbVendor = USBDevice.filter(
794             (item) => parseInt(item.vendor, 16) === usbVendorId
795           );
796           let usbProduct = [];
797           if (usbVendor.length === 1) {
798             usbProduct = usbVendor[0].devices.filter(
799               (item) => parseInt(item.devid, 16) === usbProductId
800             );
801           }
802           this.portsList.push({ label: usbProduct[0].devname, value: index });
803         }
804       });
805     },
806     // 发送
807     async sendCommon() {
808       if (this.myserialport.state.isOpen) {
809         if (this.form1.sendMsg.length !== 0) {
810           const writeType = this.form1.type;
811           let value = this.form1.sendMsg;
812           let arr = [];
813           if (writeType === 1) {
814             // ASCII
815             for (let i = 0; i < value.length; i++) {
816               arr.push(this.myserialport.a2hex(value[i]));
817             }
818           } else if (writeType === 2) {
819             // HEX
820             if (/^[0-9A-Fa-f]+$/.test(value) && value.length % 2 === 0) {
821               for (let i = 0; i < value.length; i = i + 2) {
822                 arr.push(parseInt(value.substring(i, i + 2), 16));
823               }
824             } else {
825               this.$message.error("格式错误");
826               return;
827             }
828           }
829           this.myserialport.writeText(arr);
830         } else {
831           this.$message.warning("请输入发送的信息");
832         }
833       } else {
834         this.$message.warning("串口处于关闭状态,请连接串口");
835       }
836     },
837     async getPorts() {
838       await this.myserialport.getPorts();
839       this.getPortInfo(this.myserialport.state.ports);
840     },
841     querySearch(queryString, cb) {
842       var restaurants = this.restaurants;
843       var results = queryString
844         ? restaurants.filter(this.createFilter(queryString))
845         : restaurants;
846       // 调用 callback 返回建议列表的数据
847       cb(results);
848     },
849     createFilter(queryString) {
850       return (restaurant) => {
851         return (
852           restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
853           0
854         );
855       };
856     },
857     loadAll() {
858       return [
859         { value: "110" },
860         { value: "300" },
861         { value: "600" },
862         { value: "1200" },
863         { value: "2400" },
864         { value: "4800" },
865         { value: "7200" },
866         { value: "9600" },
867         { value: "14400" },
868         { value: "19200" },
869         { value: "28800" },
870         { value: "38400" },
871         { value: "56000" },
872         { value: "57600" },
873         { value: "76800" },
874         { value: "115200" },
875         { value: "230400" },
876         { value: "460800" },
877       ];
878     },
e57a89 879   }
880 }
881
882 </script>
883 <style scoped>
884 .bottom-card{
885   height: 600px;
886 }
887 .circle-button{
888   height: 30px;
889   width: 30px;
890 }
891 .circle-red {
892   background-color: #e01a4f;
893 }
894 .circle-green {
895   background-color: green;
896 }
897 .circle-green-animate {
898   background-color: green;
899   animation: circle-green-animate 2s infinite;
900 }
901   @keyframes circle-green-animate {
902     50% {
903       opacity: 0.6;
904     }
905     0% {
906       opacity: 0.2;
907     }
908   }
909 .head-font{
c2944a 910   /*font-weight: bold;*/
911   /*font-size: 25px;*/
e57a89 912 }
913 span{
914   font-size: 15px;
915 }
916 .el-table .warning-row {
917   background: oldlace;
918 }
919
920 .el-table .success-row {
921   background: #f0f9eb;
922 }
923 </style>
924