From 68bd783c3308e6558bb3e70b3d47e2c3dd508f1b Mon Sep 17 00:00:00 2001 From: yangjian Date: Thu, 31 Dec 2020 07:56:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=B6=E8=97=8F=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96=E5=90=8E=E5=8F=B0=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 2 ++ app_admin/views.py | 34 ++++++++++++++---- app_doc/migrations/0037_mycollect.py | 30 ++++++++++++++++ app_doc/models.py | 16 +++++++++ app_doc/urls.py | 1 + app_doc/views.py | 48 ++++++++++++++++++++++++- app_doc/views_user.py | 8 +++++ static/mrdoc/mrdoc-docs.css | 6 ++++ static/mrdoc/mrdoc-docs.js | 2 +- template/app_doc/doc.html | 20 ++++++++--- template/app_doc/docs_base.html | 45 ++++++++++++++++++++++- template/app_doc/editor/create_doc.html | 6 ++-- 12 files changed, 202 insertions(+), 16 deletions(-) create mode 100644 app_doc/migrations/0037_mycollect.py diff --git a/CHANGES.md b/CHANGES.md index 1686a51..5618946 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ - [新增]文集图标配置功能; - [新增]Word(.docx格式)文档导入功能; - [优化]文档编辑器界面样式和交互; +- [修复]仅有私密文集的站点游客可搜索到私密文集的问题; +- [新增]文集水印配置; ### v0.6.2 2020-12 diff --git a/app_admin/views.py b/app_admin/views.py index 162771e..c9c7e61 100644 --- a/app_admin/views.py +++ b/app_admin/views.py @@ -900,43 +900,65 @@ def admin_center_menu(request): "id": 2, "title": "文集管理", "type": 1, - "icon": "layui-icon layui-icon-console", + "icon": "layui-icon layui-icon-list", "href": reverse('project_manage'), }, { "id": 3, "title": "文档管理", "type": 1, - "icon": "layui-icon layui-icon-console", + "icon": "layui-icon layui-icon-form", "href": reverse('doc_manage'), }, { "id": 4, "title": "文档模板管理", "type": 1, - "icon": "layui-icon layui-icon-console", + "icon": "layui-icon layui-icon-templeate-1", "href": reverse('doctemp_manage'), }, { "id": 5, "title": "注册码管理", "type": 1, - "icon": "layui-icon layui-icon-console", + "icon": "layui-icon layui-icon-component", "href": reverse('register_code_manage'), }, { "id": 6, "title": "用户管理", "type": 1, - "icon": "layui-icon layui-icon-console", + "icon": "layui-icon layui-icon-user", "href": reverse('user_manage'), }, { "id": 7, "title": "站点设置", "type": 1, - "icon": "layui-icon layui-icon-console", + "icon": "layui-icon layui-icon-set", "href": reverse('sys_setting'), }, + { + "id": "common", + "title": "使用帮助", + "icon": "layui-icon layui-icon-template-1", + "type": 0, + "href": "", + "children": [{ + "id": 701, + "title": "安装说明", + "icon": "layui-icon layui-icon-face-smile", + "type": 1, + "openType": "_blank", + "href": "http://mrdoc.zmister.com/project-7/" + }, { + "id": 702, + "title": "使用说明", + "icon": "layui-icon layui-icon-face-smile", + "type": 1, + "openType": "_blank", + "href": "http://mrdoc.zmister.com/project-54/" + }] + } ] return JsonResponse(menu_data,safe=False) diff --git a/app_doc/migrations/0037_mycollect.py b/app_doc/migrations/0037_mycollect.py new file mode 100644 index 0000000..5aa58ae --- /dev/null +++ b/app_doc/migrations/0037_mycollect.py @@ -0,0 +1,30 @@ +# Generated by Django 2.2.12 on 2020-12-30 21:02 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('app_doc', '0036_auto_20201229_2004'), + ] + + operations = [ + migrations.CreateModel( + name='MyCollect', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('collect_type', models.IntegerField(verbose_name='收藏类型')), + ('collect_id', models.IntegerField(verbose_name='收藏对象ID')), + ('create_time', models.DateTimeField(auto_now_add=True)), + ('create_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': '我的收藏', + 'verbose_name_plural': '我的收藏', + }, + ), + ] diff --git a/app_doc/models.py b/app_doc/models.py index d694331..ff55596 100644 --- a/app_doc/models.py +++ b/app_doc/models.py @@ -250,4 +250,20 @@ class Attachment(models.Model): class Meta: verbose_name = '附件管理' + verbose_name_plural = verbose_name + + +# 我的收藏 +class MyCollect(models.Model): + # 收藏类型 1表示文档 2表示文集 + collect_type = models.IntegerField(verbose_name="收藏类型") + collect_id = models.IntegerField(verbose_name="收藏对象ID") + create_user = models.ForeignKey(User,on_delete=models.CASCADE) + create_time = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return self.collect_type + + class Meta: + verbose_name = '我的收藏' verbose_name_plural = verbose_name \ No newline at end of file diff --git a/app_doc/urls.py b/app_doc/urls.py index 848dc9d..e3a7b3c 100644 --- a/app_doc/urls.py +++ b/app_doc/urls.py @@ -64,4 +64,5 @@ urlpatterns = [ path('doc_search/', views_search.DocSearchView(),name="doc_search"), # 全文检索框架 path('manage_overview/',views.manage_overview,name="manage_overview"), # 个人中心概览 path('manage_self/',views.manage_self,name="manage_self"), # 个人设置 + path('my_collect/',views.my_collect,name="my_collect"), # 我的收藏 ] \ No newline at end of file diff --git a/app_doc/views.py b/app_doc/views.py index 72bbdd4..9e1c0fe 100644 --- a/app_doc/views.py +++ b/app_doc/views.py @@ -323,6 +323,13 @@ def project_index(request,pro_id): # 获取文集的协作成员 colla_user_list = ProjectCollaborator.objects.filter(project=project) + # 获取文集收藏状态 + if request.user.is_authenticated: + is_collect_pro = MyCollect.objects.filter( + collect_type=2,collect_id=pro_id,create_user=request.user).exists() + else: + is_collect_pro = False + # 获取文集的协作用户信息 if request.user.is_authenticated: # 对登陆用户查询其协作文档信息 colla_user = ProjectCollaborator.objects.filter(project=project,user=request.user).count() @@ -849,6 +856,16 @@ def doc(request,pro_id,doc_id): else: colla_user = 0 + # 获取文集收藏状态 + if request.user.is_authenticated: + is_collect_pro = MyCollect.objects.filter(collect_type=2, collect_id=pro_id, + create_user=request.user).exists() + # 获取文档收藏状态 + is_collect_doc = MyCollect.objects.filter(collect_type=1, collect_id=doc_id, + create_user=request.user).exists() + else: + is_collect_pro,is_collect_doc = False,False + # 私密文集且访问者非创建者、协作者 - 不能访问 if (project.role == 1) and (request.user != project.create_user) and (colla_user == 0): return render(request, '404.html') @@ -2936,4 +2953,33 @@ def manage_self(request): ) return JsonResponse({'status':True,'data':'ok'}) else: - return JsonResponse({'status':False,'data':'参数不正确'}) \ No newline at end of file + return JsonResponse({'status':False,'data':'参数不正确'}) + + +# 文集文档收藏 +@login_required() +def my_collect(request): + if request.method == 'GET': + pass + elif request.method == 'POST': + collect_type = request.POST.get('type',None) # 收藏类型 + collect_id = request.POST.get('id',None) # 收藏对象ID + if (collect_type is None) or (collect_id is None): + return JsonResponse({'status':False,'data':'参数错误'}) + else: + is_collect = MyCollect.objects.filter(collect_type=collect_type,collect_id=collect_id,create_user=request.user) + # 存在收藏 + if is_collect.exists(): + is_collect.delete() + return JsonResponse({'status': True, 'data': '取消收藏成功'}) + else: + MyCollect.objects.create( + collect_type = collect_type, + collect_id = collect_id, + create_user = request.user, + create_time = datetime.datetime.now() + ) + return JsonResponse({'status':True,'data':'收藏成功'}) + + elif request.method == 'DELETE': + pass \ No newline at end of file diff --git a/app_doc/views_user.py b/app_doc/views_user.py index c725967..b6676e0 100644 --- a/app_doc/views_user.py +++ b/app_doc/views_user.py @@ -177,6 +177,14 @@ def user_center_menu(request): }, ] }, + { + "id": "user_manual", + "title": "使用手册", + "icon": "layui-icon layui-icon-template-1", + "type": 1, + "openType": "_blank", + "href": "http://mrdoc.zmister.com/project-54/", + } # { # "id": "common", # "title": "使用帮助", diff --git a/static/mrdoc/mrdoc-docs.css b/static/mrdoc/mrdoc-docs.css index efb7f0e..6a18a8e 100644 --- a/static/mrdoc/mrdoc-docs.css +++ b/static/mrdoc/mrdoc-docs.css @@ -101,4 +101,10 @@ li.L1, li.L3, li.L5, li.L7, li.L9 { position: absolute; opacity: 0.1; pointer-events: none; +} +.collected{ + color: rgb(250, 173, 20); +} +.doc-bottom-icon,.doc-bottom-btn{ + cursor: pointer; } \ No newline at end of file diff --git a/static/mrdoc/mrdoc-docs.js b/static/mrdoc/mrdoc-docs.js index 5c9c76d..fe47e7d 100644 --- a/static/mrdoc/mrdoc-docs.js +++ b/static/mrdoc/mrdoc-docs.js @@ -307,7 +307,7 @@ doc_qrcode = function(){ }; doc_qrcode(); - +// 文集水印 textBecomeImg = function(text,fontsize,fontcolor){ var canvas = document.createElement('canvas'); canvas.height = 180; diff --git a/template/app_doc/doc.html b/template/app_doc/doc.html index 0db5266..06b1c68 100644 --- a/template/app_doc/doc.html +++ b/template/app_doc/doc.html @@ -71,20 +71,32 @@
- + {% if doc.create_user.first_name != '' %} {{doc.create_user.first_name}} {% else %} {{doc.create_user.username}}{% endif %} - + {{ doc.modify_time }} + + {% if request.user.is_authenticated %} + {% if is_collect_doc %} + {% trans "收藏文档" %} + {% else %} + {% trans "收藏文档" %} + {% endif %} + {% else %} + {% trans "收藏文档" %} + {% endif %} + + {% if request.user == doc.create_user or request.user.is_superuser %} {% endif %}
diff --git a/template/app_doc/docs_base.html b/template/app_doc/docs_base.html index d77194f..8183dbd 100644 --- a/template/app_doc/docs_base.html +++ b/template/app_doc/docs_base.html @@ -55,6 +55,15 @@ {% endif %} + {% if request.user.is_authenticated %} + {% if is_collect_pro %} + + {% else %} + + {% endif %} + {% else %} + + {% endif %}

