wuyouming666
2024-05-09 a78422827afcedefd5a0ca1d893198d48ea8062f
CanadaMes-ui/src/views/Electrical/Positioning1.vue
@@ -15,21 +15,16 @@
        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/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')
      }}</router-link> -->
        }}</router-link> -->
      <router-link
        to="/Electrical/Sign"
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("Sign") }}</router-link
        >{{ $t("I/O") }}</router-link
      >
      <router-link
        to="/Electrical/Servomanual"
@@ -46,7 +41,7 @@
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("Automatic State") }}</router-link
        >{{ $t("Glass Data") }}</router-link
      >
      <!-- <router-link
        to="/Electrical/ManualJog"
@@ -61,42 +56,33 @@
        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") }}</router-link
      > -->
      <!-- <router-link to="/Electrical/Parameter1" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter1')
      }}</router-link> -->
      <router-link
        to="/Electrical/Positioning1"
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("Address parameter settings") }}</router-link
        active-class="blue-button"
        >{{ $t("Cage Positions") }}</router-link
      >
      <!-- <router-link to="/Electrical/Positioning2" tag="el-button" type="text" active-class="blue-button">{{
        $t('Positioning2')
      }}</router-link> -->
      <!-- <router-link
        to="/Electrical/ManualonePosition2"
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("ManualonePosition2") }}</router-link
      > -->
      <!-- <router-link to="/Electrical/ManualonePosition2" tag="el-button" type="text" active-class="blue-button">{{
        $t('ManualonePosition2')
      }}</router-link> -->
      <router-link
        to="/Electrical/AutomaticParameterSetting"
        tag="el-button"
@@ -105,22 +91,22 @@
        >{{ $t("Speed parameter settings") }}</router-link
      >
      <router-link
      <router-link
        to="/Electrical/InteractionState"
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("InteractionState") }}</router-link
        >{{ $t("PLC-MES Info") }}</router-link
      >
    </el-breadcrumb>
    <el-row :gutter="18" class="card"  style="width: 1400px">
    <el-row :gutter="18" class="card" style="width: 1400px">
      <el-col
        :span="7"
        v-for="(dataGroup, groupIndex) in jsonData"
        :key="groupIndex"
      >
        <el-card class="json-block"   style="width: 400px">
        <el-card class="json-block" style="width: 400px">
          <div
            class="button-row"
            style="display: flex; justify-content: space-between"
@@ -145,15 +131,59 @@
                v-if="item.type === '0'"
                style="width: 120px"
                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+`}`"
                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 +
                  `}`
                "
                @keyup.enter.native="submitDataToBackend($event)"
              ></el-input>
              <span v-if="item.unit" :name="item.unit">{{ item.unit }}</span>
              <el-button
                v-if="item.type === '0'  && item.name !== '格子间距'  && item.name !== 'GridSpacing' "
              <el-button
                v-if="
                  item.type === '0' &&
                  item.name !== '格子间距' &&
                  item.name !== 'GridSpacing'
                "
                class="input-box"
                @click="updateButtonValue(dataGroup, itemIndex, groupIndex)"
                >{{ $t("Set") }}</el-button
              >
                class="input-box" @click="updateButtonValue(dataGroup, itemIndex,groupIndex);">{{ $t("Set") }}</el-button>
              <div
                class="button-row"
                style="
                  display: flex;
                  justify-content: flex-start;
                  flex-wrap: wrap;
                "
              >
                <el-button
                  v-if="item.button"
                  v-model="item.button.value"
                  :name="item.button.name"
                  style="width: 160px"
                  :class="{
                    dow: item.button.value === 0,
                    op: item.button.value === 1,
                  }"
                  class="action-button"
                  @click="
                    updateButtonValue2(dataGroup, itemIndex);
                    submitDataToBackend2(item.button.name);
                  "
                >
                  {{ item.button.name }}
                </el-button>
              </div>
            </div>
          </div>
        </el-card>
