wuyouming666
2024-05-09 92dab966727b26c69a8a1d5839b064f7942895e8
CanadaMes-ui/src/views/Electrical/ServoManualone.vue
@@ -8,13 +8,13 @@
        active-class="blue-button"
        >{{ $t("Alarm") }}</router-link
      >
      <router-link
      <!-- <router-link
        to="/Electrical/State"
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("State") }}</router-link
      >
      > -->
      <!-- <router-link to="/Electrical/Action" tag="el-button" type="text" active-class="blue-button">{{ $t('Action')
        }}</router-link> -->
      <!-- <router-link to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter')
@@ -24,14 +24,14 @@
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("Sign") }}</router-link
        >{{ $t("I/O") }}</router-link
      >
      <router-link
        to="/Electrical/Servomanual"
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("Parameter") }}</router-link
        >{{ $t("Manual/Automatic") }}</router-link
      >
    </el-breadcrumb>
@@ -41,29 +41,29 @@
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("Automatic State") }}</router-link
        >{{ $t("Glass Data") }}</router-link
      >
      <router-link
      <!-- <router-link
        to="/Electrical/ManualJog"
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("ManualJog") }}</router-link
      >
      > -->
      <router-link
        to="/Electrical/ManualonePosition"
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("ManualonePosition") }}</router-link
        >{{ $t("Manual Control") }}</router-link
      >
      <router-link
        to="/Electrical/Servomanualone"
        tag="el-button"
        type="text"
        active-class="blue-button"
        active-class="blue-button" v-show="false"
        >{{ $t("Servomanualone") }}</router-link
      >
      <!-- <router-link to="/Electrical/Parameter1" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter1')
@@ -74,7 +74,7 @@
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("Address parameter settings") }}</router-link
        >{{ $t("Cage Positions") }}</router-link
      >
      <!-- <router-link to="/Electrical/Positioning2" tag="el-button" type="text" active-class="blue-button">{{
        $t('Positioning2')
@@ -89,6 +89,14 @@
        type="text"
        active-class="blue-button"
        >{{ $t("Speed parameter settings") }}</router-link
      >
      <router-link
        to="/Electrical/InteractionState"
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("PLC-MES Info") }}</router-link
      >
    </el-breadcrumb>
@@ -116,7 +124,7 @@
                  <el-input
                    v-if="item.type === '0' && groupIndex === 0"
                    v-model="item.value"
                    @keyup.enter.native="zuhe1"
                    @keyup.enter.native="zuhe1($event)"
                    class="input-box"
                    :class="{
                      'special-class': groupIndex === 0,
@@ -127,7 +135,7 @@
                  <el-input
                    v-else-if="item.type === '0' && groupIndex === 1"
                    v-model="item.value"
                    @keyup.enter.native="zuhe2"
                    @keyup.enter.native="zuhe2($event)"
                    class="input-box"
                    :class="{
                      'special-class': groupIndex === 0,
@@ -187,9 +195,9 @@
                  'error-button':
                    item.button.name === 'Fault' && item.button.value === 1,
                  'error-button2':
                    item.button.name === 'NotZero' && item.button.value === 0,
                    item.button.name === 'Homing Failure' && item.button.value === 1,
                  'error-button3':
                    item.button.name === 'Zero' && item.button.value === 1,
                    item.button.name === 'Homing Complete' && item.button.value === 0,
                  fuwei:
                    item.button.name === 'Reset' && item.button.value === 1,
                  huiling:
@@ -213,7 +221,7 @@
                    item.button.name === 'Abort/ResumeTasks' &&
                    item.button.value === 1,
                  yihuiling:
                    item.button.name === 'Zero' && item.button.value === 1,
                    item.button.name === 'Homing Complete' && item.button.value === 1,
                }"
                @click="
                  updateButtonValue(dataGroup, itemIndex);
@@ -230,9 +238,9 @@
                  'error-button':
                    item.button.name === '故障' && item.button.value === 1,
                  'error-button3':
                    item.button.name === '已回零' && item.button.value === 1,
                    item.button.name === '已回零' && item.button.value === 0,
                  'error-button2':
                    item.button.name === '未回零' && item.button.value === 0,
                    item.button.name === '未回零' && item.button.value === 1,
                  fuwei: item.button.name === '复位' && item.button.value === 1,
                  huiling:
                    item.button.name === '回零' && item.button.value === 1,
