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