From a5a49ece3191bf8210c42b522503687cedb420c2 Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期二, 26 十二月 2023 16:55:40 +0800
Subject: [PATCH] 修改input通过光标焦点是否在input内控制是否更新数据,回车下发参数让input失去焦点更新数据

---
 CanadaMes-ui/src/views/Electrical/ManualonePosition2.vue |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/CanadaMes-ui/src/views/Electrical/ManualonePosition2.vue b/CanadaMes-ui/src/views/Electrical/ManualonePosition2.vue
index 938c04f..636b9d0 100644
--- a/CanadaMes-ui/src/views/Electrical/ManualonePosition2.vue
+++ b/CanadaMes-ui/src/views/Electrical/ManualonePosition2.vue
@@ -51,11 +51,11 @@
                 <el-input style="width:250px;" v-else-if="item.state != 0 && item.type === '0' && groupIndex === 1 && (itemIndex === 2)"  readonly v-model="item.value"
                 class="input-box"   :oninput="`value=value.replace(/^0|[^0-9]/g,'');if(value<`+item.min+`){value=`+item.value+`}else if(value>`+item.max+`){value=`+item.value+`}`"></el-input>
 
-                <el-input style="width:250px;" v-else-if="item.state != 0 && item.type === '0' && groupIndex === 0 "   v-model="item.value"  @keyup.enter.native="A01start"
+                <el-input style="width:250px;" v-else-if="item.state != 0 && item.type === '0' && groupIndex === 0 "   v-model="item.value"  @keyup.enter.native="A01start($event)"
                 class="input-box"   :oninput="`value=value.replace(/^0|[^0-9]/g,'');if(value<`+item.min+`){value=`+item.value+`}else if(value>`+item.max+`){value=`+item.value+`}`"></el-input>
 
 
-                <el-input style="width:250px;" v-else-if="item.state != 0 && item.type === '0' && groupIndex === 1 "  v-model="item.value" @keyup.enter.native="A02start"
+                <el-input style="width:250px;" v-else-if="item.state != 0 && item.type === '0' && groupIndex === 1 "  v-model="item.value" @keyup.enter.native="A02start($event)"
                 class="input-box"   :oninput="`value=value.replace(/^0|[^0-9]/g,'');if(value<`+item.min+`){value=`+item.value+`}else if(value>`+item.max+`){value=`+item.value+`}`"></el-input>
 
 
@@ -133,7 +133,7 @@
     },
 
 
-    A01start(){
+    A01start(event){
       const data = [];
 
 for (let i = 0; i < 1; i++) {
@@ -155,10 +155,10 @@
 const jsonString = JSON.stringify(jsonObject);
 console.log('鎵�鏈塗ype涓�0鐨剉alue:', jsonString);
 socket?.send(jsonString);
-
+event.target.blur(); // 鍙栨秷杈撳叆妗嗙劍鐐�
 
     },
-    A02start(){
+    A02start(event){
 
       const data = [];
 
@@ -180,6 +180,7 @@
 const jsonString = JSON.stringify(jsonObject);
 console.log('鎵�鏈塗ype涓�0鐨剉alue:', jsonString);
 socket?.send(jsonString);
+event.target.blur(); // 鍙栨秷杈撳叆妗嗙劍鐐�
     },
     //鎻愪氦鏂规硶
     submitDataToBackend (currentButtonName) {
@@ -318,22 +319,27 @@
         };
 
         // 鏀跺埌娑堟伅
-        let isMouseInInputBox = false; // 鏍囪榧犳爣鏄惁鍦ㄨ緭鍏ユ鍐�
+//         let isMouseInInputBox = false; // 鏍囪榧犳爣鏄惁鍦ㄨ緭鍏ユ鍐�
 
-const inputBox = document.querySelectorAll('.input-box');
-inputBox.forEach(box => {
-  box.addEventListener('mouseenter', () => {
-    isMouseInInputBox = true;
-  });
-  box.addEventListener('mouseleave', () => {
-    isMouseInInputBox = false;
-  });
-});
+// const inputBox = document.querySelectorAll('.input-box');
+// inputBox.forEach(box => {
+//   box.addEventListener('mouseenter', () => {
+//     isMouseInInputBox = true;
+//   });
+//   box.addEventListener('mouseleave', () => {
+//     isMouseInInputBox = false;
+//   });
+// });
 
 socket.onmessage = (msg) => {
   if (!msg.data) {
     return; // 濡傛灉鏀跺埌绌烘暟鎹紝鍒欑洿鎺ヨ繑鍥烇紝涓嶆墽琛屽悗缁�昏緫
   }
+
+  if (document.activeElement.tagName.toLowerCase() === 'input') {
+    return;
+  }
+
 
           let obj = JSON.parse(msg.data);
           // console.log(obj)
@@ -343,7 +349,7 @@
 
 
             
-            if (obj.zuhe1&& !isMouseInInputBox ) {
+            if (obj.zuhe1 ) {
               // 鎵ц鏇存柊閫昏緫
               for (let i = 0; i < 2; i++) {
                 jsonData2[i].forEach((item, index) => {

--
Gitblit v1.8.0