ZengTao
2024-05-10 e808f9e89ad6bd5d252e1aad42daa676b481b0ca
CanadaMes-ui/src/views/Electrical/Positioning1.vue
@@ -8,35 +8,30 @@
        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/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"
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("Parameter") }}</router-link
        >{{ $t("Manual/Automatic") }}</router-link
      >
    </el-breadcrumb>
@@ -46,57 +41,48 @@
        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") }}</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"
@@ -104,15 +90,23 @@
        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>
    <el-row :gutter="18" class="card">
    <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">
        <el-card class="json-block" style="width: 400px">
          <div
            class="button-row"
            style="display: flex; justify-content: space-between"
@@ -135,28 +129,96 @@
              <span class="name" style="width: 250px">{{ item.name }}</span>
              <el-input
                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+`}`"
                @keyup.enter.native="submitDataToBackend"
                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 !== '出片接片地址' && item.name !== '存片接片地址'"
                class="input-box" @click="submitDataToBackend();">取地址</el-button> -->
              <el-button
                v-if="
                  item.type === '0' &&
                  item.name !== '格子间距' &&
                  item.name !== 'GridSpacing'
                "
                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>
      </el-col>
    </el-row>
    <!-- <el-button @click="submitDataToBackend">提交数据到后端</el-button> -->
    <div>
    <el-dialog
      :visible="isPromptVisible"
      title="Prompt"
      width="30%"
      :close-on-click-modal="false"
      @close="handleCloseDialog"
    >
      <el-input v-model="password2" type="password" :placeholder="$t('Please enter the password')"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">{{ $t('Home') }}</el-button>
        <el-button type="primary" @click="handleConfirm">{{ $t('Confirm') }}</el-button>
      </span>
    </el-dialog>
  </div>
  </div>
</template>
  
<script>
let socket;
import LanguageMixin from "../../lang/LanguageMixin";
import data from "../../configuration/Positioning1";
import {SelectPassword} from "../../api/home";
export default {
  name: "Positioning1",
@@ -164,9 +226,20 @@
  data() {
    return {
      jsonData: data, // 加载整个data.json文件作为jsonData
      A01: "",
      A02: "",
      B01: "",
      B02: "",
      password:"" ,
      password2:"" ,
      jianju: "",
      isPromptVisible: false,
    };
  },
  activated() {
    document.body.style.zoom = "90%";
    this.initWebSocket();
    const language = this.$i18n.locale;
    console.log(language);
@@ -174,19 +247,149 @@
      this.replaceChineseWithEnglish();
    }
    this.$forceUpdate();
    this.load();
// 调用函数,显示密码输入对话框
this.showPasswordPrompt();
  },
  methods: {
    updateButtonValue(dataGroup, itemIndex) {
      this.$set(dataGroup[itemIndex].button, "value", 1); // 点击按钮后将值改为1
    showPasswordPrompt() {
      this.isPromptVisible = true;
    },
    handleCancel() {
      this.$router.push('/home');
      this.isPromptVisible = false;
    },
    handleConfirm() {
      // 验证密码并执行相应操作
      if (this.password === this.password2) {
        // 密码正确,执行操作
        console.log('Password correct, perform operation');
        this.$message.success(this.$t('success password'));
        this.isPromptVisible = false;
        this.password2="";
        // 在这里执行你的操作
      } else {
        this.$message.error(this.$t('Incorrect password'));
        this.showPasswordPrompt();
      }
    },
    handleCloseDialog() {
      // 在这里处理弹框关闭事件,如果需要的话
      console.log('Dialog closed');
    },
  //   showPasswordPrompt() {
  //   // 显示遮罩层
  //   this.isPromptVisible = true;
  //   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'),
  //       showClose: false, // 不显示右上角的关闭按钮
  //       showCancelButton: false, // 不显示取消按钮
  //       type: 'warning',
  //     }
  //   ).then(({ value }) => {
  //     // 验证密码是否正确
  //     if (value !== this.password) {
  //       this.$message.error(this.$t('Incorrect password'));
  //       // 不关闭对话框,重新触发密码输入对话框
  //       this.showPasswordPrompt();
  //     } else {
  //       // 密码正确,执行操作
  //       // 这里可以添加你想要执行的操作
  //       // 如果没有操作,可以省略这个 else 代码块
  //     }
  //   }).catch(() => {
  //     // 如果用户取消操作,也不做任何处理
  //     console.log('取消1');
  //   }).finally(() => {
  //     // 关闭遮罩层
  //     this.isPromptVisible = false;
  //   });
  // },
    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);
      }
      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() {
    submitDataToBackend(event) {
      const inputData = this.jsonData.map((dataGroup) => {
        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;
        });
@@ -206,9 +409,66 @@
      // 提交数据到后端
      const jsonString = JSON.stringify(jsonObject);
       console.log('提交以下数据到后端:', jsonString);
  console.log("提交以下数据到后端:", jsonString);
      socket?.send(jsonString);
      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";
@@ -236,48 +496,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; // 如果收到空数据,则直接返回,不执行后续逻辑
  }
        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 && !isMouseInInputBox){ // 只有在鼠标不在输入框内时才更新数据
  //  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.A02 = obj.shishi1[0][1];
            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 () {
@@ -339,4 +614,11 @@
.blue-button {
  background-color: skyblue;
}
.op {
  background-color: #66b1ff;
}
.dow {
  background-color: #A0A0A0;
}
</style>