@@ -167,6 +197,7 @@
let socket;
import LanguageMixin from "../../lang/LanguageMixin";
import data from "../../configuration/Positioning1";
import {SelectPassword} from "../../api/home";
export default {
  name: "Positioning1",
@@ -174,15 +205,16 @@
  data() {
    return {
      jsonData: data, // 加载整个data.json文件作为jsonData
      A01:"",
      A02:"",
      B01:"",
      B02:"",
      jianju:""
      A01: "",
      A02: "",
      B01: "",
      B02: "",
      password: 1,
      jianju: "",
    };
  },
  activated() {
    document.body.style.zoom = "90%";
    this.initWebSocket();
    const language = this.$i18n.locale;
    console.log(language);
@@ -190,47 +222,73 @@
      this.replaceChineseWithEnglish();
    }
    this.$forceUpdate();
    this.load();
  },
  methods: {
    updateButtonValue(dataGroup, itemIndex,groupIndex) {
    load(){
      if(groupIndex==1){
  const value = parseFloat(this.A01);
SelectPassword().then(res => {
          this.password = res.data.password;
          console.log(this.password)
      });
  this.$set(dataGroup[itemIndex], "value", value);
  console.log(value)
}
if(groupIndex==2){
  const value = parseFloat(this.A02) ;
  this.$set(dataGroup[itemIndex], "value", value);
  console.log(value)
}
if(groupIndex==3){
  const value = parseFloat(this.A01) + parseFloat(this.jianju);
  this.$set(dataGroup[itemIndex], "value", value);
  console.log(value)
}
if(groupIndex==4){
  const value=parseFloat(this.A02)+parseFloat(this.jianju)
this.$set(dataGroup[itemIndex], "value", value);
}
if(groupIndex==5){
  const value=parseFloat(this.B01)-parseFloat(this.jianju)
console.log(this.jsonData)
this.$set(dataGroup[itemIndex], "value", value);
}
if(groupIndex==6){
  const value=parseFloat(this.B02)+parseFloat(this.jianju)
this.$set(dataGroup[itemIndex], "value", value);
}
      
     this.submitDataToBackend(event);
},
    updateButtonValue2 (dataGroup, itemIndex) {
      if (dataGroup[itemIndex].button.value2 === 0) {
    // 如果当前按钮的值是 0,将其设为 1
    this.$set(dataGroup[itemIndex].button, 'value2', 1);
  } else {
    // 否则将其设为 0
    this.$set(dataGroup[itemIndex].button, 'value2', 0);
  }
    },
    updateButtonValue(dataGroup, itemIndex, groupIndex) {
      if (groupIndex == 1) {
        const value = parseFloat(this.A01);
        this.$set(dataGroup[itemIndex], "value", value);
        console.log(value);
      }
      if (groupIndex == 2) {
        const value = parseFloat(this.A02);
        this.$set(dataGroup[itemIndex], "value", value);
        console.log(value);
      }
      if (groupIndex == 3) {
        const value = parseFloat(this.A01) + parseFloat(this.jianju);
        this.$set(dataGroup[itemIndex], "value", value);
        console.log(value);
      }
      if (groupIndex == 4) {
        const value = parseFloat(this.A02) + parseFloat(this.jianju);
        this.$set(dataGroup[itemIndex], "value", value);
      }
      if (groupIndex == 5) {
        const value = parseFloat(this.B01) - parseFloat(this.jianju);
        this.$set(dataGroup[itemIndex], "value", value);
      }
      if (groupIndex == 6) {
        const value = parseFloat(this.B02) + parseFloat(this.jianju);
        this.$set(dataGroup[itemIndex], "value", value);
      }
      this.submitDataToBackend(event);
    },
    //提交数据到后端
    submitDataToBackend(event) {
@@ -238,8 +296,6 @@
        return dataGroup.map((item) => {
          if (item.type === "0") {
            return { value: parseInt(item.value) };
          } else if (item.button) {
            return { value: parseInt(item.title.value) };
          }
          return null;
        });
@@ -259,10 +315,92 @@
      // 提交数据到后端
      const jsonString = JSON.stringify(jsonObject);
       console.log('提交以下数据到后端:', jsonString);
      this.$prompt(
    this.$t('Are you sure to perform this operation?'),
    this.$t('prompt'),
    {
      inputType: 'password',
      inputPlaceholder: this.$t('Please enter the password'),
      confirmButtonText: this.$t('Yes'),
      cancelButtonText: this.$t('No'),
      type: 'warning',
    }
  ).then(({ value }) => {
    // 验证密码是否正确
    if (value !== this.password) {
      this.$message.error(this.$t('Incorrect password'));
      return ;
    }else{
      console.log("提交以下数据到后端:", jsonString);
      socket?.send(jsonString);
    }
  }).catch(() => {
    // 取消操作
    console.log('取消1');
  });
      event.target.blur(); // 取消输入框焦点
    },
    submitDataToBackend2 (currentButtonName) {
if (currentButtonName ===   'A01 Calibration Pos' || currentButtonName === 'A02 Calibration Pos' || currentButtonName === 'A01原点记忆' || currentButtonName === 'A02原点记忆') {
  this.$prompt(
    this.$t('Are you sure to perform this operation?'),
    this.$t('prompt'),
    {
      inputType: 'password',
      inputPlaceholder: this.$t('Please enter the password'),
      confirmButtonText: this.$t('Yes'),
      cancelButtonText: this.$t('No'),
      type: 'warning',
    }
  ).then(({ value }) => {
    // 验证密码是否正确
    if (value !== this.password) {
      this.$message.error(this.$t('Incorrect password'));
      return;
    }
    // 密码正确,继续提交数据到后端
    const inputData = this.jsonData.map(dataGroup => {
      return dataGroup.map(item => {
        if (item.type === '1'&& item.button) {
          return { value: item.button.value2 };
        }
        return null;
      });
    });
    const values = inputData.flat().filter(item => item !== null).map(item => item.value);
    const data = [];
    data.push(values);
     data.unshift([], [], [],[],[],[],[]);
    const jsonObject = { data };
    // 提交数据到后端
    const jsonString = JSON.stringify(jsonObject);
    console.log('Type为3的value:', jsonString);
    socket?.send(jsonString);
  }).catch(() => {
    // 取消操作
    console.log('取消1');
  });
} else {
  console.log('取消2');
}
},
    initWebSocket() {
      let viewname = "Positioning1";
@@ -290,69 +428,63 @@
        };
        // 收到消息
//         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;
  }
        socket.onmessage = (msg) => {
          if (!msg.data) {
            return; // 如果收到空数据,则直接返回,不执行后续逻辑
          }
          if (document.activeElement.tagName.toLowerCase() === "input") {
            return;
          }
  let obj = JSON.parse(msg.data);
  const jsonData2 = this.jsonData;
          let obj = JSON.parse(msg.data);
          const jsonData2 = this.jsonData;
  const parms = obj.params;
          const parms = obj.params;
  if(parms ){ // 只有在鼠标不在输入框内时才更新数据
  //  console.log(parms)
    let index = 0;
    for (let i = 0; i < jsonData2.length; i++) {
      let arr = jsonData2[i];
      for (let j = 0; j < arr.length; j++) {
        let obj = arr[j];
        if (
          obj.type === "0" &&
          Object.prototype.hasOwnProperty.call(obj, "value")
        ) {
          obj.value = parms[0][index];
          index++;
        }
      }
    }
          if (parms) {
            // 只有在鼠标不在输入框内时才更新数据
            //  console.log(parms)
            let index = 0;
            for (let i = 0; i < jsonData2.length; i++) {
              let arr = jsonData2[i];
              for (let j = 0; j < arr.length; j++) {
                let obj = arr[j];
                if (
                  obj.type === "0" &&
                  Object.prototype.hasOwnProperty.call(obj, "value")
                ) {
                  obj.value = parms[0][index];
                  index++;
                }
              }
            }
                    this.A01 = obj.shishi1[0][0];
            this.A01 = obj.shishi1[0][0];
                    this.A02 = obj.shishi1[0][1];
                    this.B01= obj.shishi1[0][2];
            this.A02 = obj.shishi1[0][1];
                    this.B02 = obj.shishi1[0][3];
                    this.jianju = obj.params[0][0];
            this.B01 = obj.shishi1[0][2];
            this.B02 = obj.shishi1[0][3];
            this.jianju = obj.params[0][0];
  }
};
            jsonData2[7][0].button.value = obj.PLCOriginmarkingarraylist[0][0];
          jsonData2[7][1].button.value = obj.PLCOriginmarkingarraylist[0][1];
          }
        };
        // 关闭事件
        socket.onclose = function () {