取消收藏等

This commit is contained in:
chenyang
2022-07-24 09:04:15 +08:00
parent e878ba145b
commit 344072efc7
3 changed files with 33 additions and 10 deletions
+11 -7
View File
@@ -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="取消收藏,操作成功")
+1 -1
View File
@@ -152,7 +152,7 @@
const container = $('#pagination_div')
/**计算页数*/
if (count <= 0) {
container.empty()
container.html(`<p class="text-center">无数据</p>`)
return
}
+21 -2
View File
@@ -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 @@
<div style="position: absolute;top: 0px;z-index: 1000;cursor: pointer;" onclick="xxObj.collapse_all()"><span data-feather="folder-minus"></span><span class="un_selected">折叠</span></div>
<div style="position: absolute;top: 0px;left:80px;z-index: 1000;cursor: pointer;" onclick="xxObj.expand_all()"><span data-feather="folder-plus"></span><span class="un_selected">展开</span></div>
<div style="position: absolute;top: 0px;left:160px;z-index: 1000;cursor: pointer;" onclick="xxObj.star()"><span data-feather="star"></span><span class="un_selected">收藏</span></div>
<div style="position: absolute;top: 0px;left:240px;z-index: 1000;cursor: pointer;" onclick="xxObj.un_star()"><span data-feather="arrow-up-circle"></span><span class="un_selected">取消收藏</span></div>
<h3 id="h1" style="text-align: center;max-height: 40px;"></h3>
<div id="jsmind_container"></div>
</body>