From 54c7981d6f05ce0e3b59df3c4e23cd06a81a059b Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期四, 14 十二月 2023 09:15:01 +0800
Subject: [PATCH] 后端代码改为大部分使用消息处理对象写入

---
 CanadaMes-ui/src/views/Electrical/ServoManualone.vue |  131 +++++++++++--------------------------------
 1 files changed, 33 insertions(+), 98 deletions(-)

diff --git a/CanadaMes-ui/src/views/Electrical/ServoManualone.vue b/CanadaMes-ui/src/views/Electrical/ServoManualone.vue
index 148a9ca..10525dd 100644
--- a/CanadaMes-ui/src/views/Electrical/ServoManualone.vue
+++ b/CanadaMes-ui/src/views/Electrical/ServoManualone.vue
@@ -213,84 +213,36 @@
 
 },
 submitDataToBackend(currentButtonName) {
+  const data = [];
+  let jsonObject;
 
-//A01鍗婅嚜鍔ㄥ惎鍔ㄦ彁浜�
-  if (currentButtonName === 'A01鍗婅嚜鍔ㄥ惎鍔�' ||currentButtonName === 'A01 Semi-Auto Start') {
-    const data = [];
-
-
-  const values = [this.jsonData[0][10].button.value]
-
-  data.push(values);
- 
-
-data.unshift([], [],[],[], [],[],[], []);
-
-
-const jsonObject = { data };
-
-// 鎻愪氦鏁版嵁鍒板悗绔�
-const jsonString = JSON.stringify(jsonObject);
-console.log('鎵�鏈塗ype涓�0鐨剉alue:', jsonString);
-socket?.send(jsonString);
-
-  }
-  //A02鍗婅嚜鍔ㄥ惎鍔� 鎻愪氦
-
-  if (currentButtonName === 'A02鍗婅嚜鍔ㄥ惎鍔�' ||currentButtonName === 'A02 Semi-Auto Start') {
-    const data2 = [];
-
-    const values2 = [this.jsonData[1][8].button.value]
-
-  data2.push(values2);
-
-  data2.unshift([],[], [],[],[], [],[],[], []);
-
-
-
-
-
-const jsonObject = { data:data2 };
-
-// 鎻愪氦鏁版嵁鍒板悗绔�
-const jsonString = JSON.stringify(jsonObject);
-console.log('鎵�鏈塗ype涓�0鐨剉alue:', jsonString);
-socket?.send(jsonString);
-
+  if (currentButtonName === 'A01鍗婅嚜鍔ㄥ惎鍔�' || currentButtonName === 'A01 Semi-Auto Start') {
+    const values = [this.jsonData[0][10].button.value];
+    data.push(values);
+    data.unshift([], [],[],[], [],[],[], []);
+    jsonObject = { data };
   }
 
-  //澶嶄綅鎻愪氦
+  if (currentButtonName === 'A02鍗婅嚜鍔ㄥ惎鍔�' || currentButtonName === 'A02 Semi-Auto Start') {
+    const values2 = [this.jsonData[1][8].button.value];
+    data.push(values2);
+    data.unshift([],[], [],[],[], [],[],[], []);
+    jsonObject = { data };
+  }
 
   if (currentButtonName === '澶嶄綅' || currentButtonName === 'Reset') {
-  const data2 = [];
-  const resetButtonValues = this.jsonData.map(item => {
-    const buttonItem = item.find(subItem => subItem.button && ['澶嶄綅', 'Reset'].includes(subItem.button.name));
+    const resetButtonValues = this.jsonData
+      .map(item => item.find(subItem => subItem.button && ['澶嶄綅', 'Reset'].includes(subItem.button.name)))
+      .filter(value => value !== null)
+      .map(item => item.button.value);
 
-    
-    return buttonItem ? buttonItem.button.value : null;
-  }).filter(value => value !== null);
+    data.push(resetButtonValues.flat());
+    data.unshift([], []);
+    data.push([], [], [], [], []);
+    jsonObject = { data };
+  }
 
-  // 灏嗗緱鍒扮殑鍊兼坊鍔犲埌 data 鏁扮粍涓�
-  data2.push(resetButtonValues.flat());
-
-  // 鍦� data2 鏁扮粍鍓嶉潰娣诲姞涓や釜绌烘暟缁�
-  data2.unshift([], []);
-  data2.push([], [], [], [], []);
-
-  // 鍒涘缓 jsonObject2 瀵硅薄锛屽苟娣诲姞 data2 灞炴��
-  const jsonObject2 = { data: data2 };
-
-  // 鎻愪氦鏁版嵁鍒板悗绔�
-  const jsonString2 = JSON.stringify(jsonObject2);
-  console.log('鎵�鏈塗ype涓�0鐨剉alue:', jsonString2);
-  socket?.send(jsonString2);
-  // setTimeout(()=>
-  //   window.location.reload(),2000
-  // )
- 
-}
-////鍥為浂鎻愪氦
-if (currentButtonName === '鍥為浂' || currentButtonName === 'Home') {
+  if (currentButtonName === '鍥為浂' || currentButtonName === 'Home') {
   const data3 = [];
   const resetButtonValues3 = this.jsonData.map(item => {
     const buttonItem3 = item.find(subItem => subItem.button && ['鍥為浂', 'Home'].includes(subItem.button.name));
@@ -306,22 +258,10 @@
   data3.push([], [], [], []);
 
   // 鍒涘缓 jsonObject3 瀵硅薄锛屽苟娣诲姞 data3 灞炴��
-  const jsonObject3 = { data: data3 };
+   jsonObject = { data: data3 };
 
-  // 鎻愪氦鏁版嵁鍒板悗绔�
-  const jsonString3 = JSON.stringify(jsonObject3);
-  console.log('鍥為浂:', jsonString3);
-  socket?.send(jsonString3);
-  // setTimeout(()=>
-  //   window.location.reload(),2000
-  // )
+
 }
-
-
-
-
-//A01鍗婅嚜鍔ㄦ彁浜�
-
   if (currentButtonName === 'A01鍗婅嚜鍔�' || currentButtonName === 'A01 Semi-Auto' ) {
     const elements = document.getElementsByClassName('special-class');
     const data = [];
@@ -379,12 +319,9 @@
 
 
 
-const jsonObject = { data };
+ jsonObject = { data };
 
 // 鎻愪氦鏁版嵁鍒板悗绔�
-const jsonString = JSON.stringify(jsonObject);
-console.log('鎵�鏈塗ype涓�0鐨剉alue:', jsonString);
-socket?.send(jsonString);
 
   }
 
@@ -449,20 +386,18 @@
     data.unshift([],[],[],[],[],[],[]);
 
 
-const jsonObject = { data };
+ jsonObject = { data };
 
-// 鎻愪氦鏁版嵁鍒板悗绔�
-const jsonString = JSON.stringify(jsonObject);
-console.log('鎵�鏈塗ype涓�0鐨剉alue:', jsonString);
-socket?.send(jsonString);
 
-  }
 
  
+}
 
-  
+const jsonString = JSON.stringify(jsonObject);
+  console.log('鎵�鏈塗ype涓�0鐨剉alue:', jsonString);
+  socket?.send(jsonString);
+
 },
-
 
     initWebSocket () {
  
@@ -493,7 +428,7 @@
   }
 
   let obj = JSON.parse(msg.data);
-   console.log(obj)
+  // console.log(obj)
 const weihuiling=obj.weihuiling;
   const jsonData2 = this.jsonData;
 

--
Gitblit v1.8.0