@@ -290,6 +298,7 @@
  },
  activated() {
    document.body.style.zoom = "90%";
    this.initWebSocket();
    const language = this.$i18n.locale;
    // console.log(language);
@@ -317,7 +326,7 @@
        this.$set(dataGroup[itemIndex].button, "value", 1);
      }
    },
    zuhe1() {
    zuhe1(event) {
      const data = [];
      for (let i = 0; i < 1; i++) {
@@ -328,7 +337,36 @@
          });
        const values = inputData.map((item) => item.value);
        // console.log(values)
        if (values.length > 0) {
if (!(values[1] == "1" || values[1] == "2")) {
  values.shift();
  this.$message.error("Out of range");
  return false;
}
// if (!(values[2] < "380" ) ) {
//   values.shift();
//   this.$message.error("Out of range");
//   return false;
// }
if (!(values[4] >= "1" && values[4]  <= "210")  && values[4]  !== "1000") {
  values.shift();
  this.$message.error("Out of range");
  return false;
}
if (!(values[5] >= "1" && values[5]  <= "210")  && values[5]  !== "1000") {
  values.shift();
  this.$message.error("Out of range");
  return false;
}
}
        data.push(values);
      }
@@ -342,8 +380,13 @@
          });
        const values = inputData.map((item) => item.value);
        data.push(values);
        const pattern = /^[\w ]{1,14}$/;   // 匹配长度为14的数字、字母、空格的组合
if (!pattern.test(values[0])) {
  values.shift();
  this.$message.error("Please enter a 14-character string.");
  return false;
}
       data.push(values);
      }
      data.push([], [], []);
@@ -353,8 +396,9 @@
      const jsonString = JSON.stringify(jsonObject);
      console.log("所有Type为0的value:", jsonString);
      socket?.send(jsonString);
      event.target.blur(); // 取消输入框焦点
    },
    zuhe2() {
    zuhe2(event) {
      const data2 = [];
      for (let i = 1; i < 2; i++) {
@@ -365,6 +409,29 @@
          });
        const values2 = inputData.map((item) => item.value);
        if (values2.length > 0) {
if (!(values2[1] >= "1" && values2[1]  <= "210")  && values2[1]  !== "1000") {
  values2.shift();
  this.$message.error("Out of range");
  return false;
}
if (!(values2[2] >= "1" && values2[2]  <= "210")  && values2[2]  !== "1000") {
  values2.shift();
  this.$message.error("Out of range");
  return false;
}
if (!(values2[3] == "1" || values2[3] == "2")) {
  values2.shift();
  this.$message.error("Out of range");
  return false;
}
}
        data2.push(values2);
      }
@@ -380,7 +447,12 @@
          });
        const values2 = inputData.map((item) => item.value);
        const pattern = /^[\w ]{1,14}$/;  // 匹配长度为14的数字、字母、空格的组合
if (!pattern.test(values2[0])) {
  values2.shift();
  this.$message.error("Please enter a 14-character string.");
  return false;
}
        data2.push(values2);
        data2.push([], [], []);
      }
