From cb2a01ee7dea28a2661720060b03c41dc372acb5 Mon Sep 17 00:00:00 2001
From: yaowanxin <3588231647@qq.com>
Date: 星期五, 01 八月 2025 11:53:16 +0800
Subject: [PATCH] 完善串口处理数据,数据选择

---
 src/views/business/inspectionTask/inspection.vue |  143 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 112 insertions(+), 31 deletions(-)

diff --git a/src/views/business/inspectionTask/inspection.vue b/src/views/business/inspectionTask/inspection.vue
index f26bb54..d32723c 100644
--- a/src/views/business/inspectionTask/inspection.vue
+++ b/src/views/business/inspectionTask/inspection.vue
@@ -141,7 +141,7 @@
           <el-button :loading="dataAcquisitionLoading" v-if="state == 1" size="small" type="primary"
             @click="getDataAcquisitionDevice">鏁版嵁閲囬泦</el-button>
           <el-button :type="dataAcquisitionEidtAble ? '' : 'primary'" v-if="state == 1" size="small"
-            @click="dataAcquisitionEidtAble = !dataAcquisitionEidtAble">{{ dataAcquisitionEidtAble ? "鍏抽棴缂栬緫" : "缂栬緫鏁伴噰"
+            @click="dataAcquisitionEidtAble = !dataAcquisitionEidtAble,disconnect()">{{ dataAcquisitionEidtAble ? "鍏抽棴缂栬緫" : "缂栬緫鏁伴噰"
             }}</el-button>
         </div>
       </div>
@@ -447,7 +447,7 @@
                 <el-checkbox-group v-if="!item.child[0].isShowSelect" v-model="item.child[0].getDataIndex1"
                   :max="item.child[0].maxNum">
                   <el-checkbox v-for="(n, j) in item.child[0].arr" :key="index + '-' + j + 'aaaaaa'" :label="j + '^' + n"
-                  @change="handleGroupSelect(item.child[0], j)" >{{ n }}</el-checkbox>
+                  @change="handleGroupSelect(item.child[0], j, item.child[0].arr.length)" >{{ n }}</el-checkbox>
                 </el-checkbox-group>
               </div>
             </td>
@@ -478,7 +478,7 @@
                 </el-select>
                 <el-checkbox-group v-if="!m.isShowSelect" v-model="m.getDataIndex1" :max="m.maxNum">
                   <el-checkbox v-for="(n, j) in m.arr" :key="index + '-' + j + 'dddddddd'" :label="j + '^' + n"
-                  @change="handleGroupSelect(m, j)" >{{ n }}</el-checkbox>
+                  @change="handleGroupSelect(m, j, m.arr.length)" >{{ n }}</el-checkbox>
                 </el-checkbox-group>
               </div>
             </td>
@@ -526,6 +526,7 @@
       :purchaseDialog="purchaseDialog" @resetPurchaseDialog="resetPurchaseDialog"></purchase-verification>
     <!--鏌ョ湅宸ユ椂寮规-->
     <viewManHourDia ref="viewManHourDia" @submit="openAddVerifyDia"></viewManHourDia>
+    <button @click="sss">杩炴帴涓插彛</button>
   </div>
 </template>
 
@@ -536,6 +537,8 @@
 import AddUnPass from "../unpass/components/addUnPass.vue";
 import InspectionWord from "./components/InspectionWord.vue";
 import PurchaseVerification from "../unpass/components/PurchaseVerification.vue";
+
+
 import {
   doInsOrder,
   getCableTag,
@@ -559,6 +562,7 @@
 import DataWorker from '@/workers/DataWorker.worker.js';
 import html2canvas from "html2canvas";
 import { mapGetters } from "vuex";
+import { connect,disconnect,weightList } from "@/utils/connect.js";
 import viewManHourDia from "@/views/business/inspectionTask/components/viewManHourDia.vue";
 export default {
   name: 'Inspection',
@@ -596,6 +600,8 @@
         sampleName: null,
         state: null,
       },
+      isSerialConnected: false, // 鏂板鐘舵�佸彉閲忥紝涓插彛杩炴帴鐘舵��
+      serialPort: null, // 瀛樺偍涓插彛瀵硅薄
       id: null,
       changeType: null,
       insOrder: {},
@@ -818,6 +824,7 @@
     this.startWorker();
     // this.getList0() // 浠诲姟鍒囨崲
     this.scrollInit();
+    disconnect()
   },
   activated() {
     this.getTypeDicts(); // 鑾峰彇绱ф�ョ▼搴︿笅鎷夋閫夐」
@@ -897,8 +904,16 @@
   beforeDestroy() {
     // 鍦ㄧ粍浠堕攢姣佸墠纭繚鍋滄 Worker锛岄伩鍏嶅唴瀛樻硠婕�
     this.stopWorker();
+    disconnect();
+    // 璋冪敤鍓嶅厛鍒ゆ柇鏂规硶鏄惁瀛樺湪锛岄伩鍏嶆姤閿�
+    if (this.closeSerialPort) {
+      this.closeSerialPort();// 缁勪欢閿�姣佸墠鍏抽棴涓插彛
+    }
   },
   methods: {
+    sss() {
+      console.log(this.$store.state.weightList) // 
+    },
     // 鏂囦欢绠$悊--寮�濮�
     getList() {
       this.tableLoading = true;
@@ -934,14 +949,19 @@
       }).catch(() => { });
     },
     // 鏂囦欢绠$悊--缁撴潫
-  // 澶勭悊鏁寸粍鍕鹃�夐�昏緫鐨勬柟娉�
-    handleGroupSelect(childItem, clickedIndex) {
+    // 澶勭悊鏁寸粍鍕鹃�夐�昏緫鐨勬柟娉�
+    handleGroupSelect(childItem, clickedIndex, groupSize = 5) {
+      if(groupSize == 6){
+        groupSize = 6;
+      }else{
+        groupSize = 5;
+      }
       // 璁$畻鎵�鍦ㄧ粍鐨勮捣濮嬬储寮�
-      const groupStartIndex = Math.floor(clickedIndex / 5) * 5;
+      const groupStartIndex = Math.floor(clickedIndex / groupSize) * groupSize;
       // 娓呯┖褰撳墠宸查��
       childItem.getDataIndex1 = [];
-      // 閬嶅巻褰撳墠缁勭殑 5 涓厓绱狅紝娣诲姞鍒伴�変腑鍒楄〃
-      for (let i = groupStartIndex; i < groupStartIndex + 5 && i < childItem.arr.length; i++) {
+      // 閬嶅巻褰撳墠缁勭殑 groupSize 涓厓绱狅紝娣诲姞鍒伴�変腑鍒楄〃
+      for (let i = groupStartIndex; i < groupStartIndex + groupSize && i < childItem.arr.length; i++) {
         childItem.getDataIndex1.push(i + '^' + childItem.arr[i]);
       }
     },
@@ -1126,33 +1146,89 @@
       this.$refs.purchaseDialog.$refs["purchaseForm"].resetFields();
       this.purchaseDialog = false;
     },
+
     // 鏁版嵁閲囬泦
-    getDataAcquisitionDevice() {
-      let itemIds = [];
-      this.currentSample.insProduct.forEach((item) => {
-        if (item.inspectionItemType === "1") {
-          itemIds.push(item.id);
+
+  getDataAcquisitionDevice() {
+      (async () => {
+        try {
+          // 妫�鏌ユ槸鍚︽敮鎸� Web Serial API
+          if ('serial' in navigator) {
+            // 璇锋眰鍙敤涓插彛
+            const ports = await navigator.serial.getPorts();
+            if (ports.length > 0) {
+              await connect();
+            } else {
+              console.log('娌℃湁鍙敤鐨勪覆鍙�');
+            }
+          } else {
+            console.log('褰撳墠娴忚鍣ㄤ笉鏀寔 Web Serial API');
+          }
+        } catch (error) {
+          console.error('妫�娴嬩覆鍙f椂鍑洪敊:', error);
         }
-      });
-      const params = {
-        entrustCode: this.insOrder.entrustCode,
-        sampleCode: this.currentSample.sampleCode,
-        id: this.currentSample.id,
-        itemIds: itemIds,
-      };
-      this.dataAcquisitionLoading = true;
-      dataCollection(params).then((res) => {
-        this.dataAcquisitionLoading = false;
-        if (res.code != 200) {
-          return;
-        }
-        this.dataAcquisitionInfoNew = this.HaveJson(res.data);
-        // 瀵规暟閲囧洖鏉ョ殑鍊艰繘琛屽鐞�
-        this.handleDataAcquisition(res.data);
-      }).catch(err => {
-        this.dataAcquisitionLoading = false;
+      })().then(() => {
+        let itemIds = [];
+        this.currentSample.insProduct.forEach((item) => {
+          if (item.inspectionItemType === "1") {
+            itemIds.push(item.id);
+          }
+        });
+        const params = {
+          entrustCode: this.insOrder.entrustCode,
+          sampleCode: this.currentSample.sampleCode,
+          id: this.currentSample.id,
+          itemIds: itemIds,
+        };
+        this.dataAcquisitionLoading = true;
+        dataCollection(params).then((res) => {
+          this.dataAcquisitionLoading = false;
+          if (res.code != 200) {
+            return;
+          }
+          this.dataAcquisitionInfoNew = this.HaveJson(res.data);
+          // 瀵规暟閲囧洖鏉ョ殑鍊艰繘琛屽鐞�
+          this.handleDataAcquisition(res.data);
+        }).catch(err => {
+          this.dataAcquisitionLoading = false;
+        });
       });
     },
+    // getDataAcquisitionDevice() {
+    //   if (this.isSerialConnected) {
+    //     connect();
+    //   }
+    //   // return
+    //   let itemIds = [];
+    //   this.currentSample.insProduct.forEach((item) => {
+    //     if (item.inspectionItemType === "1") {
+    //       itemIds.push(item.id);
+    //     }
+    //   });
+    //   const params = {
+    //     entrustCode: this.insOrder.entrustCode,
+    //     sampleCode: this.currentSample.sampleCode,
+    //     id: this.currentSample.id,
+    //     itemIds: itemIds,
+    //   };
+    //   this.dataAcquisitionLoading = true;
+    //   dataCollection(params).then((res) => {
+    //     this.dataAcquisitionLoading = false;
+    //     if (res.code != 200) {
+    //       return;
+    //     }
+    //     this.dataAcquisitionInfoNew = this.HaveJson(res.data);
+    //     // 瀵规暟閲囧洖鏉ョ殑鍊艰繘琛屽鐞�
+    //     this.handleDataAcquisition(res.data);
+    //   }).catch(err => {
+    //     this.dataAcquisitionLoading = false;
+    //   });
+    // },
+    // 鍋囪瀛樺湪涓�涓柟娉曠敤浜庢洿鏂颁覆鍙h繛鎺ョ姸鎬�
+    // updateSerialConnectionStatus(status) {
+    //   this.isSerialConnected = status;
+    // },
+
     objectOrder(obj) {
       let newkey = Object.keys(obj).sort();
       let newObj = {};
@@ -1162,6 +1238,7 @@
       return newObj;
     },
     handleDataAcquisition(data, noDialog) {
+      console.log(data);
       // 鏄惁鍙互缂栬緫鏁伴噰鏁版嵁
       if (this.dataAcquisitionEidtAble) {
         this.getDataType = 1;
@@ -1214,6 +1291,7 @@
               };
             }
             let list = this.tableList[0].arr;
+            console.log(this.tableList[0]);
             // 寰幆椤甸潰鍒楄〃淇℃伅锛屽垽鏂暟閲囨暟鎹搴旈〉闈㈠垪琛ㄤ俊鎭殑妫�楠岄」鏄摢涓紝骞剁粰褰撳墠妫�楠岄」缁戝畾璁惧淇℃伅
             list.forEach((item, index) => {
               let num0 = 0;
@@ -2914,6 +2992,9 @@
       this.$router.go(-1)
     }
   },
+  destroyed() {
+    disconnect()
+  },
 };
 </script>
 <style scoped>

--
Gitblit v1.9.3