From da6f349faa41bd2e3b50830d082340d7408172cf Mon Sep 17 00:00:00 2001 From: chenyang Date: Sun, 10 Jul 2022 12:30:58 +0800 Subject: [PATCH] update --- server/views/mind_map.py | 14 +++++++ static/html/dashboard.html | 76 +++++++++++++++++++++++++++----------- 2 files changed, 69 insertions(+), 21 deletions(-) diff --git a/server/views/mind_map.py b/server/views/mind_map.py index 0aba43e..2078178 100644 --- a/server/views/mind_map.py +++ b/server/views/mind_map.py @@ -165,3 +165,17 @@ class JsMindShareView(LoginRequiredJSONMixin, ListAPIView): # 重复分享 return build_response(code=DUPLICATE, data={"u": share.share_uuid, "h": share.share_uuid_hash}) + + def delete(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='参数错误') + if user.id is None: + return build_response(code=CODE_FAILED, msg='用户未登录') + res = CooperationMindShare.objects.filter(coop_mind_id=id, operator_user_id=user.id).delete() + return build_response(msg="操作成功", data=res[0]) diff --git a/static/html/dashboard.html b/static/html/dashboard.html index 309f764..a46df2c 100644 --- a/static/html/dashboard.html +++ b/static/html/dashboard.html @@ -22,11 +22,12 @@ this.uuid = (new Date().getTime().toString(16) + Math.random().toString(16).substr(2)).substr(2, 16) this.current_page_num = 1 this.default_page_size = 15 + this.title_map = new Map([["main", "全部文件"], ["share", "我的分享"]]);// k-v 的形式 } DefaultView.prototype = { /**界面初始化*/ - view_init: function () { + init_view: function () { const uid = $('#uid').html() // 未登录 if (!uid || isNaN(uid)) { @@ -40,6 +41,10 @@ $('#login_register').hide() $('#logout_a').show() } + + // 判断页面 + const src_page = this.get_src_page() + $('#main h5').html(this.title_map.get(src_page)) }, get_uu_id: function () { return (new Date().getTime().toString(16) + Math.random().toString(16).substr(2)).substr(2, 16) @@ -78,7 +83,6 @@ // 获得跳转源页面 const src_page = me.get_src_page() - console.log(src_page) $.ajax({ type: `get`, @@ -96,26 +100,34 @@ const results = resp.results let idx = 0 let row = $(`
`) + + results.forEach(function (item) { const uuid = me.get_uu_id() - const content = ` -
-
-
${item.coop_mind_name}
-
- -
-
- - -
-
-
-
` + + // 添加按钮组 + let sub_btn; + if (src_page === 'main') { + sub_btn = `编辑 + 删除 + 分享` + } else if (src_page === 'share') { + sub_btn = `取消分享` + } + + const content = `
+
+
${item.coop_mind_name}
+
+ +
+
+ + +
+
+
+
` row.append(content) }) @@ -192,6 +204,28 @@ async: false }); }, + /**取消分享*/ + share_cancel: function (mind_id) { + const me = this + $.ajax({ + type: "delete", + url: "share", + headers: {"X-CSRFToken": $.cookie("csrftoken")}, + data: {'id': mind_id}, + dataType: "json", + success: function (resp) { + if (me.is_success_resp(resp)) { + location.reload() + } else { + common_alert(resp.msg) + } + }, + async: false + }); + }, + is_success_resp(resp) { + return resp.code === 0 + }, /** 清除注册时输入内容 */ clear_reg_info: function () { $('#userName').val(''); @@ -384,7 +418,7 @@ $(function () { const view = new DefaultView() /**初始化*/ - view.view_init() + view.init_view() view.jq_listener_init() /**如果已经登录则查询列表*/