clll
2023-11-27 1de312a18d164c2fa3718a1a975b8c5804723bcf
CanadaMes-ui/src/views/Electrical/ServoManualone.vue
@@ -1,90 +1,56 @@
<template>
  <div class="app">
    <div class="app">
    <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb">
      <router-link to="/Electrical/alarm" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm')
      }}</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')
      }}</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">{{
        $t('ServoManual')
      }}</router-link>
    </el-breadcrumb>
        <router-link to="/Electrical/alarm" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm')
        }}</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')
        }}</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">{{ $t('Servo Manual')
        }}</router-link>
      </el-breadcrumb>
    <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb">
      <router-link to="/Electrical/Servomanualone" tag="el-button" type="text" active-class="blue-button">{{
        $t('Servomanualone')
      <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb">
        <router-link to="/Electrical/Servomanualone" tag="el-button" type="text" active-class="blue-button">{{ $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/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>
      <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" type="text" active-class="blue-button">{{
        $t('AutomaticParameterSetting')
      }}</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>
      <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" type="text" active-class="blue-button">{{
        $t('AutomaticParameterSetting')
      }}</router-link>
      <router-link to="/Electrical/ManualJog" tag="el-button" type="text" active-class="blue-button">{{
        $t('ManualJog')
      }}</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/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>
    </el-breadcrumb>
    <el-row :gutter="26">
      <el-col :span="12" v-for="(dataGroup, groupIndex) in jsonData" :key="groupIndex">
        <el-card class="json-block" style="width:auto;">
          <el-row>
            <el-col v-for="(item, itemIndex) in dataGroup" :key="itemIndex" :span="12">
              <div class="item-container">
                <div class="item-row">
                  <span class="name" style='width:230px;'>{{ item.name }}</span>
                  <el-input v-if="item.type === '0'" v-model="item.value" class='input-box'
                    :class="{ 'special-class': groupIndex === 0, 'special-class2': groupIndex === 1 }"
                    v-show="groupIndex !== 0 && groupIndex !== 1"></el-input>
                </div>
              </div>
            </el-col>
          </el-row>
          <div class="button-row" style="display: flex; justify-content: space-between;">
            <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex">
              <el-button v-if="item.button" :name="item.button.name" v-model="item.button.value"
                :class="{ 'action-button': true, 'error-button': item.button.name === '故障' && item.button.value === 1 }"
                @click="updateButtonValue(dataGroup, itemIndex); submitDataToBackend(item.button.name);">{{
                  item.button.name }}</el-button>
  <el-col :span="12" v-for="(dataGroup, groupIndex) in jsonData" :key="groupIndex">
    <el-card class="json-block"  style="width:auto;">
      <el-row >
        <el-col v-for="(item, itemIndex) in dataGroup" :key="itemIndex" :span="12">
          <div class="item-container">
            <div class="item-row">
              <span class="name" style='width:230px;'>{{ item.name }}</span>
              <el-input v-if="item.type === '0'" v-model="item.value"   class='input-box' :class="{ 'special-class': groupIndex === 0,'special-class2': groupIndex === 1 }" v-show="groupIndex !== 0 && groupIndex !== 1"  ></el-input>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
        </el-col>
      </el-row>
      <div class="button-row" style="display: flex; justify-content: space-between;">
        <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex">
          <el-button v-if="item.button" :name="item.button.name" v-model="item.button.value" :class="{'action-button': true, 'error-button': item.button.name === '故障' && item.button.value === 1}" @click="updateButtonValue(dataGroup, itemIndex); submitDataToBackend(item.button.name);">{{ item.button.name }}</el-button>
        </div>
      </div>
    </el-card>
  </el-col>
</el-row>
    <!-- <el-button @click="submitDataToBackend">提交数据到后端</el-button> -->
  </div>
