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 | 134 ++++++++++++++++++++++++++++++++------------ 1 files changed, 98 insertions(+), 36 deletions(-) diff --git a/src/views/business/inspectionTask/inspection.vue b/src/views/business/inspectionTask/inspection.vue index 01ef6f2..d32723c 100644 --- a/src/views/business/inspectionTask/inspection.vue +++ b/src/views/business/inspectionTask/inspection.vue @@ -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,7 +537,7 @@ import AddUnPass from "../unpass/components/addUnPass.vue"; import InspectionWord from "./components/InspectionWord.vue"; import PurchaseVerification from "../unpass/components/PurchaseVerification.vue"; -import { connect,disconnect } from "@/utils/connect.js"; + import { doInsOrder, @@ -561,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', @@ -599,6 +601,7 @@ state: null, }, isSerialConnected: false, // 鏂板鐘舵�佸彉閲忥紝涓插彛杩炴帴鐘舵�� + serialPort: null, // 瀛樺偍涓插彛瀵硅薄 id: null, changeType: null, insOrder: {}, @@ -901,9 +904,16 @@ beforeDestroy() { // 鍦ㄧ粍浠堕攢姣佸墠纭繚鍋滄 Worker锛岄伩鍏嶅唴瀛樻硠婕� this.stopWorker(); - disconnect() + disconnect(); + // 璋冪敤鍓嶅厛鍒ゆ柇鏂规硶鏄惁瀛樺湪锛岄伩鍏嶆姤閿� + if (this.closeSerialPort) { + this.closeSerialPort();// 缁勪欢閿�姣佸墠鍏抽棴涓插彛 + } }, methods: { + sss() { + console.log(this.$store.state.weightList) // + }, // 鏂囦欢绠$悊--寮�濮� getList() { this.tableLoading = true; @@ -939,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]); } }, @@ -1133,36 +1148,82 @@ }, // 鏁版嵁閲囬泦 - getDataAcquisitionDevice() { - if (this.isSerialConnected) { - connect(); - } - // return - 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; @@ -1177,6 +1238,7 @@ return newObj; }, handleDataAcquisition(data, noDialog) { + console.log(data); // 鏄惁鍙互缂栬緫鏁伴噰鏁版嵁 if (this.dataAcquisitionEidtAble) { this.getDataType = 1; -- Gitblit v1.9.3