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