@@ -95,12 +61,12 @@
import data from '../../configuration/ServoManualone'
import { throttle } from 'lodash';
let socket;
export default {
  export default {
  name: "ServoManualone",
  mixins: [LanguageMixin],
  data () {
  data() {
    return {
      jsonData: data,
      jsonData: data ,
      // 加载整个data.json文件作为jsonData
    }
@@ -111,84 +77,84 @@
  },
  methods: {
    updateButtonValue (dataGroup, itemIndex) {
      // 将当前按钮的值设为1
    updateButtonValue(dataGroup, itemIndex) {
  // 将当前按钮的值设为1
      this.$set(dataGroup[itemIndex].button, 'value', 1);
    this.$set(dataGroup[itemIndex].button, 'value', 1);
},
submitDataToBackend(currentButtonName) {
  if (currentButtonName === '半自动启动') {
    const data = [];
for (let i = 0; i < 2; i++) {
  const inputData = this.jsonData[i].filter(item => item.type === '0').map(item => {
    return { value: item.value };
  });
  const values = inputData.map(item => item.value);
  data.push(values);
}
    },
    submitDataToBackend (currentButtonName) {
      if (currentButtonName === '半自动启动') {
        const data = [];
const jsonObject = { data };
        for (let i = 0; i < 2; i++) {
          const inputData = this.jsonData[i].filter(item => item.type === '0').map(item => {
            return { value: item.value };
          });
// 提交数据到后端
const jsonString = JSON.stringify(jsonObject);
console.log('所有Type为0的value:', jsonString);
socket?.send(jsonString);
          const values = inputData.map(item => item.value);
  }
          data.push(values);
        }
  if (currentButtonName === '复位') {
    const data2 = [];
    const resetButtonValues = this.jsonData.map(item => {
  const buttonItem = item.find(subItem => subItem.button && subItem.button.name === '复位');
  return buttonItem ? buttonItem.button.value : null;
}).filter(value => value !== null);
// 将得到的值添加到 data 数组中
data2.push(...resetButtonValues);
const jsonObject2 = { data2 };
// 提交数据到后端
const jsonString2 = JSON.stringify(jsonObject2);
console.log('所有Type为0的value:', jsonString2);
socket?.send(jsonString2);
}
  if (currentButtonName === 'A01半自动') {
    const elements = document.getElementsByClassName('special-class');
    for (let i = 0; i < elements.length; i++) {
      if (elements[i].style.display === 'none') {
        elements[i].style.display = ''; // 显示元素
      }
    }
  }
        const jsonObject = { data };
  if (currentButtonName === 'A02半自动') {
    const elements = document.getElementsByClassName('special-class2');
    for (let i = 0; i < elements.length; i++) {
      if (elements[i].style.display === 'none') {
        elements[i].style.display = ''; // 显示元素
      }
    }
  }
        // 提交数据到后端
        const jsonString = JSON.stringify(jsonObject);
        console.log('所有Type为0的value:', jsonString);
        socket?.send(jsonString);
      }
      if (currentButtonName === '复位') {
        const data2 = [];
        const resetButtonValues = this.jsonData.map(item => {
          const buttonItem = item.find(subItem => subItem.button && subItem.button.name === '复位');
          return buttonItem ? buttonItem.button.value : null;
        }).filter(value => value !== null);
        // 将得到的值添加到 data 数组中
        data2.push(...resetButtonValues);
        const jsonObject2 = { data2 };
        // 提交数据到后端
        const jsonString2 = JSON.stringify(jsonObject2);
        console.log('所有Type为0的value:', jsonString2);
        socket?.send(jsonString2);
      }
      if (currentButtonName === 'A01半自动') {
        const elements = document.getElementsByClassName('special-class');
        for (let i = 0; i < elements.length; i++) {
          if (elements[i].style.display === 'none') {
            elements[i].style.display = ''; // 显示元素
          }
        }
      }
      if (currentButtonName === 'A02半自动') {
        const elements = document.getElementsByClassName('special-class2');
        for (let i = 0; i < elements.length; i++) {
          if (elements[i].style.display === 'none') {
            elements[i].style.display = ''; // 显示元素
          }
        }
      }
    },
},
    initWebSocket () {
      let viewname = "ServoManualone";
      if (typeof WebSocket === "undefined") {
@@ -211,60 +177,57 @@
        // 收到消息
        socket.onmessage = (msg) => {
          if (!msg.data) {
            return; // 如果收到空数据,则直接返回,不执行后续逻辑
          }
  if (!msg.data) {
    return; // 如果收到空数据,则直接返回,不执行后续逻辑
  }
          let obj = JSON.parse(msg.data);
          // console.log(obj)
          const jsonData2 = this.jsonData;
  let obj = JSON.parse(msg.data);
  // console.log(obj)
  const jsonData2 = this.jsonData;
          const handleMouseMove = throttle(function (event) {
            const inputBox = document.querySelectorAll('.el-card__body');
            const target = event.target;
            if (inputBox && Array.from(inputBox).every(box => !box.contains(target))) {
              // 执行更新逻辑
              for (let i = 0; i < 6; i++) {
                jsonData2[i].forEach((item, index) => {
                  if (typeof item.value !== 'undefined' && typeof obj[`zuhe${i + 1}`][0][index] !== 'undefined') {
                    item.value = obj[`zuhe${i + 1}`][0][index];
                  }
                });
              }
  const handleMouseMove = throttle(function(event) {
  const inputBox = document.querySelectorAll('.el-card__body');
  const target = event.target;
  if (inputBox && Array.from(inputBox).every(box => !box.contains(target))) {
    // 执行更新逻辑
    for (let i = 0; i < 6; i++) {
  jsonData2[i].forEach((item, index) => {
    if (typeof item.value !== 'undefined' && typeof obj[`zuhe${i+1}`][0][index] !== 'undefined') {
      item.value = obj[`zuhe${i+1}`][0][index];
    }
  });
}
              // 遍历guzhang数组
              for (let i = 0; i < obj.guzhang[0].length; i++) {
                const guzhangValue = obj.guzhang[0][i];
                // 查找jsonData2中带有"button"的对象,并且name等于"故障"
                for (let j = 0; j < jsonData2.length; j++) {
                  const section = jsonData2[j];
                  for (let k = 0; k < section.length; k++) {
                    const item = section[k];
                    if (item.button && item.button.name === "故障") {
                      // 更新value属性
                      item.button.value = guzhangValue;
                      break;
                    }
                  }
                }
              }
// 遍历guzhang数组
for (let i = 0; i < obj.guzhang[0].length; i++) {
  const guzhangValue = obj.guzhang[0][i];
  // 查找jsonData2中带有"button"的对象,并且name等于"故障"
  for (let j = 0; j < jsonData2.length; j++) {
    const section = jsonData2[j];
    for (let k = 0; k < section.length; k++) {
      const item = section[k];
      if (item.button && item.button.name === "故障") {
        // 更新value属性
        item.button.value = guzhangValue;
        break;
      }
    }
  }
}
  }
}, 200);
            }
          }, 200);
          document.addEventListener('mouseover', handleMouseMove);
        };
  document.addEventListener('mouseover', handleMouseMove);
};
@@ -282,21 +245,22 @@
      }
    },
    send () {
      socket?.send(JSON.stringify(this.messagepack));
    }
  }
}
  }
</script>
<style scoped>
.item-row {
  display: flex;
  align-items: center;
  margin-bottom: 2px;
  /* 调整每个项目之间的间距 */
  margin-bottom: 2px; /* 调整每个项目之间的间距 */
}
.action-button {
@@ -304,12 +268,12 @@
  background: #66b1ff;
  color: #FFF;
}
.blue-button {
  background-color: skyblue;
}
.error-button {
  background-color: red;
}
</style>