ZengTao
2023-12-20 857a92a183e31655477786812ec26d6bda9395ac
Merge branch 'master' of http://10.153.19.25:10101/r/CanadaMes
1个文件已修改
1个文件已添加
53 ■■■■■ 已修改文件
CanadaMes-ui/src/api/websocketPlugin.js 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot-vue3/src/main/java/com/example/springboot/component/PlcParameter2.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CanadaMes-ui/src/api/websocketPlugin.js
New file
@@ -0,0 +1,52 @@
let socket;
export default {
  install: (Vue, options) => {
    Vue.prototype.$connectWebSocket = (viewname, handleData) => {
      if (typeof WebSocket === "undefined") {
        console.log("您的浏览器不支持 WebSocket");
      } else {
        let socketUrl = "ws://" + options.ip + ":8888" + "/springboot-vue3/api/talk/" + viewname;
        if (socket != null) {
          socket.close();
          socket = null;
        }
        // 开启一个 WebSocket 连接
        socket = new WebSocket(socketUrl);
        // 打开事件
        socket.onopen = () => {
          console.log("WebSocket 已打开");
        };
        // 收到消息
        socket.onmessage = (msg) => {
          if (!msg.data) {
            return;
          }
          handleData(JSON.parse(msg.data));
        };
        // 关闭事件
        socket.onclose = () => {
          console.log("WebSocket 已关闭");
        };
        // 发生错误事件
        socket.onerror = () => {
          console.log("WebSocket 发生了错误");
        };
      }
    };
    Vue.prototype.$sendWebSocketMessage = (message) => {
      socket?.send(JSON.stringify(message));
    };
    Vue.prototype.$closeWebSocket = () => {
      // 关闭 WebSocket 连接
      socket.close();
    };
  },
};
springboot-vue3/src/main/java/com/example/springboot/component/PlcParameter2.java
@@ -147,6 +147,7 @@
                            //存片等待延迟
                            customS7Control.Writetime(messageArray, timeout2, 2);
                            // 清空消息列表
                            webserver.clearMessages();
                        }