XWWitPark/witpark_jzzs/xw_jzzs_web/public/widgets/plotSocket/widget.js

2 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-09-12 00:10:00 +00:00
/* 2020-9-24 14:48:23 | 版权所有 军懋国兴 */
mars3d.widget.bindClass(mars3d.widget.BaseWidget.extend({options:{view:{type:"divwindow",url:"view.html",windowOptions:{width:400,height:110}}},winCreateOK:function(){var t=this,o=haoutil.storage.get("plot_ws");o&&($("#txtWSUrl").val(o),t.connectionWS(o)),$("#txtCoonWS").click(function(){var o=$("#txtWSUrl").val();haoutil.storage.add("plot_ws",o),t.connectionWS(o)}),$("#txtColseWS").click(function(){t.closeSocket()})},activate:function(){},disable:function(){this.viewWindow=null},showMsg:function(o){$("#lblMsg").html(o)},webSocket:null,connectionWS:function(o){var e=this;this.closeSocket();var t=new WebSocket(o);return t.onopen=function(o){console.log("WebSocket打开连接"),e.showMsg("已连接")},t.onerror=function(o){console.log("WebSocket发生异常"),e.showMsg("连接发生异常")},t.onclose=function(o){console.log("WebSocket关闭连接"),e.showMsg("连接已关闭")},t.onmessage=function(o){console.log("WebSocket接收到消息"),console.log(o.data);var t=JSON.parse(o.data);e.config.updateAttr(t)},this.webSocket=t},closeSocket:function(){this.webSocket&&(this.webSocket.close(),delete this.webSocket)},sendSocket:function(o){this.webSocket&&(console.log("发送了WebSocket消息"),console.log(o),this.webSocket.send(JSON.stringify(o)))}}));