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