@@ -391,6 +463,7 @@
      const jsonString = JSON.stringify(jsonObject);
      console.log("所有Type为0的value:", jsonString);
      socket?.send(jsonString);
      event.target.blur(); // 取消输入框焦点
    },
    submitDataToBackend(currentButtonName) {
      const data = [];
@@ -438,7 +511,7 @@
      }
      if (currentButtonName === "回零" || currentButtonName === "Home") {
        const data3 = [];
        const resetButtonValues3 = this.jsonData
          .map((item) => {
            const buttonItem3 = item.find(
@@ -451,14 +524,14 @@
          .filter((value) => value !== null);
        // 将得到的值添加到 data 数组中
        data3.push(resetButtonValues3.flat());
        data.push(resetButtonValues3.flat());
        // 在 data3 数组前面添加两个空数组
        data3.unshift([], [], []);
        data3.push([], [], [], []);
        data.unshift([], [], []);
        data.push([], [], [], []);
        // 创建 jsonObject3 对象,并添加 data3 属性
        jsonObject = { data: data3 };
        jsonObject = { data };
      }
      if (
        currentButtonName === "A01半自动" ||
@@ -593,6 +666,19 @@
      const jsonString = JSON.stringify(jsonObject);
      console.log("所有Type为0的value:", jsonString);
      socket?.send(jsonString);
      setTimeout(() => {
    const reversedData = data.map(values => values.map(value => {
      return   (!value || value === 0) ? 0 : 0 ;
    }));
    const reversedJsonObject = { data: reversedData };
    // 提交数据到后端
    const reversedJsonString = JSON.stringify(reversedJsonObject);
    console.log('反转后:', reversedJsonString);
    socket?.send(reversedJsonString);
  }, 1000);
    },
    initWebSocket() {
@@ -620,17 +706,17 @@
          console.log("websocket已打开");
        };
        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) {
@@ -641,8 +727,11 @@
          // console.log(obj)
          const weihuiling = obj.weihuiling;
          const jsonData2 = this.jsonData;
          if (document.activeElement.tagName.toLowerCase() === 'input') {
    return;
  }
          if (obj.zuhe1 && !isMouseInInputBox) {
          if (obj.zuhe1 ) {
            //启动按钮
            // 执行更新逻辑
@@ -699,19 +788,36 @@
            }
            // 复位更新
            for (let i = 0; i < jsonData2.length; i++) {
              let arr = jsonData2[i];
              for (let j = 0; j < arr.length; j++) {
                let obj2 = arr[j];
                if (
                  obj2.button &&
                  (obj2.button.name === "复位" || obj2.button.name === "Reset")
                ) {
                  obj2.button.value = obj.fuwei[0][i];
                  //  console.log(obj2.button.value)
                }
              }
            }
            // for (let i = 0; i < jsonData2.length; i++) {
            //   let arr = jsonData2[i];
            //   for (let j = 0; j < arr.length; j++) {
            //     let obj2 = arr[j];
            //     if (
            //       obj2.button &&
            //       (obj2.button.name === "复位" || obj2.button.name === "Reset")
            //     ) {
            //       obj2.button.value = obj.fuwei[0][i];
            //       //  console.log(obj2.button.value)
            //     }
            //   }
            // }
            // for (let i = 0; i < jsonData2.length; i++) {
            //   let arr = jsonData2[i];
            //   for (let j = 0; j < arr.length; j++) {
            //     let obj2 = arr[j];
            //     if (
            //       obj2.button &&
            //       (obj2.button.name === "回零" || obj2.button.name === "Home")
            //     ) {
            //       obj2.button.value = obj.huiling[0][i];
            //       //  console.log(obj2.button.value)
            //     }
            //   }
            // }
            //未回零更新
@@ -727,8 +833,8 @@
            // console.log(jsonData2[5][4].button.value)
            if (
              jsonData2[2][3].button.value === 1 &&
              (jsonData2[2][3].button.name === "NotZero" ||
              jsonData2[2][3].button.value === 0 &&
              (jsonData2[2][3].button.name === "Homing Failure" ||
                jsonData2[2][3].button.name === "未回零")
            ) {
              jsonData2[2][3].button.name = jsonData2[2][3].button.name.replace(
@@ -736,13 +842,13 @@
                "已回零"
              );
              jsonData2[2][3].button.name = jsonData2[2][3].button.name.replace(
                "NotZero",
                "Zero"
                "Homing Failure",
                "Homing Complete"
              );
            }
            if (
              jsonData2[3][3].button.value === 1 &&
              (jsonData2[3][3].button.name === "NotZero" ||
              jsonData2[3][3].button.value === 0 &&
              (jsonData2[3][3].button.name === "Homing Failure" ||
                jsonData2[3][3].button.name === "未回零")
            ) {
              jsonData2[3][3].button.name = jsonData2[3][3].button.name.replace(
@@ -750,13 +856,13 @@
                "已回零"
              );
              jsonData2[3][3].button.name = jsonData2[3][3].button.name.replace(
                "NotZero",
                "Zero"
                "Homing Failure",
                "Homing Complete"
              );
            }
            if (
              jsonData2[4][4].button.value === 1 &&
              (jsonData2[4][4].button.name === "NotZero" ||
              jsonData2[4][4].button.value === 0 &&
              (jsonData2[4][4].button.name === "Homing Failure" ||
                jsonData2[4][4].button.name === "未回零")
            ) {
              jsonData2[4][4].button.name = jsonData2[4][4].button.name.replace(
@@ -764,13 +870,13 @@
                "已回零"
              );
              jsonData2[4][4].button.name = jsonData2[4][4].button.name.replace(
                "NotZero",
                "Zero"
                "Homing Failure",
                "Homing Complete"
              );
            }
            if (
              jsonData2[5][4].button.value === 1 &&
              (jsonData2[5][4].button.name === "NotZero" ||
              jsonData2[5][4].button.value === 0 &&
              (jsonData2[5][4].button.name === "Homing Failure" ||
                jsonData2[5][4].button.name === "未回零")
            ) {
              jsonData2[5][4].button.name = jsonData2[5][4].button.name.replace(
@@ -778,14 +884,14 @@
                "已回零"
              );
              jsonData2[5][4].button.name = jsonData2[5][4].button.name.replace(
                "NotZero",
                "Zero"
                "Homing Failure",
                "Homing Complete"
              );
            }
            if (
              jsonData2[2][3].button.value === 0 &&
              (jsonData2[2][3].button.name === "Zero" ||
              jsonData2[2][3].button.value === 1 &&
              (jsonData2[2][3].button.name === "Homing Complete" ||
                jsonData2[2][3].button.name === "已回零")
            ) {
              jsonData2[2][3].button.name = jsonData2[2][3].button.name.replace(
@@ -793,13 +899,13 @@
                "未回零"
              );
              jsonData2[2][3].button.name = jsonData2[2][3].button.name.replace(
                "Zero",
                "NotZero"
                "Homing Complete",
                "Homing Failure"
              );
            }
            if (
              jsonData2[3][3].button.value === 0 &&
              (jsonData2[3][3].button.name === "Zero" ||
              jsonData2[3][3].button.value === 1 &&
              (jsonData2[3][3].button.name === "Homing Complete" ||
                jsonData2[3][3].button.name === "已回零")
            ) {
              jsonData2[3][3].button.name = jsonData2[3][3].button.name.replace(
@@ -807,13 +913,13 @@
                "未回零"
              );
              jsonData2[3][3].button.name = jsonData2[3][3].button.name.replace(
                "Zero",
                "NotZero"
                "Homing Complete",
                "Homing Failure"
              );
            }
            if (
              jsonData2[4][4].button.value === 0 &&
              (jsonData2[4][4].button.name === "Zero" ||
              jsonData2[4][4].button.value === 1 &&
              (jsonData2[4][4].button.name === "Homing Complete" ||
                jsonData2[4][4].button.name === "已回零")
            ) {
              jsonData2[4][4].button.name = jsonData2[4][4].button.name.replace(
@@ -821,13 +927,13 @@
                "未回零"
              );
              jsonData2[4][4].button.name = jsonData2[4][4].button.name.replace(
                "Zero",
                "NotZero"
                "Homing Complete",
                "Homing Failure"
              );
            }
            if (
              jsonData2[5][4].button.value === 0 &&
              (jsonData2[5][4].button.name === "Zero" ||
              jsonData2[5][4].button.value === 1 &&
              (jsonData2[5][4].button.name === "Homing Complete" ||
                jsonData2[5][4].button.name === "已回零")
            ) {
              jsonData2[5][4].button.name = jsonData2[5][4].button.name.replace(
@@ -835,8 +941,8 @@
                "未回零"
              );
              jsonData2[5][4].button.name = jsonData2[5][4].button.name.replace(
                "Zero",
                "NotZero"
                "Homing Complete",
                "Homing Failure"
              );
            }
          }