From f5b42e6f5f57aec1c076c54e07bfc7d0482dda29 Mon Sep 17 00:00:00 2001 From: aqu415 Date: Wed, 16 Feb 2022 22:10:08 +0800 Subject: [PATCH] update --- README.en.md | 36 ----------------------------------- server/lib/__init__.py | 0 server/lib/coope_mind_lib.py | 31 ++++++++++++++++++++++++++++++ server/models.py | 3 +-- server/websocket/consumers.py | 7 ++++++- static/js/jsmind.coop.js | 14 ++++++++++---- static/js/jsmind.js | 8 ++++++++ 7 files changed, 56 insertions(+), 43 deletions(-) delete mode 100644 README.en.md create mode 100644 server/lib/__init__.py create mode 100644 server/lib/coope_mind_lib.py diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 4d95a35..0000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# jsmindmutli - -#### Description -多人协作思维导图python后台版本 - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/server/lib/__init__.py b/server/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/lib/coope_mind_lib.py b/server/lib/coope_mind_lib.py new file mode 100644 index 0000000..b61477f --- /dev/null +++ b/server/lib/coope_mind_lib.py @@ -0,0 +1,31 @@ +from server.models import CooperationMindLog +import ast + + +class CooperationMindLogLib(object): + """ + 操作日志 + """ + + def save_log(self, json_msg): + """ + 保存操作日志 + """ + if self.should_handle(json_msg): + # 避免json解析失败 + json_msg = json_msg.replace(',null]', ']') + json_msg_dict = ast.literal_eval(json_msg) + + log = CooperationMindLog( + coop_mind_id=json_msg_dict.get('coop_mind_id'), + log_uuid=json_msg_dict.get('log_uuid'), + log_content=json_msg, + client_id=json_msg_dict.get('client_id') + ) + log.save() + json_msg_dict.update({'log_id': log.id}) + return json_msg_dict + return None + + def should_handle(self, json_msg): + return 'coop_mind_id' in json_msg and 'select_node' not in json_msg diff --git a/server/models.py b/server/models.py index 476ad37..2021ac7 100644 --- a/server/models.py +++ b/server/models.py @@ -37,9 +37,8 @@ class CooperationMindLog(AbstractModel): """ coop_mind_id = models.BigIntegerField(verbose_name='脑图ID', null=False, blank=False) log_uuid = models.CharField(verbose_name='操作UUID', max_length=64, null=False, blank=False) - log_event = models.CharField(verbose_name='操作事件', max_length=32, null=False, blank=False) log_content = models.CharField(verbose_name='操作内容', max_length=1024, null=False, blank=False) - operator = models.BigIntegerField(verbose_name='操作人', null=False) + operator = models.BigIntegerField(verbose_name='操作人', null=True) operator_ip = models.CharField(verbose_name='操作人IP', null=False, max_length=32) client_id = models.CharField(verbose_name='客户端ID', max_length=64, null=False, blank=False) diff --git a/server/websocket/consumers.py b/server/websocket/consumers.py index 43cac79..23b82c9 100644 --- a/server/websocket/consumers.py +++ b/server/websocket/consumers.py @@ -1,8 +1,12 @@ from asgiref.sync import async_to_sync from channels.generic.websocket import WebsocketConsumer +from server.lib.coope_mind_lib import CooperationMindLogLib +import json class ChatConsumer(WebsocketConsumer): + log_lib = CooperationMindLogLib() + def connect(self): self.room_group_name = 'chat%s' % bytes.decode(self.scope['query_string']) print(self.room_group_name) @@ -25,12 +29,13 @@ class ChatConsumer(WebsocketConsumer): def receive(self, text_data): # Send message to room group print(text_data) + log_dict = self.log_lib.save_log(text_data) async_to_sync(self.channel_layer.group_send)( self.room_group_name, { # chat_message 方法 'type': 'chat_message', - 'message': text_data + 'message': text_data if log_dict is None else json.dumps(log_dict) } ) diff --git a/static/js/jsmind.coop.js b/static/js/jsmind.coop.js index e458c85..c0d6f50 100644 --- a/static/js/jsmind.coop.js +++ b/static/js/jsmind.coop.js @@ -34,7 +34,7 @@ coop_mind_id: null, // 上一次操作日志ID coop_mind_log_last_id: 0, - // 默认操作日志ID + // 默认操作日志IDh coop_mind_log_id: 0, // 定时备份数据 timer_push_task: null, @@ -76,7 +76,7 @@ } ws.onmessage = function (e) { //当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据 - me._oper_jsmind_with_ws_message(e.data) + me._handle_jsmind_with_ws_message(e.data) } ws.onclose = function (e) { //当客户端收到服务端发送的关闭连接请求时,触发onclose事件 @@ -117,8 +117,14 @@ 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) { + _handle_jsmind_with_ws_message: function (message) { const msg_json = JSON.parse(message) + const client_id = msg_json.client_id + if (client_id === this.client_id) { + console.log('self msg') + } else { + + } }, /** * body: @@ -153,7 +159,7 @@ }, // 发送ws消息 _send_ws_message: function (msg) { - if (this.web_socket) { + if (this.web_socket != null) { this.web_socket.send(msg) } else { console.error('web_socket is not ready!') diff --git a/static/js/jsmind.js b/static/js/jsmind.js index 61fcd71..fcce917 100644 --- a/static/js/jsmind.js +++ b/static/js/jsmind.js @@ -2986,6 +2986,10 @@ var nodeid = this._newid(); var node = _jm.add_node(selected_node, nodeid, 'New Node'); if (!!node) { + let evt = e || event; + evt.stopPropagation(); + evt.preventDefault(); + _jm.select_node(nodeid); _jm.begin_edit(nodeid); } @@ -2997,6 +3001,10 @@ var nodeid = this._newid(); var node = _jm.insert_node_after(selected_node, nodeid, 'New Node'); if (!!node) { + const evt = e || event; + evt.stopPropagation(); + evt.preventDefault(); + _jm.select_node(nodeid); _jm.begin_edit(nodeid); }