ZengTao
2024-05-09 63574bf6cf94613385cb8d0e2c2beb1829f644b5
CanadaMes-ui/src/views/Electrical/Positioning1.vue
@@ -15,13 +15,8 @@
        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
@@ -29,7 +24,7 @@
        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
        >{{ $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"
@@ -110,7 +96,7 @@
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("InteractionState") }}</router-link
        >{{ $t("PLC-MES Info") }}</router-link
      >
    </el-breadcrumb>
@@ -145,15 +131,53 @@
                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' "
                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>
            <div class="button-row" style="display: flex; justify-content: space-between; flex-wrap: wrap;">
                <el-button
                  v-if="item.button"
                  v-model="item.button.value"
                  :name="item.button.name"
                  :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>
        </el-card>
@@ -167,6 +191,7 @@
let socket;
import LanguageMixin from "../../lang/LanguageMixin";
import data from "../../configuration/Positioning1";
import {SelectPassword} from "../../api/home";
export default {
  name: "Positioning1",
@@ -178,11 +203,12 @@
      A02:"",
      B01:"",
      B02:"",
      jianju:""
      password: 1,
      jianju: "",
    };
  },
  activated() {
    document.body.style.zoom = "90%";
    this.initWebSocket();
    const language = this.$i18n.locale;
    console.log(language);
@@ -190,47 +216,73 @@
      this.replaceChineseWithEnglish();
    }
    this.$forceUpdate();
    this.load();
  },
  methods: {
    updateButtonValue(dataGroup, itemIndex,groupIndex) {
    load(){
SelectPassword().then(res => {
          this.password = res.data.password;
          console.log(this.password)
      });
console.log(this.jsonData)
},
    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)
        console.log(value);
}
if(groupIndex==2){
  const value = parseFloat(this.A02) ;
  this.$set(dataGroup[itemIndex], "value", value); 
  console.log(value)
        console.log(value);
}
if(groupIndex==3){
  const value = parseFloat(this.A01) + parseFloat(this.jianju);
  this.$set(dataGroup[itemIndex], "value", value); 
  console.log(value)
        console.log(value);
}
if(groupIndex==4){
  const value=parseFloat(this.A02)+parseFloat(this.jianju)
        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)
        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)
        const value = parseFloat(this.B02) + parseFloat(this.jianju);
this.$set(dataGroup[itemIndex], "value", value); 
}
      
     this.submitDataToBackend(event);
    },
    //提交数据到后端
    submitDataToBackend(event) {
@@ -238,8 +290,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,9 +309,91 @@
      // 提交数据到后端
      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";
@@ -306,7 +438,7 @@
  if (!msg.data) {
    return; // 如果收到空数据,则直接返回,不执行后续逻辑
  }
  if (document.activeElement.tagName.toLowerCase() === 'input') {
          if (document.activeElement.tagName.toLowerCase() === "input") {
    return;
  }
@@ -315,7 +447,8 @@
  const parms = obj.params;
  if(parms ){ // 只有在鼠标不在输入框内时才更新数据
          if (parms) {
            // 只有在鼠标不在输入框内时才更新数据
  //  console.log(parms)
   
    let index = 0;
@@ -333,9 +466,6 @@
      }
    }
                    this.A01 = obj.shishi1[0][0];
                    this.A02 = obj.shishi1[0][1];
@@ -345,14 +475,10 @@
                    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 () {
@@ -414,4 +540,11 @@
.blue-button {
  background-color: skyblue;
}
.op {
  background-color: #66b1ff;
}
.dow {
  background-color: #A0A0A0;
}
</style>