From 093615ab71eebddeea28a74a6c21898fc929450f Mon Sep 17 00:00:00 2001 From: yaowanxin <3588231647@qq.com> Date: 星期一, 04 八月 2025 14:43:22 +0800 Subject: [PATCH] 判断检测项,调整请求 --- src/views/CNAS/resourceDemand/device/component/acquisitionConfig.vue | 4 src/utils/connect.js | 126 +++++++++++++++++++----------------------- src/views/business/inspectionTask/inspection.vue | 25 +++++--- 3 files changed, 75 insertions(+), 80 deletions(-) diff --git a/src/utils/connect.js b/src/utils/connect.js index 251a15e..f5899fb 100644 --- a/src/utils/connect.js +++ b/src/utils/connect.js @@ -4,24 +4,12 @@ let reader = null; let accumulatedData = ""; // 绉诲埌鍏ㄥ眬锛屼究浜庡叧闂椂閲嶇疆 let weightList = []; // 鐢ㄤ簬瀛樺偍閲嶉噺鍊肩殑鍒楄〃 - - async function sendWeightsToBackend(weights) { - try { - // 浣跨敤 await 绛夊緟 request 鍑芥暟杩斿洖缁撴灉 - const response = await request({ - url: "/weight/handleWeights", - method: "POST", - data: weights, // 閫氬父 request 鍑芥暟浣跨敤 data 瀛楁浼犻�掓暟鎹� - }); - // 鏍规嵁 request 鍑芥暟鐨勫疄鐜板垽鏂搷搴旀槸鍚︽垚鍔� - if (response.code !== 200) { // 鍋囪 response 鏈� code 瀛楁锛�200 琛ㄧず鎴愬姛 - throw new Error(`Backend response error: ${response.message}`); - } - return response.data; // 鍋囪鍝嶅簲鏁版嵁鍦� data 瀛楁涓� - } catch (error) { - console.error('鍙戦�侀噸閲忔暟鎹埌鍚庣澶辫触:', error); - throw error; - } + export function sendWeightsToBackend(weights) { + return request({ + url: "/weight/handleWeights", + method: "POST", + data: weights, + }); } async function connect() { @@ -49,66 +37,66 @@ console.error("涓插彛閿欒:", error); } } - function processAccumulatedData(data) { + function processAccumulatedData(data) { - if (data.includes("\n")) { - const messages = data.split("\n"); + 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); - // 鎻愬彇鏁板�� - const weightValue = extractWeightValue(completeMessage); - if (!isNaN(weightValue)) { - console.log("鎻愬彇鐨勯噸閲忓��:", weightValue); - // 灏嗘湁鏁堥噸閲忓�兼坊鍔犲埌鍒楄〃 - weightList.push(weightValue); + for (let i = 0; i < messages.length - 1; i++) { + const completeMessage = messages[i]; + console.log("瀹屾暣娑堟伅:", completeMessage); + // 鎻愬彇鏁板�� + const weightValue = extractWeightValue(completeMessage); + if (!isNaN(weightValue)) { + console.log("鎻愬彇鐨勯噸閲忓��:", weightValue); + // 灏嗘湁鏁堥噸閲忓�兼坊鍔犲埌鍒楄〃 + weightList.push(weightValue); - // 褰撳垪琛ㄩ暱搴﹁揪鍒� 6 鏃讹紝鍙戦�佹暟鎹埌鍚庣骞舵竻绌哄垪琛� - if (weightList.length === 6) { - sendWeightsToBackend({ - weights: weightList - }) - .then(() => { - console.log('鏁版嵁鍙戦�佹垚鍔�'); - weightList = []; - }) - .catch(() => { - console.log('鍙戦�佸け璐ワ紝淇濈暀鏁版嵁寰呴噸璇�'); - }); - } + // 褰撳垪琛ㄩ暱搴﹁揪鍒� 6 鏃讹紝鍙戦�佹暟鎹埌鍚庣骞舵竻绌哄垪琛� + if (weightList.length === 6) { + sendWeightsToBackend({ + weights: weightList + }) + .then(() => { + console.log('鏁版嵁鍙戦�佹垚鍔�'); + weightList = []; + }) + .catch(() => { + console.log('鍙戦�佸け璐ワ紝淇濈暀鏁版嵁寰呴噸璇�'); + }); } } - - 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; - } - */ + 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; + } + */ } + // 鏂板鎻愬彇閲嶉噺鏁板�肩殑鏂规硶 function extractWeightValue(message) { // 鍖归厤鏁板�奸儴鍒嗭紝鍙鐞嗘璐熷彿 diff --git a/src/views/CNAS/resourceDemand/device/component/acquisitionConfig.vue b/src/views/CNAS/resourceDemand/device/component/acquisitionConfig.vue index 3857916..7be6506 100644 --- a/src/views/CNAS/resourceDemand/device/component/acquisitionConfig.vue +++ b/src/views/CNAS/resourceDemand/device/component/acquisitionConfig.vue @@ -268,8 +268,8 @@ { label: "db", value: ".db" }, { label: "mdb", value: ".mdb" }, { label: "word", value: ".docx" }, - { label: "excel", value: ".xlsx" }, - { label: "excel", value: ".xls" }, + { label: "excelxlsx", value: ".xlsx" }, + { label: "excelxls", value: ".xls" }, { label: "txt", value: ".txt" }, { label: "mysql", value: ".mysql" }, { label: "mqtt", value: ".mqtt" }, diff --git a/src/views/business/inspectionTask/inspection.vue b/src/views/business/inspectionTask/inspection.vue index d32723c..0d72b63 100644 --- a/src/views/business/inspectionTask/inspection.vue +++ b/src/views/business/inspectionTask/inspection.vue @@ -1152,17 +1152,24 @@ getDataAcquisitionDevice() { (async () => { try { - // 妫�鏌ユ槸鍚︽敮鎸� Web Serial API - if ('serial' in navigator) { - // 璇锋眰鍙敤涓插彛 - const ports = await navigator.serial.getPorts(); - if (ports.length > 0) { - await connect(); + // 妫�鏌ラ〉闈腑妫�娴嬮」鏄惁鍖呭惈瀵嗗害 + const hasDensityItem = this.currentSample.insProduct.some(item => { + // 鍋囪瀵嗗害鐩稿叧鐨勬娴嬮」鍚嶇О鍖呭惈 "瀵嗗害" 鍏抽敭瀛楋紝鍙寜闇�淇敼 + return item.inspectionItem && item.inspectionItem.includes('瀵嗗害'); + }); + if (hasDensityItem) { + // 妫�鏌ユ槸鍚︽敮鎸� 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('娌℃湁鍙敤鐨勪覆鍙�'); + console.log('褰撳墠娴忚鍣ㄤ笉鏀寔 Web Serial API'); } - } else { - console.log('褰撳墠娴忚鍣ㄤ笉鏀寔 Web Serial API'); } } catch (error) { console.error('妫�娴嬩覆鍙f椂鍑洪敊:', error); -- Gitblit v1.9.3