admin
2024-07-11 653b17eac39c339774cd46291a9345493b253a1f
提交 | 用户 | 时间
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,
305   releaseCheck,
306   updateResults,
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('总成码为空,请扫码!')
741             return;
742           }
743
744           // if(self.headContent.cardCode === null || self.headContent.cardCode === ''){
745           //   self.$alert('<strong style="color: red;font-size: 30px">未扫描小车码禁止放行</strong>', '提示', {
746           //     dangerouslyUseHTMLString: true
747           //   });
748           //   return;
749           // }
750
751           if(self.formulaChildList[formulaChildIndex].results !== 'OK'){
752             self.$message('未做完工序禁止放行');
753             return;
754           }
755
756
757           const param = {
758             workOrderNo: self.workpieceInformation.workOrderNo,
759             productCode: self.workpieceInformation.productCode,
760             locationCode: self.headContent.processesCode,
761             productBarcode: self.headContent.sfcCode,
762             inboundTime: self.workpieceInformation.inboundTime,
763             formulaChildEntity: self.formulaChildList[formulaChildIndex]
764           }
765
766           console.log("进入最终方法")
767           self.endSaveData(param)
768
769         } else if (event.data.includes("[")) {
770           let formulaChilds = "";
771           self.formulaChildList.sort((a, b) => a.stepSort - b.stepSort);
772           self.formulaChildList
773             .filter((formulaChild) => formulaChild.operationType === '1');
774           for (let i = 0; i < self.formulaChildList.length; i++) {
775             let formulaChild = self.formulaChildList[i];
776             let results = formulaChild.results;
777
778             if (results === '' || results === null || results === 'NG') {
779               formulaChilds = formulaChild;
780               break;
781             }
782           }
783            if(formulaChilds === ""){
784              self.$message.error('本工位已工作完成!');
785              return;
786            }
787           const param = {
788             id: formulaChilds.id,
789             tightenTheArray: event.data,
790             paramCode: formulaChilds.paramCode,
791             workOrderNo: self.workpieceInformation.workOrderNo,
792             productCode: self.workpieceInformation.productCode,
793             locationCode: self.headContent.processesCode,
794             productBarcode: self.headContent.sfcCode,
795             spareField1: formulaChilds.spareField1,
796             spareField2: formulaChilds.spareField2,
797             spareField3: formulaChilds.spareField3,
798             spareField4: formulaChilds.spareField4,
799             stepSort: formulaChilds.stepSort
800           }
801           if(formulaChilds.paramCode === null||formulaChilds.paramCode ===''){
802             self.$message('未找到参数码,请检查参数码是否正确');
803             return;
804           }
805           if(self.headContent.sfcCode!==null||self.headContent.sfcCode!==''){
806             updateTighteningFormula(param).then(response => {
807               //addTighteningParameters(param).then(response => {});
808               self.getListFormulaChild()
809             }).catch(error =>{
810               self.getListFormulaChild()
811             });
812           }
8c5c9c 813         }else if(event.data.includes("productNum")){
22c9e0 814           let productNum = event.data.split(',')[1];
A 815           self.headContent.sfcCode = productNum;
816           self.queryParams.productNum = productNum;
817           self.getList()
818           self.cakeLamp.scanFinish = 1
819           self.cakeLamp.startWork = 1
50c585 820           this.cakeLamp.InPlace = 1
A 821
0ca254 822         }
A 823       };
824     },
825
826     endSaveData(param){
827       saveCampaignTimeParameters(param).then(response => {
828       this.cakeLamp.release = 1;
829       this.endClear()
830       workpieceRelease(param).then(response => {});
831       });
832     },
833
834     //接受数据的回调
835     callBack(value) {
836       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
837       else {
838         const scanValue = this.myserialport.hex2atostr(value).replace(/[\r\n]/g, '');
839         console.log("串口收到数据-------------------"+scanValue)
840         console.log("sfc=--"+this.headContent.sfcCode+"--")
841         if(this.headContent.sfcCode !== '' && this.headContent.sfcCode !== null
842           && this.headContent.sfcCode !== undefined){
843           if(scanValue.includes("0RSP1TE") && this.headContent.processesCode === 'OP240'){
844             this.headContent.cardCode = scanValue
845             this.bindcardCode(scanValue);
846             this.serialPortMethod(scanValue)
847           }else {
848             this.$message('工位终端扫描物料编码'+scanValue);
849             console.log(scanValue)
850             this.serialPortMethod(scanValue)
851           }
852         } else {
50c585 853           // if(this.headContent.processesCode === 'OP240'){
0ca254 854             this.headContent.sfcCode = scanValue;
A 855             this.queryParams.productNum = scanValue;
856             this.getList()
857             this.cakeLamp.scanFinish = 1
858             this.cakeLamp.startWork = 1
50c585 859             this.cakeLamp.InPlace = 1
A 860           // }else {
861           //   let param = {
862           //     trolleyYard: scanValue
863           //   }
864           //   findBytrolleyYardGetOne(param).then(response => {
865           //     if(response.msg !== '2'){
866           //       this.headContent.sfcCode = response.msg;
867           //       this.queryParams.productNum = response.msg;
868           //       this.$message('扫码识别产品序列号'+scanValue);
869           //       this.getList()
870           //       this.cakeLamp.scanFinish = 1
871           //       this.cakeLamp.startWork = 1
872           //       this.cakeLamp.InPlace = 1
873           //     }else {
874           //       this.$message('没有序列号'+scanValue);
875           //       return
876           //     }
877           //   });
878           // }
0ca254 879
A 880         }
881
882       }
883     },
884     clearHistory() {
885       this.form1.desc = "";
886       this.myserialport.state.readValue = [];
887     },
888     loadHistory() {
889       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
890       else {
891         let temp = this.readLi();
892         if (temp.length > 0) this.form1.desc = temp[temp.length - 1].join("");
893       }
894     },
895     readLi() {
896       let readType = this.readType;
897       return this.myserialport.state.readValue.map((items, index) => {
898         const item = items.value;
899         const type = items.type; // 1接收,2发送
900         let body = [];
901         if (item !== undefined) {
902           let strArr = [];
903           for (let hex of Array.from(item)) {
904             strArr.push(hex.toString(16).toLocaleUpperCase());
905           }
906           if (strArr.includes("D") && strArr.includes("A")) {
907             if (strArr.indexOf("A") - strArr.indexOf("D") === 1) {
908               strArr.splice(strArr.indexOf("D"), 1);
909               strArr.splice(strArr.indexOf("A"), 1, <br key={0} />);
910             }
911           }
912           strArr = strArr.map((item) => {
913             if (typeof item === "string") {
914               if (readType === 1) {
915                 return this.myserialport.hex2a(parseInt(item, 16));
916               } else if (readType === 2) {
917                 return item + " ";
918               }
919             }
920             return item;
921           });
922           if (typeof strArr[strArr.length - 1] === "string") {
923             strArr.push("\r\n");
924           }
925           body.push(strArr.join(""));
926         }
927         return body;
928       });
929     },
930     conCom(){
931       try {
932         this.myserialport.state.baudRate = this.form1.baudRate;
933         this.myserialport.state.dataBits = this.form1.dataBits;
934         this.myserialport.state.stopBits = this.form1.stopBits;
935         this.myserialport.state.parity = this.form1.parity;
936         this.myserialport.state.flowControl = this.form1.flowControl;
937         this.myserialport.openPort(0, true, this.callBack);
938         console.log(this.form1.port)
939       } catch (error) {
940         this.$message.error("串口连接失败!请检查串口是否已被占用");
941       }
942       if (this.myserialport.state.isOpen) {
943         this.$message.success("串口连接成功");
944       }
945     },
946     //连接
947     async connectBtn() {
948       if (this.btnType === "primary") {
949         try {
950           this.myserialport.state.baudRate = this.form1.baudRate;
951           this.myserialport.state.dataBits = this.form1.dataBits;
952           this.myserialport.state.stopBits = this.form1.stopBits;
953           this.myserialport.state.parity = this.form1.parity;
954           this.myserialport.state.flowControl = this.form1.flowControl;
955           await this.myserialport.openPort(this.form1.port, true, this.callBack);
956           console.log(this.form1.port)
957         } catch (error) {
958           this.$message.error("串口连接失败!请检查串口是否已被占用");
959         }
960         if (this.myserialport.state.isOpen) {
961           this.$message.success("串口连接成功");
962           this.open1 = false
963           this.btnType = "danger";
964           this.btnText = "关闭串口";
965         }
966       } else {
967         this.myserialport.openPort(this.form1.port, false, this.callBack);
968         this.$message.success("串口关闭成功");
969         this.btnType = "primary";
970         this.btnText = "连接串口";
971       }
972     },
973     //授权
974     async obtainAuthorization() {
975       if ("serial" in navigator) {
976         console.log("The Web Serial API is supported.");
977         if (!this.myserialport) this.myserialport = new MySerialPort();
978         try {
979           await this.myserialport.handleRequestPort();
980           this.$message.success("串口授权成功");
981           this.getPortInfo(this.myserialport.state.ports);
982         } catch (error) {
983           this.$message.warning("未选择新串口授权!");
984         }
985       } else {
986         this.$message.error(
987           "当前为HTTP模式或者浏览器版本过低,不支持网页连接串口"
988         );
989       }
990     },
991     //串口列表初始化
992     getPortInfo(portList) {
993       this.portsList = [];
994       portList.map((port, index) => {
995         const { usbProductId, usbVendorId } = port.getInfo();
996         if (usbProductId === undefined || usbVendorId === undefined) {
997           this.portsList.push({ label: "未知设备" + index, value: index });
998         } else {
999           const usbVendor = USBDevice.filter(
1000             (item) => parseInt(item.vendor, 16) === usbVendorId
1001           );
1002           let usbProduct = [];
1003           if (usbVendor.length === 1) {
1004             usbProduct = usbVendor[0].devices.filter(
1005               (item) => parseInt(item.devid, 16) === usbProductId
1006             );
1007           }
1008           this.portsList.push({ label: usbProduct[0].devname, value: index });
1009         }
1010       });
1011     },
1012     // 发送
1013     async sendCommon() {
1014       if (this.myserialport.state.isOpen) {
1015         if (this.form1.sendMsg.length !== 0) {
1016           const writeType = this.form1.type;
1017           let value = this.form1.sendMsg;
1018           let arr = [];
1019           if (writeType === 1) {
1020             // ASCII
1021             for (let i = 0; i < value.length; i++) {
1022               arr.push(this.myserialport.a2hex(value[i]));
1023             }
1024           } else if (writeType === 2) {
1025             // HEX
1026             if (/^[0-9A-Fa-f]+$/.test(value) && value.length % 2 === 0) {
1027               for (let i = 0; i < value.length; i = i + 2) {
1028                 arr.push(parseInt(value.substring(i, i + 2), 16));
1029               }
1030             } else {
1031               this.$message.error("格式错误");
1032               return;
1033             }
1034           }
1035           this.myserialport.writeText(arr);
1036         } else {
1037           this.$message.warning("请输入发送的信息");
1038         }
1039       } else {
1040         this.$message.warning("串口处于关闭状态,请连接串口");
1041       }
1042     },
1043     async getPorts() {
1044       await this.myserialport.getPorts();
1045       this.getPortInfo(this.myserialport.state.ports);
1046     },
1047     querySearch(queryString, cb) {
1048       var restaurants = this.restaurants;
1049       var results = queryString
1050         ? restaurants.filter(this.createFilter(queryString))
1051         : restaurants;
1052       // 调用 callback 返回建议列表的数据
1053       cb(results);
1054     },
1055     createFilter(queryString) {
1056       return (restaurant) => {
1057         return (
1058           restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
1059           0
1060         );
1061       };
1062     },
1063     loadAll() {
1064       return [
1065         { value: "110" },
1066         { value: "300" },
1067         { value: "600" },
1068         { value: "1200" },
1069         { value: "2400" },
1070         { value: "4800" },
1071         { value: "7200" },
1072         { value: "9600" },
1073         { value: "14400" },
1074         { value: "19200" },
1075         { value: "28800" },
1076         { value: "38400" },
1077         { value: "56000" },
1078         { value: "57600" },
1079         { value: "76800" },
1080         { value: "115200" },
1081         { value: "230400" },
1082         { value: "460800" },
1083       ];
1084     },
1085   }
1086 }
1087
1088 </script>
1089 <style scoped>
1090 .bottom-card{
1091   height: 600px;
1092 }
1093 .circle-button{
1094   height: 30px;
1095   width: 30px;
1096 }
1097 .circle-red {
1098   background-color: #e01a4f;
1099 }
1100 .circle-green {
1101   background-color: green;
1102 }
1103 .circle-green-animate {
1104   background-color: green;
1105   animation: circle-green-animate 2s infinite;
1106 }
1107   @keyframes circle-green-animate {
1108     50% {
1109       opacity: 0.6;
1110     }
1111     0% {
1112       opacity: 0.2;
1113     }
1114   }
1115 .head-font{
1116   /*font-weight: bold;*/
1117   /*font-size: 25px;*/
1118 }
1119 span{
1120   font-size: 15px;
1121 }
1122 .el-table .warning-row {
1123   background: oldlace;
1124 }
1125
1126 .el-table .success-row {
1127   background: #f0f9eb;
1128 }
1129 </style>
1130