diff --git a/server/views/mind_map.py b/server/views/mind_map.py index 6a652cc..cf0c37d 100644 --- a/server/views/mind_map.py +++ b/server/views/mind_map.py @@ -37,12 +37,17 @@ class JsMindView(LoginRequiredJSONMixin, ListAPIView): print('list current user: %s' % user) if pk is not None: - # 查询导图详细 查看用户是否有权限(创建者) - mind = CooperationMind.objects.filter(id=pk, creator_user_id=user.id).first() - if mind is None: + # 查询导图详细 查看用户是否有权限 + sql = """ + select * from cooperation_mind mind where id=%s and mind.creator_user_id=%s + union all select m1.* from cooperation_mind m1 join cooperation_mind_share sh on sh.coop_mind_id = m1.id where m1.id=%s and sh.operator_user_id =%s + union all select m1.* from cooperation_mind m1 join cooperation_mind_star st on st.coop_mind_id = m1.id where m1.id=%s and st.operator_user_id =%s + """ % (pk, user.id, pk, user.id, pk, user.id) + mind = CooperationMind.objects.raw(sql) + if len(mind) is None: return build_response(code=CODE_FAILED, msg="无权限") # 序列化 - serializer = CooperationMindSerializer(mind) + serializer = CooperationMindSerializer(mind[0]) return build_response(data=serializer.data) # 查询列表 @@ -237,15 +242,14 @@ class JsMindStarView(LoginRequiredJSONMixin, ListAPIView): if star is None: star = CooperationMindStar(operator_user_id=user.id, coop_mind_id=coop_mind_id, coop_mind_name=mind.coop_mind_name) star.save() - return build_response() + return build_response(msg="收藏成功") def delete(self, request): """ 取消收藏 """ - print('dlete') post_body = request.POST user = request.user coop_mind_id = post_body.get('coop_mind_id') CooperationMindStar.objects.filter(operator_user_id=user.id, coop_mind_id=coop_mind_id).delete() - return build_response() + return build_response(msg="取消收藏,操作成功") diff --git a/static/html/dashboard.html b/static/html/dashboard.html index de2a658..8054e57 100644 --- a/static/html/dashboard.html +++ b/static/html/dashboard.html @@ -152,7 +152,7 @@ const container = $('#pagination_div') /**计算页数*/ if (count <= 0) { - container.empty() + container.html(`
无数据
`) return } diff --git a/static/html/detail.html b/static/html/detail.html index 28f90ce..cd847f7 100644 --- a/static/html/detail.html +++ b/static/html/detail.html @@ -35,6 +35,7 @@ this.jm = null this.coop_mind_id = null this.coop_mind_log_id = null + /**是否通过分享链接访问*/ this.from_share = null } // prototype @@ -144,8 +145,6 @@ /**收藏或者取消收藏*/ star: function () { const coop_mind_id = this.coop_mind_id - console.log(`this.from_share:${this.from_share}`) - // ajax start $.ajax({ type: "post", @@ -159,8 +158,27 @@ async: false }); // ajax end + }, + /**取消收藏*/ + un_star: function () { + const coop_mind_id = this.coop_mind_id + // ajax start + $.ajax({ + type: "delete", + url: "star", + headers: {"X-CSRFToken": $.cookie("csrftoken")}, + data: {'coop_mind_id': coop_mind_id}, + dataType: "json", + success: function (resp) { + common_alert(resp.msg) + }, + async: false + }); + // ajax end } } + + /***/ $(function () { const xxObj = new fetch() xxObj.loadMind() @@ -173,6 +191,7 @@