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