This commit is contained in:
aqu415
2022-03-04 10:12:15 +08:00
parent a343794b3f
commit 7b2e922515
6 changed files with 44 additions and 23 deletions
+1
View File
@@ -20,6 +20,7 @@ class CooperationMind(AbstractModel):
client_id = models.CharField(verbose_name='客户端ID', max_length=64, null=False, blank=False) client_id = models.CharField(verbose_name='客户端ID', max_length=64, null=False, blank=False)
snapshot_data = models.TextField(verbose_name='脑图数据', null=True, ) snapshot_data = models.TextField(verbose_name='脑图数据', null=True, )
log_id = models.BigIntegerField(verbose_name='data对应的操作日志(cooperation_mind_log)ID', null=True, ) log_id = models.BigIntegerField(verbose_name='data对应的操作日志(cooperation_mind_log)ID', null=True, )
data_format = models.CharField(verbose_name='数据格式化类型', max_length=32, null=False, blank=False)
class Meta: class Meta:
db_table = 'cooperation_mind' db_table = 'cooperation_mind'
+1
View File
@@ -6,6 +6,7 @@ urlpatterns = [
path('', to_list), # 跳转列表界面 path('', to_list), # 跳转列表界面
path('detail', to_detail), # 跳转详情界面 path('detail', to_detail), # 跳转详情界面
path('create', JsMindView.as_view()), # 创建思维导图 path('create', JsMindView.as_view()), # 创建思维导图
path('delete', JsMindView.as_view()), # 删除思维导图
path('list', JsMindView.as_view()), # 查询思维导图 path('list', JsMindView.as_view()), # 查询思维导图
path(r'jsmind_op', JsMindLogView.as_view()), # 更新快照,get日志 path(r'jsmind_op', JsMindLogView.as_view()), # 更新快照,get日志
] ]
+16 -7
View File
@@ -37,6 +37,9 @@ class JsMindView(ListAPIView):
pagination_class = NewPagination pagination_class = NewPagination
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
"""
查询思维导图
"""
pk = request.GET.get('id') pk = request.GET.get('id')
if pk is not None: if pk is not None:
mind = CooperationMind.objects.filter(id=pk).first() mind = CooperationMind.objects.filter(id=pk).first()
@@ -47,26 +50,31 @@ class JsMindView(ListAPIView):
def post(self, request): def post(self, request):
""" """
查询思维导图 创建思维导图
""" """
coop_mind_name = request.data.get('mind_name') coop_mind_name = request.data.get('mind_name')
snapshot_data = request.data.get('snapshot_data') snapshot_data = request.data.get('snapshot_data')
mind = CooperationMind(coop_mind_name=coop_mind_name, client_id='', snapshot_log_id=-1, creator=9527, snapshot_data=snapshot_data) data_format = request.data.get('data_format')
mind = CooperationMind(coop_mind_name=coop_mind_name, client_id='', log_id=-1, creator=9527, snapshot_data=snapshot_data, data_format=data_format)
mind.save() mind.save()
return build_response(data=mind.id) return build_response(data=mind.id)
def delete(self, request, pk):
# 删除
pk = request.GET.get('id')
CooperationMind.objects.filter(id=pk).delete()
return build_response()
# Create your views here. # Create your views here.
class JsMindLogView(APIView): class JsMindLogView(APIView):
""" """
日志获取,快照保存
""" """
def get(self, request): def get(self, request):
""" """
查询日志
:param request:
:return:
""" """
param = request.GET param = request.GET
coop_mind_id = param.get('coop_mind_id') coop_mind_id = param.get('coop_mind_id')
@@ -88,5 +96,6 @@ class JsMindLogView(APIView):
coop_mind_id = post_body.get('coop_mind_id') coop_mind_id = post_body.get('coop_mind_id')
data = post_body.get('data') data = post_body.get('data')
coop_mind_log_id = post_body.get('coop_mind_log_id') coop_mind_log_id = post_body.get('coop_mind_log_id')
CooperationMind.objects.filter(id=coop_mind_id, log_id__lt=coop_mind_log_id).update(snapshot_data=data, log_id=coop_mind_log_id, update_time=dt.now(), client_id=client_id) data_format = post_body.get('data_format')
CooperationMind.objects.filter(id=coop_mind_id, log_id__lt=coop_mind_log_id).update(data_format=data_format, snapshot_data=data, log_id=coop_mind_log_id, update_time=dt.now(), client_id=client_id)
return build_response() return build_response()
+14 -7
View File
@@ -41,21 +41,28 @@
const me = this const me = this
$.get('list?id=' + id, function (resp) { $.get('list?id=' + id, function (resp) {
// reset // reset
me.destroy_coop_timer_if_necessary() me.close_coop_timer_if_necessary()
// show // show
let data = resp.data.snapshot_data let snapshot_data = resp.data.snapshot_data
me.coop_mind_id = id me.coop_mind_id = id
me.coop_mind_log_id = resp.data.log_id
me.show_mind(resp.data.coop_mind_name, JSON.parse(data)) const resp_data = resp.data
me.coop_mind_log_id = resp_data.log_id
const data_format = resp_data.data_format
// node_tree 和 node_array 需要被转成对象,freemind 不需要
snapshot_data = data_format === 'node_tree' || data_format === 'node_array' ? JSON.parse(snapshot_data) : snapshot_data
me.show_mind(resp.data.coop_mind_name, data_format, snapshot_data)
}) })
}, },
// 清除定时任务等 // 清除定时任务等
destroy_coop_timer_if_necessary() { close_coop_timer_if_necessary() {
if (this.jm && this.jm.coop) { if (this.jm && this.jm.coop) {
this.jm.coop.clear_timer() this.jm.coop.clear_timer()
} }
}, },
show_mind: function (name, data) { show_mind: function (name, data_format, data) {
// options // options
const options = { const options = {
container: 'jsmind_container', container: 'jsmind_container',
@@ -87,7 +94,7 @@
/* 元数据,定义思维导图的名称、作者、版本等信息 */ /* 元数据,定义思维导图的名称、作者、版本等信息 */
meta: {name: name, author: 'cy20081118148@163.com', version: '0.2'}, meta: {name: name, author: 'cy20081118148@163.com', version: '0.2'},
/* 数据格式声明 */ /* 数据格式声明 */
format: 'node_tree', format: data_format,
/* 数据内容 */ /* 数据内容 */
data: {id: 'root', topic: 'jsMind'} data: {id: 'root', topic: 'jsMind'}
} }
+2 -1
View File
@@ -72,6 +72,7 @@
<td> <td>
<i class="layui-icon layui-icon-edit" style="font-size: 15px; color: #1E9FFF;cursor: pointer;" onclick="window.open('detail?id=${item.id}')">编辑</i> <i class="layui-icon layui-icon-edit" style="font-size: 15px; color: #1E9FFF;cursor: pointer;" onclick="window.open('detail?id=${item.id}')">编辑</i>
<i class="layui-icon layui-icon-share" style="font-size: 15px; color: #1E9FFF;cursor: pointer;margin-left: 10px;">复制分享</i> <i class="layui-icon layui-icon-share" style="font-size: 15px; color: #1E9FFF;cursor: pointer;margin-left: 10px;">复制分享</i>
<i class="layui-icon layui-icon-delete" style="font-size: 15px; color: #1E9FFF;cursor: pointer;margin-left: 10px;">删除</i>
</td> </td>
</tr>` </tr>`
$('#layui-table tbody').append(tr) $('#layui-table tbody').append(tr)
@@ -216,7 +217,7 @@
] ]
} }
// post start // post start
$.post('create', {'mind_name': mind_name, 'snapshot_data': view.json2string(snapshot_data)}, function (resp) { $.post('create', {'mind_name': mind_name, 'data_format': 'node_tree', 'snapshot_data': view.json2string(snapshot_data)}, function (resp) {
layer.closeAll() layer.closeAll()
view.fetch_data() view.fetch_data()
+10 -8
View File
@@ -38,18 +38,19 @@
coop_mind_log_id: 0, coop_mind_log_id: 0,
// 定时备份数据 // 定时备份数据
timer_push_task: null, timer_push_task: null,
// 定时获得变化
timer_fetch_task: null,
// web_socket // web_socket
web_socket: null, web_socket: null,
// init // init
_init: function (_jm) { _init: function (_jm) {
if (!this._jm) { if (!this._jm) {
this._jm = _jm this._jm = _jm
// 添加事件处理
_jm.add_event_listener(jsMindCallBackFacade) _jm.add_event_listener(jsMindCallBackFacade)
// 初始化属性 // 初始化属性
this._init_properties(_jm) this._init_properties(_jm)
// 初始化websocket // 初始化websocket
this._init_ws() this._init_ws()
@@ -109,9 +110,6 @@
if (this.timer_push_task) { if (this.timer_push_task) {
$w.clearInterval(this.timer_push_task) $w.clearInterval(this.timer_push_task)
} }
if (this.timer_fetch_task) {
$w.clearInterval(this.timer_fetch_task)
}
}, },
/** /**
* 是否为空 * 是否为空
@@ -180,7 +178,7 @@
*/ */
js_mind_callback_: function (type, body) { js_mind_callback_: function (type, body) {
const evt = body.evt const evt = body.evt
if (!!evt) { if (this.should_handle_evt(evt)) {
const param = this._build_evt_param() const param = this._build_evt_param()
Jm.util.json.merge(body, param) Jm.util.json.merge(body, param)
@@ -190,6 +188,9 @@
this._send_ws_message(msg) this._send_ws_message(msg)
} }
}, },
should_handle_evt: function (evt) {
return evt && ['add_node', 'insert_node_before', 'insert_node_after', 'remove_node', 'update_node', 'move_node'].includes(evt)
},
// 处理特殊字符 // 处理特殊字符
handle_spec_str: function (msg) { handle_spec_str: function (msg) {
if (!!msg) { if (!!msg) {
@@ -214,11 +215,12 @@
if (this._is_null(me.timer_push_task)) { if (this._is_null(me.timer_push_task)) {
me.timer_push_task = setInterval(function () { me.timer_push_task = setInterval(function () {
const param = { const param = {
'data': Jm.util.json.json2string(me._jm.get_data('node_array').data), 'data': Jm.util.json.json2string(me._jm.get_data('node_tree').data),
'client_id': me.client_id, 'client_id': me.client_id,
'coop_mind_id': me.coop_mind_id, 'coop_mind_id': me.coop_mind_id,
'coop_mind_log_id': me.coop_mind_log_id, 'coop_mind_log_id': me.coop_mind_log_id,
'type': 'snapshot' 'type': 'snapshot',
'data_format': 'node_tree'
} }
Jm.util.ajax.post(me.coop_api_url, param, function (resp) { Jm.util.ajax.post(me.coop_api_url, param, function (resp) {
}) })