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