WXL
2024-11-01 0c26cb58f143c56f3753f4745519502222cde4ff
src/views/repositoryai/templateku/configurat/measurement.vue
@@ -100,6 +100,7 @@
  websocketSend,
  closeWebsocket,
} from "@/websocket/websocket.js";
import store from "@/store";
export default {
  data() {
    return {
@@ -112,6 +113,7 @@
      drawer: false,
      radio: "2",
      code: "",
      timeout: "5",
      Answerline: [],
      questionList: [],
    };
@@ -119,6 +121,9 @@
  created() {
    this.TemplateName = this.$route.query.name;
    this.userid = store.getters.Id;
    console.log(store.getters.Id,'11');
    this.requstWs(); //进入页面创建连接
  },
  mounted() {
@@ -147,18 +152,19 @@
    requstWs(message, next, file) {
      console.log("连接");
      this.id = this.$route.query.id;
      this.timeout = this.$route.query.timeout;
      // 防止用户多次连续点击发起请求,所以要先关闭上次的ws请求。
      closeWebsocket();
      console.log(this.id);
      const obj = {
        type: "text",
        userId: "1",
        userId: this.userid,
        templateId: this.id,
        content: null,
      };
      // 发起ws请求
      sendWebsocket(
        "ws://192.168.2.10:8095/chat?userId=1",
        "ws://192.168.2.13:8095/chat?userId="+this.userid,
        obj,
        this.wsMessage,
        this.wsError
@@ -167,16 +173,26 @@
    // 接收ws返回的数据
    wsMessage(data) {
      let dataJson = data;
      let timerId = null;
      dataJson = JSON.parse(dataJson);
      dataJson = JSON.parse(dataJson);
      console.log(dataJson, "数据");
      // 首次接收数据
      if (!this.Answerline[0]) {
        this.Answerline.push({
          value: dataJson.kcb,
          isEat: 1,
        });
      // if (!this.Answerline[0]) {
      //   this.Answerline.push({
      //     value: dataJson.kcb,
      //     isEat: 1,
      //   });
      // }
      timerId = setTimeout(() => {
        if (!this.answer) {
          this.sendFn(); // 后调用
        }
      }, this.timeout * 1000);
      if (condition) {
      }
      // clearTimeout(timerId)
      // 优先加入通用库匹配文本
      if (dataJson.nowQuestion.submoduleText) {
        this.Answerline.push({
@@ -207,7 +223,6 @@
      });
      console.log(this.questionList);
      // IMUI.appendMessage(data);
    },
    //ws错误回调
@@ -216,17 +231,19 @@
    },
    sendFn() {
      console.log("发送");
      // 消息发送
      const obj = {
        type: "text",
        userId: "1",
        userId: this.userid,
        templateId: "",
        questionMessage: { content: this.answer },
      };
      console.log(obj, "入参");
      // 发起ws请求
      sendWebsocket(
        "ws://192.168.2.10:8095/chat?userId=1",
        "ws://192.168.2.13:8095/chat?userId="+this.userid,
        obj,
        this.wsMessage,
        this.wsError
@@ -273,13 +290,14 @@
  overflow: auto;
  .leftside {
    margin-bottom: 30px;
    max-width: 566px;
    margin-left: 20px;
    padding: 10px;
    color: #fff;
    background: rgb(110, 196, 247);
    border-radius: 10px;
    span {
      width: 400px;
      margin-left: 20px;
      padding: 10px;
      color: #fff;
      background: rgb(110, 196, 247);
      border-radius: 10px;
      word-wrap: break-word;
    }
  }
  .offside {