wuyouming666
2023-12-04 82c2df0968b099bd589936adc5b28c1ac4827a05
CanadaMes-ui/src/views/Electrical/Positioning1.vue
@@ -7,8 +7,8 @@
      }}</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 to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter')
      }}</router-link> -->
      <router-link to="/Electrical/Sign" tag="el-button" type="text" active-class="blue-button">{{ $t('Sign')
      }}</router-link>
      <router-link to="/Electrical/Servomanual" tag="el-button" type="text" active-class="blue-button">{{
@@ -22,16 +22,16 @@
      }}</router-link>
      <router-link to="/Electrical/Parameter1" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter1')
      }}</router-link>
      <!-- <router-link to="/Electrical/Parameter2" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter2')
          }}</router-link> -->
      <router-link to="/Electrical/Parameter2" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter2')
      }}</router-link>
      <router-link to="/Electrical/Positioning1" tag="el-button" type="text" active-class="blue-button">{{
        $t('Positioning1')
      }}</router-link>
      <router-link to="/Electrical/Positioning2" tag="el-button" type="text" active-class="blue-button">{{
        $t('Positioning2')
      }}</router-link>
      <router-link to="/Electrical/Manualoneposition" tag="el-button" type="text" active-class="blue-button">{{
        $t('Manualoneposition')
      <router-link to="/Electrical/ManualonePosition" tag="el-button" type="text" active-class="blue-button">{{
        $t('ManualonePosition')
      }}</router-link>
      <router-link to="/Electrical/ManualonePosition2" tag="el-button" type="text" active-class="blue-button">{{
        $t('ManualonePosition2')
@@ -44,8 +44,8 @@
      }}</router-link>
    </el-breadcrumb>
    <el-row :gutter="18">
      <el-col :span="7" v-for="(dataGroup, groupIndex) in jsonData" :key="groupIndex" class='card'>
    <el-row :gutter="18" class='card'>
      <el-col :span="7" v-for="(dataGroup, groupIndex) in jsonData" :key="groupIndex">
        <el-card class="json-block">
          <div class="button-row" style="display: flex; justify-content: space-between;">
            <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex">
@@ -55,8 +55,13 @@
          <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex" class="item-container">
            <div class="item-row">
              <span class="name" style="width:250px;">{{ item.name }}</span>
              <el-input v-if="item.type === '0'" v-model="item.value" class="input-box"></el-input>
              <el-button v-if="item.type === '0'" class="input-box" @click="submitDataToBackend();">取地址</el-button>
              <el-input v-if="item.type === '0'" v-model="item.value" class="input-box"      @keyup.enter.native="submitDataToBackend" ></el-input>
              <!-- <el-button
                v-if="item.type === '0' && item.name !== '格子间距' && item.name !== '出片接片地址' && item.name !== '存片接片地址'"
                class="input-box" @click="submitDataToBackend();">取地址</el-button> -->
            </div>
          </div>
@@ -80,11 +85,16 @@
      jsonData: data // 加载整个data.json文件作为jsonData
    }
  },
  created () {
    this.initWebSocket();
    console.log('jsonData:', this.jsonData);
  },
  activated(){
   this.initWebSocket ();
   const language = this.$i18n.locale;
  console.log(language);
  if (language === 'en-US') {
    this.replaceChineseWithEnglish();
  }
  this.$forceUpdate();
 },
  methods: {
    updateButtonValue (dataGroup, itemIndex) {
      this.$set(dataGroup[itemIndex].button, 'value', 1); // 点击按钮后将值改为1
@@ -115,7 +125,7 @@
      // 提交数据到后端
      const jsonString = JSON.stringify(jsonObject);
      console.log('提交以下数据到后端:', jsonString);
      // console.log('提交以下数据到后端:', jsonString);
      socket?.send(jsonString);
    },
    initWebSocket () {
@@ -149,29 +159,32 @@
          let obj = JSON.parse(msg.data);
          const jsonData2 = this.jsonData;
          document.addEventListener('mouseover', function (event) {
            const inputBox = document.querySelector('.card'); // 根据你的实际情况选择正确的选择器
            if (inputBox && !inputBox.contains(event.target)) {
            const inputBox = document.querySelectorAll('.el-card__body');
            const target = event.target;
            if (inputBox && Array.from(inputBox).every(box => !box.contains(target))) {
              // 如果鼠标不在输入框内,更新输入框的值
              // this.submitDataToBackend()
              const params = obj.params;
              const parms = obj.params;
              // console.log(parms)
              // this.submitDataToBackend()
              let currentIndex = 0;
              jsonData2.forEach((group, groupIndex) => {
                group.forEach((item) => {
                  if (item.type !== '1') {
                    if (params[groupIndex] && params[groupIndex][currentIndex] !== undefined) {
                      item.value = params[groupIndex][currentIndex];
                    }
                    currentIndex++;
              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++;
                  }
                });
                currentIndex = 0; // 手动重置索引,准备处理下一个分组
              });
                }
              }
              console.log(jsonData2);
              // console.log(jsonData2);
            }
          });
@@ -189,9 +202,37 @@
        socket.onerror = function () {
          console.log("websocket发生了错误");
        };
        this.$router.afterEach(function(){
          socket.close();
        })
      }
    },
    replaceChineseWithEnglish() {
 const nameMap=  this.$t('langPositioning1')
 this.jsonData = this.jsonData.map((item) => {
  return item.map((obj) => {
    if (obj.name) {
      const newName = nameMap[obj.name] || obj.name;
      return { ...obj, name: newName };
    } else if (obj.button && obj.button.name) {
      const newName = nameMap[obj.button.name] || obj.button.name;
      return { ...obj, button: { ...obj.button, name: newName } };
    } else if (obj.title && obj.title.name) {
      const newName = nameMap[obj.title.name] || obj.title.name;
      return { ...obj, title: { ...obj.title, name: newName } };
    } else {
      return obj;
    }
  });
});
// console.log(this.jsonData)
},
    send () {
@@ -219,4 +260,4 @@
.blue-button {
  background-color: skyblue;
}
</style>
</style>