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