From 0a144cc1dd664851638a6a01d030dd6a1585c25a Mon Sep 17 00:00:00 2001 From: yaowanxin <3588231647@qq.com> Date: 星期五, 25 七月 2025 14:55:34 +0800 Subject: [PATCH] 增添数据库表字段 --- src/views/CNAS/resourceDemand/device/component/acquisitionConfig.vue | 14 +++- src/utils/connect.js | 96 ++++++++++++++++++++++++++++++++ src/views/business/inspectionTask/inspection.vue | 11 +++ 3 files changed, 117 insertions(+), 4 deletions(-) diff --git a/src/utils/connect.js b/src/utils/connect.js new file mode 100644 index 0000000..39edfd6 --- /dev/null +++ b/src/utils/connect.js @@ -0,0 +1,96 @@ +// 鏂板锛氬瓨鍌ㄥ叏灞�涓插彛鍜岃鍙栧櫒瀹炰緥 + let port = null; + let reader = null; + let accumulatedData = ""; // 绉诲埌鍏ㄥ眬锛屼究浜庡叧闂椂閲嶇疆 + + async function connect() { + if ("serial" in navigator) { + try { + port = await navigator.serial.requestPort(); // 淇敼涓哄叏灞�鍙橀噺 + await port.open({ baudRate: 9600 }); + + reader = port.readable.getReader(); // 淇敼涓哄叏灞�鍙橀噺 + const decoder = new TextDecoder(); + accumulatedData = ""; // 閲嶇疆绱Н鏁版嵁 + + console.log("涓插彛杩炴帴鎴愬姛锛屽紑濮嬫帴鏀舵暟鎹�..."); + + while (true) { + const { value, done } = await reader.read(); + if (done) break; + + const decodedChunk = decoder.decode(value, { stream: true }); + accumulatedData += decodedChunk; + console.log("鎺ユ敹鍒版暟鎹潡:", decodedChunk); + + processAccumulatedData(accumulatedData); + } + } catch (error) { + console.error("涓插彛閿欒:", error); + } + } + + function processAccumulatedData(data) { + if (data.includes("\n")) { + const messages = data.split("\n"); + + for (let i = 0; i < messages.length - 1; i++) { + const completeMessage = messages[i]; + console.log("瀹屾暣娑堟伅:", completeMessage); + handleMessage(completeMessage); + } + + accumulatedData = messages[messages.length - 1]; + } + + // 鍏朵粬娑堟伅鎷嗗垎绀轰緥淇濇寔涓嶅彉 + /* + while (accumulatedData.length >= 32) { + const message = accumulatedData.substring(0, 32); + accumulatedData = accumulatedData.substring(32); + handleMessage(message); + } + */ + + /* + let startIndex = 0; + while (true) { + const start = accumulatedData.indexOf(0xAA, startIndex); + if (start === -1) break; + + const end = accumulatedData.indexOf(0x55, start + 1); + if (end === -1) break; + + const message = accumulatedData.substring(start, end + 1); + accumulatedData = accumulatedData.substring(end + 1); + handleMessage(message); + startIndex = start; + } + */ + } + } + + // 鏂板锛氬叧闂繛鎺ュ嚱鏁� + async function disconnect() { + if (!port || !reader) { + console.log("鏈缓绔嬭繛鎺ワ紝鏃犻渶鍏抽棴"); + return; + } + + try { + // 鍏堝彇娑堣鍙栧櫒 + await reader.cancel(); + // 鍐嶅叧闂覆鍙� + await port.close(); + console.log("涓插彛杩炴帴宸插叧闂�"); + + // 閲嶇疆鍏ㄥ眬鍙橀噺 + port = null; + reader = null; + accumulatedData = ""; + } catch (error) { + console.error("鍏抽棴杩炴帴澶辫触:", error); + } + } + + export { connect, disconnect }; \ No newline at end of file diff --git a/src/views/CNAS/resourceDemand/device/component/acquisitionConfig.vue b/src/views/CNAS/resourceDemand/device/component/acquisitionConfig.vue index 23a9e18..a8fa850 100644 --- a/src/views/CNAS/resourceDemand/device/component/acquisitionConfig.vue +++ b/src/views/CNAS/resourceDemand/device/component/acquisitionConfig.vue @@ -158,6 +158,10 @@ <div class="search_label">鏁版嵁搴撳瘑鐮侊細</div> <el-input size="small" placeholder="璇疯緭鍏�" clearable v-model="configForm.dbPassword"></el-input> </div> + <div v-if="configForm.fileType === '.mysql'" class="search_thing" style="margin-bottom: 14px;"> + <div class="search_label"><span style="color:red;margin-right: 4px;">*</span>鏁版嵁搴撹〃锛�</div> + <el-input size="small" placeholder="璇疯緭鍏�" clearable v-model="configForm.dbTable"></el-input> + </div> <span slot="footer" class="dialog-footer"> <el-row> <el-button @click="dialogVisible4 = false">鍙� 娑�</el-button> @@ -244,7 +248,8 @@ dbFileName: "", fiberOpticRibbon: "", dbUserName: "", - dbPassword: "" + dbPassword: "", + dbTable: "" }, domains: [ { @@ -266,6 +271,7 @@ { label: "excel", value: ".xlsx" }, { label: "excel", value: ".xls" }, { label: "txt", value: ".txt" }, + { label: "mysql", value: ".mysql" }, { label: "png", value: ".png" } ], spanList: [], @@ -417,7 +423,8 @@ this.$set(this.configForm, "dbFileName", res.data.dbFileName); this.$set(this.configForm, "fiberOpticRibbon", res.data.fiberOpticRibbon); this.$set(this.configForm, "dbUserName", res.data.dbUserName); - this.$set(this.configForm, "dbPassword", res.data.dbPassword) + this.$set(this.configForm, "dbPassword", res.data.dbPassword); + this.$set(this.configForm, "dbTable", res.data.dbTable); }) }, // 鎻愪氦鏂囦欢閰嶇疆 @@ -433,7 +440,8 @@ dbFileName: this.configForm.dbFileName, fiberOpticRibbon: this.configForm.fiberOpticRibbon, dbUserName: this.configForm.dbUserName, - dbPassword: this.configForm.dbPassword + dbPassword: this.configForm.dbPassword, + dbTable: this.configForm.dbTable }); this.upLoad4 = true; saveDeviceFileConfiguration({ deviceId: this.deviceId, ...obj }).then(res => { diff --git a/src/views/business/inspectionTask/inspection.vue b/src/views/business/inspectionTask/inspection.vue index f26bb54..b441fb0 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> @@ -536,6 +536,8 @@ 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, getCableTag, @@ -818,6 +820,7 @@ this.startWorker(); // this.getList0() // 浠诲姟鍒囨崲 this.scrollInit(); + disconnect() }, activated() { this.getTypeDicts(); // 鑾峰彇绱ф�ョ▼搴︿笅鎷夋閫夐」 @@ -897,6 +900,7 @@ beforeDestroy() { // 鍦ㄧ粍浠堕攢姣佸墠纭繚鍋滄 Worker锛岄伩鍏嶅唴瀛樻硠婕� this.stopWorker(); + disconnect() }, methods: { // 鏂囦欢绠$悊--寮�濮� @@ -1128,6 +1132,8 @@ }, // 鏁版嵁閲囬泦 getDataAcquisitionDevice() { + // connect() + // return let itemIds = []; this.currentSample.insProduct.forEach((item) => { if (item.inspectionItemType === "1") { @@ -2914,6 +2920,9 @@ this.$router.go(-1) } }, + destroyed() { + disconnect() + }, }; </script> <style scoped> -- Gitblit v1.9.3