CanadaMes-ui/src/views/Electrical/Parameter.vue
@@ -8,6 +8,7 @@
  <router-link to="/Electrical/Action" tag="el-button" type="text">Action</router-link>
  <router-link to="/Electrical/Sign" tag="el-button" type="text">Sign</router-link>
  <router-link to="/Electrical/State" tag="el-button" type="text">State</router-link>
  <router-link to="/Electrical/alarm" tag="el-button" type="text">Alarm</router-link>
  </el-breadcrumb>
  <div>Parameter</div>
  
@@ -16,8 +17,8 @@
      <el-button type="primary" @click="send()">下发参数</el-button>
    </div>
    <div class="kuai_div" v-for="(item, index) in record.xyData" :key="index">
      <el-input style="width: 280px;" class="in_mc" v-model="item.name"  readonly></el-input>
      <el-input v-model="item.value" style="width: 80px;"></el-input>
      <el-input style="width: 280px;" class="in_mc" v-model="item.name" readonly></el-input>
      <el-input v-model.number="item.value" style="width: 80px;" @input="handleChange(index, $event.target.value)"></el-input>
    </div>
  </el-form>
  </div>
@@ -32,20 +33,21 @@
  return {
  record: {
  params: [100, 200, 10, 10, 10, 10],
  xyData: [{ name: "conveyor Velocity(Auto SLOW)", value: 100 },
    { name: "B01 B02 TRAVEL POS Velocity AUTO", value: 10 },
    { name: "B01 B02 TRAVEL JOG Velocity", value: 10 },
    { name: "conveyor Velocity(Manual)", value: 10},
    { name: "B01 B02 TRAVEL JOG Velocity", value: 10},
    { name: "conveyor Velocity(Manual)", value: 10 }],
  canshu: [
  'conveyor Velocity(Auto SLOW)',
  'B01 B02 TRAVEL POS Velocity AUTO',
  'B01 B02 TRAVEL JOG Velocity',
  'conveyor Velocity(Manual)',
  'B01 B02 TRAVEL JOG Velocity',
  'conveyor Velocity(Manual)'
  xyData: [
  { name: "conveyor Velocity(Auto FAST)", value: 0 },
  { name: "conveyor Velocity(Auto SLOW)", value: 0 },
  { name: "conveyor Velocity(Manual)", value: 0 },
  { name: "A01 A02 TURN JOG Velocity", value: 0 },
  { name: "A01 A02 TRAVEL JOG Velocity", value: 0 },
  { name: "B01 B02 TRAVEL JOG Velocity", value: 0 },
  { name: "A01 A02 TURN POS Velocity AUTO", value: 0 },
  { name: "A01 A02 TURN POS Velocity manual", value: 0 },
  { name: "A01 A02 TRAVEL POS Velocity AUTO", value: 0 },
  { name: "A01 A02 TRAVEL POS Velocity manual", value: 0 },
  { name: "B01 B02 TRAVEL POS Velocity AUTO", value: 0 },
  { name: "B01 B02 TRAVEL POS Velocity manual", value: 0 }
  ],
  canshu: []
  },
  messagepack: {
  data: { taskname: "" }
@@ -53,21 +55,19 @@
  queryInfo: {
  data: "1",
  pageSize: 10
  },
  }
  };
  },
  created() {
  this.initWebSocket();
  },
  methods: {
  initWebSocket() {
  let viewname = "action";
  let viewname = "Parameter";
  
    if (typeof WebSocket == "undefined") {
    if (typeof WebSocket === "undefined") {
      console.log("您的浏览器不支持WebSocket");
    } else {
      //console.log("您的浏览器支持WebSocket");
      let socketUrl = "ws://" + "localhost:8888" + "/springboot-vue3/api/talk/" + viewname;
  
      if (socket != null) {
@@ -85,24 +85,24 @@
  
      // 收到消息
      socket.onmessage = (msg) => {
  if (!msg.data) {
    return; // 如果收到空数据,则直接返回,不执行后续逻辑
  }
  let obj = JSON.parse(msg.data);
  this.record.params[0] = obj.params[0];
  for (let a = 0; a <= this.record.params[0].length - 1; a++) {
    if (!this.record.xyData[a]) {
      this.record.xyData[a] = { name: this.record.canshu[a], value: this.record.params[0][a] };
    } else {
      this.record.xyData[a].value = this.record.params[0][a];
    }
  }
  console.log(this.record.xyData);
  this.$forceUpdate();
};
        if (!msg.data) {
          return; // 如果收到空数据,则直接返回,不执行后续逻辑
        }
        let obj = JSON.parse(msg.data);
        this.record.params[0] = obj.params[0];
        for (let a = 0; a <= this.record.params[0].length - 1; a++) {
          if (!this.record.xyData[a]) {
            this.record.xyData[a] = { name: this.record.canshu[a], value: this.record.params[0][a] };
          } else {
            this.record.xyData[a].value = this.record.params[0][a];
          }
        }
        console.log(this.record.xyData);
        this.$forceUpdate();
      };
  
      // 关闭事件
      socket.onclose = function () {
@@ -112,16 +112,19 @@
      // 发生错误事件
      socket.onerror = function () {
        console.log("websocket发生了错误");
      }
      };
    }
  },
  send() {
  this.messagepack.data = this.record.xyData.map(item => parseInt(item.value)); // 转换为整数数组
  console.log(this.messagepack);
  socket?.send(JSON.stringify(this.messagepack));
}
    this.messagepack.data = this.record.xyData.map((item) => parseInt(item.value)); // 转换为整数数组
    console.log(this.messagepack);
    socket?.send(JSON.stringify(this.messagepack));
  },
  handleChange(index, value) {
    this.record.xyData[index].value = value;
  }
  }
  };
  </script>
  
  <style>
@@ -149,4 +152,4 @@
  #btn_div .el-button {
  float: right;
  }
  </style>
  </style>