{% if colla_user > 0 %} {% trans "* 此为协作文集" %} @@ -389,7 +398,6 @@ {% if project.is_watermark %} var img_base64 = textBecomeImg('{{project.watermark_value}}','14','#000') - console.log(img_base64) document.getElementById("wm").style.background = 'url('+ img_base64 + ')' {% endif %} @@ -408,6 +416,41 @@ }; var img_viewer = new Viewer(document.getElementById('content'), img_options); {% endif %} + + // 收藏文集 + var layer = layui.layer; + $("#collect_pro").click(function(e){ + $(this).toggleClass("layui-icon-star-fill layui-icon-star"); + $(this).toggleClass("collected"); + $.ajax({ + url:'/my_collect/', + type:'post', + data:{'type':2,'id':'{{project.id}}'}, + success:function(r){ + layer.msg(r.data) + }, + error:function(){ + layer.msg("操作异常") + } + }); + }); + // 收藏文档 + $("#collect_doc").click(function(){ + $(this).toggleClass("layui-icon-star-fill layui-icon-star") + $(this).toggleClass("collected") + $.ajax({ + url:'/my_collect/', + type:'post', + data:{'type':1,'id':'{{doc.id}}'}, + success:function(r){ + layer.msg(r.data) + }, + error:function(){ + layer.msg("操作异常") + } + }) + }); + diff --git a/template/app_doc/editor/create_doc.html b/template/app_doc/editor/create_doc.html index 14b94ba..759abc3 100644 --- a/template/app_doc/editor/create_doc.html +++ b/template/app_doc/editor/create_doc.html @@ -310,10 +310,10 @@ layer.closeAll("loading"); //关闭加载层 window.localStorage.removeItem('mrdoc_doc_cache') // 清空文档缓存 if(status === 1){ - layer.msg('发布成功,即将跳转到文档页面',function(){ + layer.msg('发布成功',{time:1000},function(){ md_changed = false; - //跳转到发布的文档 - window.location.href = "/project-" + r.data.pro + "/doc-" + r.data.doc + //跳转到文档修改 + window.location.href = "/modify_doc/"+r.data.doc+"/"; }); }else{ layer.msg('保存成功',{time:1000},function(){