diff --git a/server/models.py b/server/models.py index ab88da1..227cb84 100644 --- a/server/models.py +++ b/server/models.py @@ -64,11 +64,13 @@ class CooperationMindShare(AbstractModel): share_uuid = models.CharField(verbose_name='分享uuid', max_length=128, null=False, blank=False) share_uuid_hash = models.BigIntegerField(verbose_name='分享uuid_hash', null=False, blank=False) share_end_time = models.DateTimeField(verbose_name='分享有效期', null=True) + operator_user_id = models.BigIntegerField(verbose_name='分享操作人', null=False) class Meta: db_table = 'cooperation_mind_share' indexes = [ models.Index(fields=['share_uuid_hash'], ), + models.Index(fields=['operator_user_id'], ), ] verbose_name = "协作分享表" diff --git a/server/urls.py b/server/urls.py index 691507f..a0a516b 100644 --- a/server/urls.py +++ b/server/urls.py @@ -16,8 +16,9 @@ urlpatterns = [ # --------------------------------------------------- path('create', JsMindView.as_view()), # 创建思维导图 - path('delete', JsMindView.as_view()), # 删除思维导图 path('list', JsMindView.as_view()), # 查询思维导图 + path('delete', JsMindView.as_view()), # 删除思维导图 + path('share', JsMindShareView.as_view()), # 分享思维导图 path(r'jsmind_op', JsMindLogView.as_view()), # 更新快照,get日志 # --------------------------------------------------- @@ -25,4 +26,6 @@ urlpatterns = [ path('login', LoginView.as_view()), # 用户登录 path('logout', LogoutView.as_view()), # 用户登出 + # --------------------------------------------------- + ] diff --git a/server/util/constant_util.py b/server/util/constant_util.py index 4de4476..8932dc8 100644 --- a/server/util/constant_util.py +++ b/server/util/constant_util.py @@ -1,5 +1,6 @@ CODE_SUCCESS = 0 CODE_FAILED = -1 +DUPLICATE = 1 snapshot_json_data = """{ "id": "root", diff --git a/server/views/mind_map.py b/server/views/mind_map.py index aa0810f..2d239bb 100644 --- a/server/views/mind_map.py +++ b/server/views/mind_map.py @@ -11,6 +11,7 @@ from server.util.mix_util import build_response from server.pagination import DefaultNumberPagination from server_auth.lib.auth import LoginRequiredJSONMixin from server.util.constant_util import * +import uuid class JsMindView(LoginRequiredJSONMixin, ListAPIView): @@ -29,7 +30,7 @@ class JsMindView(LoginRequiredJSONMixin, ListAPIView): """ pk = request.GET.get('id') user = request.user - print(user) + print('list current user: %s' % user) if pk is not None: mind = CooperationMind.objects.filter(id=pk).first() # 序列化 @@ -97,3 +98,30 @@ class JsMindLogView(APIView): data_format = post_body.get('data_format') CooperationMind.objects.filter(id=coop_mind_id, mind_log_id__lt=coop_mind_log_id).update(data_format=data_format, snapshot_data=data, mind_log_id=coop_mind_log_id, update_time=dt.now(), client_uuid=client_uuid) return build_response() + + +class JsMindShareView(LoginRequiredJSONMixin, APIView): + """ + 分享脑图功能,只有创建人能分享 + """ + + def post(self, request): + post_body = request.POST + id = post_body.get('id') + user = request.user + if id is None: + return build_response(code=CODE_FAILED, msg='参数错误') + mind = CooperationMind.objects.filter(id=id, creator_user_id=user.id).first() + if mind is None: + return build_response(code=CODE_FAILED, msg='导图不存在') + + # 校验成功 + share = CooperationMindShare.objects.filter(coop_mind_id=mind.id, operator_user_id=user.id).first() + if share is None: + uuid_str = str(uuid.uuid4()).replace('-', "") + share = CooperationMindShare(coop_mind_id=mind.id, coop_mind_name=mind.coop_mind_name, share_uuid=uuid_str, share_uuid_hash=-1, operator_user_id=user.id) + share.save() + return build_response(data=uuid_str) + + # 重复分享 + return build_response(code=DUPLICATE, data=share.share_uuid) diff --git a/static/html/dashboard.html b/static/html/dashboard.html index f7174b6..8b0aa7f 100644 --- a/static/html/dashboard.html +++ b/static/html/dashboard.html @@ -31,6 +31,7 @@ // 未登录 if (!uid || isNaN(uid)) { $('#login_register').show() + $('#login_register').click() $('#logout_a').hide() $('#newMindModal_btn').hide() } else { @@ -100,7 +101,7 @@
@@ -165,6 +166,21 @@ async: false }); }, + /**分享脑图*/ + share_mind: function (mind_id) { + const me = this + $.ajax({ + type: "post", + url: "share", + headers: {"X-CSRFToken": $.cookie("csrftoken")}, + data: {'id': mind_id}, + dataType: "json", + success: function (data) { + console.log(data) + }, + async: false + }); + }, /** 清除注册时输入内容 */ clear_reg_info: function () { $('#userName').val(''); diff --git a/static/pic/demo_icon.png b/static/pic/demo_icon.png index db1a270..1856283 100644 Binary files a/static/pic/demo_icon.png and b/static/pic/demo_icon.png differ