diff --git a/static/js/jsmind.coop.js b/static/js/jsmind.coop.js index 5b9ef89..e458c85 100644 --- a/static/js/jsmind.coop.js +++ b/static/js/jsmind.coop.js @@ -65,6 +65,7 @@ }, // 初始化websocket _init_ws: function () { + const me = this if (!this.web_socket && this.coop_mind_id) { const ws = new WebSocket(this.coop_ws_url + '?_' + this.coop_mind_id) this.web_socket = ws @@ -75,9 +76,7 @@ } ws.onmessage = function (e) { //当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据 - // console.log(e.data); - console.log('onmessage:'); - console.log(JSON.parse(e.data)); + me._oper_jsmind_with_ws_message(e.data) } ws.onclose = function (e) { //当客户端收到服务端发送的关闭连接请求时,触发onclose事件 @@ -117,6 +116,10 @@ _build_evt_param: function () { return {'client_id': this.client_id, 'log_uuid': Jm.util.uuid.newid(), 'coop_mind_id': this.coop_mind_id} }, + // 调用jsmind接口 + _oper_jsmind_with_ws_message: function (message) { + const msg_json = JSON.parse(message) + }, /** * body: * # {evt:'add_node',data:[parent_node.id,nodeid,topic,data],node:nodeid} @@ -130,17 +133,25 @@ * @private */ js_mind_callback_: function (type, body) { - const evt = body.evt if (!!evt) { const param = this._build_evt_param() Jm.util.json.merge(body, param) // 序列化数据,处理特殊字符 - const msg = Jm.util.json.json2string(body).replaceAll('\\n', '
') + let msg = Jm.util.json.json2string(body) + msg = this.handle_spec_str(msg) this._send_ws_message(msg) } }, + // 处理特殊字符 + handle_spec_str: function (msg) { + if (!!msg) { + return msg.replaceAll('\\n', '
') + } + return msg + }, + // 发送ws消息 _send_ws_message: function (msg) { if (this.web_socket) { this.web_socket.send(msg)