forked from mirror/MrDoc
后台文集文档管理替换为数据表格,优化个人中心文档管理
This commit is contained in:
parent
f35df1e1e4
commit
13101b221c
@ -362,32 +362,47 @@ def admin_del_user(request):
|
||||
@logger.catch()
|
||||
def admin_project(request):
|
||||
if request.method == 'GET':
|
||||
search_kw = request.GET.get('kw','')
|
||||
if search_kw == '':
|
||||
project_list = Project.objects.all().order_by('-create_time')
|
||||
paginator = Paginator(project_list,10)
|
||||
page = request.GET.get('page',1)
|
||||
try:
|
||||
projects = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
projects = paginator.page(1)
|
||||
except EmptyPage:
|
||||
projects = paginator.page(paginator.num_pages)
|
||||
else:
|
||||
project_list = Project.objects.filter(intro__icontains=search_kw)
|
||||
paginator = Paginator(project_list, 10)
|
||||
page = request.GET.get('page', 1)
|
||||
|
||||
try:
|
||||
projects = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
projects = paginator.page(1)
|
||||
except EmptyPage:
|
||||
projects = paginator.page(paginator.num_pages)
|
||||
projects.kw = search_kw
|
||||
return render(request,'app_admin/admin_project.html',locals())
|
||||
else:
|
||||
return HttpResponse('方法错误')
|
||||
elif request.method == 'POST':
|
||||
kw = request.POST.get('kw', '')
|
||||
page = request.POST.get('page', 1)
|
||||
limit = request.POST.get('limit', 10)
|
||||
# 获取文集列表
|
||||
if kw == '':
|
||||
project_list = Project.objects.all().order_by('-create_time')
|
||||
else:
|
||||
project_list = Project.objects.filter(
|
||||
Q(intro__icontains=kw) | Q(name__icontains=kw),
|
||||
).order_by('-create_time')
|
||||
paginator = Paginator(project_list, limit)
|
||||
try:
|
||||
pros = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
pros = paginator.page(1)
|
||||
except EmptyPage:
|
||||
pros = paginator.page(paginator.num_pages)
|
||||
table_data = []
|
||||
for project in pros:
|
||||
item = {
|
||||
'id': project.id,
|
||||
'name': project.name,
|
||||
'intro': project.intro,
|
||||
'doc_total': Doc.objects.filter(top_doc=project.id).count(),
|
||||
'role': project.role,
|
||||
'role_value': project.role_value,
|
||||
'colla_total': ProjectCollaborator.objects.filter(project=project).count(),
|
||||
'create_user':project.create_user.username,
|
||||
'create_time': project.create_time,
|
||||
'modify_time': project.modify_time
|
||||
}
|
||||
table_data.append(item)
|
||||
resp_data = {
|
||||
"code": 0,
|
||||
"msg": "ok",
|
||||
"count": project_list.count(),
|
||||
"data": table_data
|
||||
}
|
||||
return JsonResponse(resp_data)
|
||||
|
||||
# 后台管理 - 修改文集权限
|
||||
@superuser_only
|
||||
@ -429,29 +444,93 @@ def admin_project_role(request,pro_id):
|
||||
@logger.catch()
|
||||
def admin_doc(request):
|
||||
if request.method == 'GET':
|
||||
kw = request.GET.get('kw','')
|
||||
if kw == '':
|
||||
doc_list = Doc.objects.all().order_by('-modify_time')
|
||||
paginator = Paginator(doc_list, 10)
|
||||
page = request.GET.get('page', 1)
|
||||
try:
|
||||
docs = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
docs = paginator.page(1)
|
||||
except EmptyPage:
|
||||
docs = paginator.page(paginator.num_pages)
|
||||
else:
|
||||
doc_list = Doc.objects.filter(Q(content__icontains=kw) | Q(name__icontains=kw)).order_by('-modify_time')
|
||||
paginator = Paginator(doc_list, 10)
|
||||
page = request.GET.get('page', 1)
|
||||
try:
|
||||
docs = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
docs = paginator.page(1)
|
||||
except EmptyPage:
|
||||
docs = paginator.page(paginator.num_pages)
|
||||
docs.kw = kw
|
||||
# 文集列表
|
||||
project_list = Project.objects.all() # 自己创建的文集列表
|
||||
# 文档数量
|
||||
# 已发布文档数量
|
||||
published_doc_cnt = Doc.objects.filter(status=1).count()
|
||||
# 草稿文档数量
|
||||
draft_doc_cnt = Doc.objects.filter(status=0).count()
|
||||
# 所有文档数量
|
||||
all_cnt = published_doc_cnt + draft_doc_cnt
|
||||
return render(request,'app_admin/admin_doc.html',locals())
|
||||
elif request.method == 'POST':
|
||||
kw = request.POST.get('kw', '')
|
||||
project = request.POST.get('project', '')
|
||||
status = request.POST.get('status', '')
|
||||
if status == '-1': # 全部文档
|
||||
q_status = [0, 1]
|
||||
elif status in ['0', '1']:
|
||||
q_status = [int(status)]
|
||||
else:
|
||||
q_status = [0, 1]
|
||||
|
||||
if project == '':
|
||||
project_list = Project.objects.all().values_list('id', flat=True) # 自己创建的文集列表
|
||||
q_project = list(project_list)
|
||||
else:
|
||||
q_project = [project]
|
||||
|
||||
page = request.POST.get('page', 1)
|
||||
limit = request.POST.get('limit', 10)
|
||||
# 没有搜索
|
||||
if kw == '':
|
||||
doc_list = Doc.objects.filter(
|
||||
status__in=q_status,
|
||||
top_doc__in=q_project
|
||||
).order_by('-modify_time')
|
||||
# 有搜索
|
||||
else:
|
||||
doc_list = Doc.objects.filter(
|
||||
Q(content__icontains=kw) | Q(name__icontains=kw),
|
||||
status__in=q_status, top_doc__in=q_project
|
||||
).order_by('-modify_time')
|
||||
|
||||
# 文集列表
|
||||
project_list = Project.objects.filter(create_user=request.user) # 自己创建的文集列表
|
||||
colla_project_list = ProjectCollaborator.objects.filter(user=request.user) # 协作的文集列表
|
||||
|
||||
# 文档数量
|
||||
# 已发布文档数量
|
||||
published_doc_cnt = Doc.objects.filter(create_user=request.user, status=1).count()
|
||||
# 草稿文档数量
|
||||
draft_doc_cnt = Doc.objects.filter(create_user=request.user, status=0).count()
|
||||
# 所有文档数量
|
||||
all_cnt = published_doc_cnt + draft_doc_cnt
|
||||
|
||||
# 分页处理
|
||||
paginator = Paginator(doc_list, limit)
|
||||
page = request.GET.get('page', page)
|
||||
try:
|
||||
docs = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
docs = paginator.page(1)
|
||||
except EmptyPage:
|
||||
docs = paginator.page(paginator.num_pages)
|
||||
|
||||
table_data = []
|
||||
for doc in docs:
|
||||
item = {
|
||||
'id': doc.id,
|
||||
'name': doc.name,
|
||||
'parent': Doc.objects.get(id=doc.parent_doc).name if doc.parent_doc != 0 else '无',
|
||||
'project_id': Project.objects.get(id=doc.top_doc).id,
|
||||
'project_name': Project.objects.get(id=doc.top_doc).name,
|
||||
'status': doc.status,
|
||||
'editor_mode': doc.editor_mode,
|
||||
'open_children': doc.open_children,
|
||||
'create_user':doc.create_user.username,
|
||||
'create_time': doc.create_time,
|
||||
'modify_time': doc.modify_time
|
||||
}
|
||||
table_data.append(item)
|
||||
resp_data = {
|
||||
"code": 0,
|
||||
"msg": "ok",
|
||||
"count": doc_list.count(),
|
||||
"data": table_data
|
||||
}
|
||||
return JsonResponse(resp_data)
|
||||
|
||||
|
||||
# 后台管理 - 文档模板管理
|
||||
|
@ -4,114 +4,174 @@
|
||||
{% block title %}文档管理{% endblock %}
|
||||
{% block content %}
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">高级筛选</div>
|
||||
<div class="layui-card-body">
|
||||
<div class="layui-card-header" style="margin-bottom: 10px;">
|
||||
<div class="layui-row">
|
||||
<span style="font-size:18px;">文档管理
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-row">
|
||||
<form action="{% url 'doc_manage' %}" method="get">
|
||||
<div class="layui-form">
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="kw" id="kw" placeholder="输入文档标题或内容" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
<button class="layui-btn layui-btn-normal layui-btn-sm" type="submit"><i class="layui-icon layui-icon-search"></i>搜索</button>
|
||||
<a href="{% url 'create_doc' %}" target="_blank" class="layui-btn layui-btn-normal layui-btn-sm"><i class="layui-icon layui-icon-addition"></i>新建文档</a>
|
||||
<label class="layui-form-label">关键词</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="kw" placeholder="请输入标题" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
<button class="layui-btn layui-btn-normal layui-btn-sm" id="search">搜索</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<!-- 表格数据 -->
|
||||
<div class="layui-row">
|
||||
<table class="layui-table" id="doctemp-list" lay-skin="nob" lay-even>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>文档名称</th>
|
||||
<th>上级文档</th>
|
||||
<th>所属文集</th>
|
||||
<th>创建人</th>
|
||||
<th>创建时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% load doc_filter %}
|
||||
{% for doc in docs %}
|
||||
<tr>
|
||||
{% if doc.status == 1 %}
|
||||
<td>
|
||||
<a href="{% url 'doc' doc.top_doc doc.id %}" target="_blank" title="查看文档:{{doc.name}}">{{ doc.name }}
|
||||
<i class="layui-icon layui-icon-circle-dot" style="color: #1E9FFF;"></i>
|
||||
</a>
|
||||
</td>
|
||||
{% else %}
|
||||
<td>
|
||||
<a href="{% url 'modify_doc' doc.id %}" target="_blank" title="修改文档:{{doc.name}}">{{ doc.name }}
|
||||
<i class="layui-icon layui-icon-circle-dot" style="color: #FF5722;"></i>
|
||||
</a>
|
||||
</td>
|
||||
{% endif %}
|
||||
<td>{{ doc.parent_doc|get_doc_parent }}</td>
|
||||
<td>{{ doc.top_doc|get_doc_top }}</td>
|
||||
<td>{{ doc.create_user }}</td>
|
||||
<td>{{ doc.create_time }}</td>
|
||||
<td>
|
||||
<a href="{% url 'modify_doc' doc_id=doc.id %}" target="_blank" class="layui-btn layui-btn-normal layui-btn-xs">
|
||||
<i class="layui-icon layui-icon-edit"></i>修改
|
||||
</a>
|
||||
<a href="javascript:void(0);" onclick="delDoc('{{doc.id}}');" class="layui-btn layui-btn-warm layui-btn-xs">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- 分页 -->
|
||||
<div class="layui-row">
|
||||
<div class="layui-box layui-laypage layui-laypage-default">
|
||||
<!-- 上一页 -->
|
||||
{% if docs.has_previous %}
|
||||
<a href="?page={{ docs.previous_page_number }}&kw={{docs.kw}}&status={{docs.status}}" class="layui-btn layui-btn-xs layui-btn-normal">上一页</a>
|
||||
{% else %}
|
||||
<a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-disabled">上一页</a>
|
||||
{% endif %}
|
||||
<!-- 当前页 -->
|
||||
<span class="layui-laypage-curr">
|
||||
<em class="layui-laypage-em"></em>
|
||||
<em>{{ docs.number }}/{{ docs.paginator.num_pages }}</em>
|
||||
</span>
|
||||
<!-- 下一页 -->
|
||||
{% if docs.has_next %}
|
||||
<a href="?page={{ docs.next_page_number }}&kw={{docs.kw}}&status={{docs.status}}" class="layui-btn layui-btn-xs layui-btn-normal">下一页</a>
|
||||
{% else %}
|
||||
<a class="layui-btn layui-btn-xs layui-btn-disabled">下一页</a>
|
||||
{% endif %}
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">文集</label>
|
||||
<div class="layui-input-inline">
|
||||
<select name="pro_id" lay-verify="required" lay-filter="project" id="project">
|
||||
<option value="">按文集筛选</option>
|
||||
{% for p in project_list %}
|
||||
{% if p.role == 1 %}
|
||||
<option value="{{ p.id }}">[私密]《{{ p.name }}》</option>
|
||||
{% elif p.role == 2 %}
|
||||
<option value="{{ p.id }}" >[指定用户]《{{ p.name }}》</option>
|
||||
{% elif p.role == 3 %}
|
||||
<option value="{{ p.id }}" >[访问码]《{{ p.name }}》</option>
|
||||
{% else %}
|
||||
<option value="{{ p.id }}" >[公开]《{{ p.name }}》</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">文档状态</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="status" title="全部({{all_cnt}})" value="-1" lay-skin="primary" checked lay-filter="doc_status">
|
||||
<input type="radio" name="status" title="草稿({{draft_doc_cnt}})" value="0" lay-skin="primary" lay-filter="doc_status">
|
||||
<input type="radio" name="status" title="已发布({{published_doc_cnt}})" value="1" lay-skin="primary" lay-filter="doc_status">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<table id="doc-table" lay-filter="doc-table"></table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 表格工具栏 -->
|
||||
<script type="text/html" id="doc-toolbar">
|
||||
<a class="layui-btn layui-btn-normal pear-btn-sm" href="/create_doc/" target="_blank">
|
||||
<i class="layui-icon layui-icon-add-1"></i>新增
|
||||
</a>
|
||||
<button class="layui-btn layui-btn-warm pear-btn-sm" lay-event="batchRemove">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<!-- 文档名称 -->
|
||||
<script type="text/html" id="doc-name">
|
||||
{% verbatim %}
|
||||
{{#if (d.status == 1) { }}
|
||||
<span class="layui-badge-dot layui-bg-blue"></span>
|
||||
<a href="/project-{{d.project_id}}/doc-{{d.id}}" target="_blank">{{d.name}}</a>
|
||||
{{# }else if(d.status == 0){ }}
|
||||
<!-- <i class="layui-icon layui-icon-release" style="cursor: pointer;" onclick="fastPubDoc('{{d.id}}')" title="草稿状态,点击一键发布"></i> -->
|
||||
<span class="layui-badge-dot layui-bg-orange"></span>
|
||||
<a href="/modify_doc/{{d.id}}/" target="_blank" title="修改文档:{{d.name}}">{{ d.name }} </a>
|
||||
{{# } }}
|
||||
{% endverbatim %}
|
||||
</script>
|
||||
|
||||
<!-- 文档状态 -->
|
||||
<script type="text/html" id="doc-status">
|
||||
{% verbatim %}
|
||||
{{#if (d.status == 1) { }}
|
||||
<span class="layui-badge-rim">已发布</span>
|
||||
{{# }else if(d.status == 0){ }}
|
||||
<!-- <i class="layui-icon layui-icon-release" style="cursor: pointer;" onclick="fastPubDoc('{{d.id}}')" title="草稿状态,点击一键发布"></i> -->
|
||||
<span class="layui-badge-rim" style="cursor: pointer;" onclick="fastPubDoc('{{d.id}}')" title="点击一键发布">草稿</span>
|
||||
{{# } }}
|
||||
{% endverbatim %}
|
||||
</script>
|
||||
|
||||
<!-- 修改时间 -->
|
||||
<script type="text/html" id="doc-modify-time">
|
||||
{% verbatim %}
|
||||
{{layui.util.toDateString(d.modify_time, "yyyy-MM-dd HH:mm:ss")}}
|
||||
{% endverbatim %}
|
||||
</script>
|
||||
|
||||
<!-- 编辑模式 -->
|
||||
<script type="text/html" id="editor-mode">
|
||||
{% verbatim %}
|
||||
{{#if (d.editor_mode == 1) { }}
|
||||
Editor.MD
|
||||
{{# }else if(d.editor_mode == 2){ }}
|
||||
Vditor
|
||||
{{# } }}
|
||||
{% endverbatim %}
|
||||
</script>
|
||||
|
||||
<!-- 展开下级 -->
|
||||
<script type="text/html" id="open_children">
|
||||
{% verbatim %}
|
||||
{{#if (d.open_children == true) { }}
|
||||
展开
|
||||
{{# }{ }}
|
||||
收起
|
||||
{{# } }}
|
||||
{% endverbatim %}
|
||||
</script>
|
||||
|
||||
<!-- 单个文档操作 -->
|
||||
<script type="text/html" id="doc-bar">
|
||||
{% verbatim %}
|
||||
<a href="/manage_doc_history/{{d.id}}/" class="layui-btn layui-btn-primary pear-btn-sm"><i class="layui-icon layui-icon-log"></i></a>
|
||||
<!-- <a href="/modify_doc/{{d.id}}/" title="修改文档" class="layui-btn layui-btn-primary pear-btn-sm" target="_blank"><i class="layui-icon layui-icon-edit"></i></a> -->
|
||||
<button class="layui-btn layui-btn-warm pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
|
||||
{% endverbatim %}
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
{% block custom_script %}
|
||||
<script>
|
||||
layui.use(['table','jquery','form','layer','element'], function() {
|
||||
layui.use(['table', 'form', 'jquery', 'dtree','layer'], function() {
|
||||
let table = layui.table;
|
||||
let form = layui.form;
|
||||
let $ = layui.jquery;
|
||||
let layer = layui.layer;
|
||||
let element = layui.element;
|
||||
let dtree = layui.dtree;
|
||||
var layer = layui.layer;
|
||||
$.ajaxSetup({
|
||||
data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
});
|
||||
let cols = [
|
||||
[
|
||||
{type: 'checkbox',width:20},
|
||||
{title: '文档名称',field: 'name',align: 'left',templet:"#doc-name",minWidth:280},
|
||||
{title: '状态',field: 'status',align: 'left',templet:"#doc-status",width:90},
|
||||
{title: '上级',field: 'parent',align: 'left',},
|
||||
{title: '文集',field: 'project_name',align: 'left',templet:"#project-role"},
|
||||
{title: '编辑模式',field: 'editor_mode',align: 'left',templet:"#editor-mode",width:90},
|
||||
{title: '展开下级',field: 'open_children',align: 'left',width:90, templet:"#open_children"},
|
||||
{title: '文档作者',field: 'create_user',align: 'left',},
|
||||
{title: '最后编辑',field: 'modify_time',align: 'left',templet:"#doc-modify-time"},
|
||||
{title: '操作',toolbar: '#doc-bar',align: 'left',} ]
|
||||
]
|
||||
// 渲染表格
|
||||
table.render({
|
||||
elem: '#doc-table',
|
||||
method:'post',
|
||||
where:{
|
||||
'type':1,
|
||||
},
|
||||
url: "{% url 'doc_manage' %}",
|
||||
page: true,
|
||||
cols: cols,
|
||||
skin: 'line',
|
||||
toolbar: '#doc-toolbar',
|
||||
defaultToolbar: ['filter']
|
||||
});
|
||||
// 删除文档
|
||||
delDoc = function(doc_id){
|
||||
layer.open({
|
||||
type:1,
|
||||
title:'删除文档',
|
||||
area:'300px;',
|
||||
id:'delPro',//配置ID
|
||||
content:'<div style="margin-left:10px;">警告:将删除此文档!</div>',
|
||||
content:'<div style="margin-left:10px;">警告:此操作将删除此文档!</div>',
|
||||
btn:['确定','取消'], //添加按钮
|
||||
btnAlign:'c', //按钮居中
|
||||
yes:function (index,layero) {
|
||||
@ -120,7 +180,7 @@
|
||||
'doc_id':doc_id,
|
||||
}
|
||||
$.post("{% url 'del_doc' %}",data,function(r){
|
||||
layer.closeAll('loading');
|
||||
layer.closeAll('loading')
|
||||
if(r.status){
|
||||
//修改成功
|
||||
window.location.reload();
|
||||
@ -133,7 +193,112 @@
|
||||
})
|
||||
},
|
||||
});
|
||||
};
|
||||
// 一键发布文档
|
||||
fastPubDoc = function(doc_id){
|
||||
data = {
|
||||
'doc_id':doc_id,
|
||||
}
|
||||
$.post("{% url 'fast_pub_doc' %}",data,function(r){
|
||||
layer.closeAll('loading')
|
||||
if(r.status){
|
||||
//发布成功
|
||||
window.location.reload();
|
||||
}else{
|
||||
//发布失败,提示
|
||||
console.log(r)
|
||||
layer.msg(r.data)
|
||||
}
|
||||
})
|
||||
};
|
||||
// 批量删除文档
|
||||
batchRemoveDoc = function(obj) {
|
||||
let data = table.checkStatus(obj.config.id).data;
|
||||
if (data.length === 0) {
|
||||
layer.msg("未选中任何文档", {
|
||||
icon: 3,
|
||||
time: 1000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
let doc_id = "";
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
doc_id += data[i].id + ",";
|
||||
}
|
||||
doc_id = doc_id.substr(0, doc_id.length - 1);
|
||||
// console.log(pro_id)
|
||||
layer.confirm('确定要删除这些文档?', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function(index) {
|
||||
layer.close(index);
|
||||
let loading = layer.load();
|
||||
$.ajax({
|
||||
url: "{% url 'del_doc' %}",
|
||||
dataType: 'json',
|
||||
type: 'post',
|
||||
data:{'doc_id':doc_id,'range':'multi'},
|
||||
success: function(r) {
|
||||
layer.close(loading);
|
||||
if (r.status) {
|
||||
layer.msg("删除成功", {
|
||||
icon: 1,
|
||||
time: 1000
|
||||
}, function() {
|
||||
table.reload('doc-table');
|
||||
});
|
||||
} else {
|
||||
layer.msg(r.data, {
|
||||
icon: 2,
|
||||
time: 1000
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
// 监听文集筛选
|
||||
form.on('select(project)', function(data){
|
||||
console.log('选择文集:',data.value); //得到被选中的值
|
||||
table.reload('doc-table',{
|
||||
where:{
|
||||
'type':1,'project':data.value,
|
||||
},
|
||||
})
|
||||
});
|
||||
// 监听状态筛选
|
||||
form.on('radio(doc_status)', function(data){
|
||||
console.log(data.value); //被点击的radio的value值
|
||||
table.reload('doc-table',{
|
||||
where:{
|
||||
'type':1,'status':data.value,
|
||||
},
|
||||
})
|
||||
});
|
||||
// 监听搜索按钮
|
||||
$("#search").click(function(){
|
||||
table.reload('doc-table',{
|
||||
where:{
|
||||
'type':1,'kw':$("input[name=kw]").val(),
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
// 侦听文档删除按钮
|
||||
table.on("tool(doc-table)",function(obj){
|
||||
if (obj.event === 'remove') {
|
||||
// console.log(obj)
|
||||
delDoc(obj.data.id)
|
||||
}
|
||||
});
|
||||
// 侦听表格工具栏
|
||||
table.on("toolbar(doc-table)",function(obj){
|
||||
if (obj.event === 'add') { // 新增文集
|
||||
createProject();
|
||||
}else if(obj.event === 'batchRemove'){ // 批量删除文集
|
||||
batchRemoveDoc(obj)
|
||||
}
|
||||
});
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
@ -5,120 +5,142 @@
|
||||
{% block content %}
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<div class="layui-card-header" style="margin-bottom: 10px;">
|
||||
<div class="layui-row">
|
||||
<span style="font-size:18px;">文集管理
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-row">
|
||||
<form action="{% url 'project_manage' %}" method="get">
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="kw" id="kw" placeholder="输入文集内容" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
<button class="layui-btn layui-btn-normal layui-btn-sm" type="submit"><i class="layui-icon layui-icon-search"></i>搜索</button>
|
||||
<button class="layui-btn layui-btn-normal layui-btn-sm" onclick="createProject()" type="button"><i class="layui-icon layui-icon-addition"></i>新建文集</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="layui-row" >
|
||||
<table class="layui-table" id="doctemp-list" lay-skin="nob" lay-size='' lay-even>
|
||||
<colgroup>
|
||||
<col width="90">
|
||||
<col width="100">
|
||||
<col width="40">
|
||||
<col width="60">
|
||||
<col width="90">
|
||||
<col width="30">
|
||||
<col width="50">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>文集名称</th>
|
||||
<th>文集简介</th>
|
||||
<th>文档数量</th>
|
||||
<th>权限</th>
|
||||
<th>创建时间</th>
|
||||
<th>所属用户</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for pro in projects %}
|
||||
<tr>
|
||||
<td><a href="{% url 'pro_index' pro_id=pro.id %}" target="_blank">{{ pro.name }}</a></td>
|
||||
<td>{{ pro.intro }}</td>
|
||||
{% load project_filter %}
|
||||
<td>{{ pro.id | get_doc_count }}</td>
|
||||
<td>
|
||||
<div class="layui-input-inline">
|
||||
{% if pro.role == 0 %}
|
||||
<i class="layui-icon layui-icon-circle"></i> 公开 <a href="{% url 'admin_project_role' pro.id %}" title="修改文集权限"><i class="layui-icon layui-icon-edit"></i></a>
|
||||
{% elif pro.role == 1 %}
|
||||
<i class="layui-icon layui-icon-menu-fill"></i> 私密 <a href="{% url 'admin_project_role' pro.id %}" title="修改文集权限"><i class="layui-icon layui-icon-edit"></i></a>
|
||||
{% elif pro.role == 2 %}
|
||||
<i class="layui-icon layui-icon-group"></i> 指定用户可见 <a href="{% url 'admin_project_role' pro.id %}" title="修改文集权限"><i class="layui-icon layui-icon-edit"></i></a>
|
||||
{% elif pro.role == 3 %}
|
||||
<i class="layui-icon layui-icon-password"></i> 访问码可见 <a href="{% url 'admin_project_role' pro.id %}" title="修改文集权限"><i class="layui-icon layui-icon-edit"></i></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
<td>{{ pro.create_time }}</td>
|
||||
<td>{{ pro.create_user }}</td>
|
||||
<td>
|
||||
<!-- <a href="{% url 'pro_index' pro_id=pro.id %}" target="_blank" class="layui-btn layui-btn-normal layui-btn-xs">
|
||||
<i class="layui-icon layui-icon-read"></i>查看
|
||||
</a> -->
|
||||
<a href="javascript:void(0);" onclick="modifyProject('{{pro.id}}','{{pro.name}}','{{pro.intro}}')" class="layui-btn layui-btn-normal layui-btn-xs">
|
||||
<i class="layui-icon layui-icon-edit"></i>
|
||||
</a>
|
||||
<a href="javascript:void(0);" onclick="delProject('{{pro.id}}');" class="layui-btn layui-btn-warm layui-btn-xs">
|
||||
<i class="layui-icon layui-icon-delete"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- 分页 -->
|
||||
<div class="layui-row">
|
||||
<div class="layui-box layui-laypage layui-laypage-default">
|
||||
<!-- 上一页 -->
|
||||
{% if projects.has_previous %}
|
||||
<a href="?page={{ projects.previous_page_number }}&kw={{projects.kw}}" class="layui-btn layui-btn-xs layui-btn-normal">上一页</a>
|
||||
{% else %}
|
||||
<a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-disabled">上一页</a>
|
||||
{% endif %}
|
||||
<!-- 当前页 -->
|
||||
<span class="layui-laypage-curr">
|
||||
<em class="layui-laypage-em"></em>
|
||||
<em>{{ projects.number }}/{{ projects.paginator.num_pages }}</em>
|
||||
</span>
|
||||
<!-- 下一页 -->
|
||||
{% if projects.has_next %}
|
||||
<a href="?page={{ projects.next_page_number }}&kw={{projects.kw}}" class="layui-btn layui-btn-xs layui-btn-normal">下一页</a>
|
||||
{% else %}
|
||||
<a class="layui-btn layui-btn-xs layui-btn-disabled">下一页</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<table id="project-table" lay-filter="project-table"></table>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
<!-- 表格工具栏 -->
|
||||
<script type="text/html" id="project-toolbar">
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="project-search-kw" placeholder="" class="layui-input" >
|
||||
</div>
|
||||
<button class="layui-btn layui-btn-primary pear-btn-sm" lay-event="search">
|
||||
<i class="layui-icon layui-icon-search"></i>搜索
|
||||
</button>
|
||||
<button class="layui-btn layui-btn-normal pear-btn-sm" lay-event="add">
|
||||
<i class="layui-icon layui-icon-add-1"></i>新增
|
||||
</button>
|
||||
<button class="layui-btn layui-btn-warm pear-btn-sm" lay-event="batchRemove">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
|
||||
</script>
|
||||
|
||||
<!-- 文集名称 -->
|
||||
<script type="text/html" id="project-name">
|
||||
{% verbatim %}
|
||||
<a href="/project-{{d.id}}/" target="_blank">
|
||||
{{d.name}}
|
||||
{{#if (d.role == 0) { }}
|
||||
{{# }else if(d.role == 1){ }}
|
||||
<span tooltip="私密" placement="right"><i class="layui-icon layui-icon-password"></i></span>
|
||||
{{# }else if(d.role == 2){ }}
|
||||
<span tooltip="指定用户" placement="right"><i class="layui-icon layui-icon-user"></i></span>
|
||||
{{# }else if(d.role == 3){ }}
|
||||
<span tooltip="访问码" placement="right"><i class="layui-icon layui-icon-key"></i></span>
|
||||
{{# } }}
|
||||
</a>
|
||||
{% endverbatim %}
|
||||
</script>
|
||||
|
||||
<!-- 单个文集操作 -->
|
||||
<script type="text/html" id="project-bar">
|
||||
{% verbatim %}
|
||||
<!-- <a href="/manage_pro_doc_sort/{{d.id}}/" class="layui-btn layui-btn-primary pear-btn-sm" lay-event="sort"><i class="layui-icon layui-icon-cols"></i></a> -->
|
||||
<!-- <a href="/modify_pro/?pro_id={{d.id}}" title="修改文集配置" class="layui-btn layui-btn-primary pear-btn-sm"><i class="layui-icon layui-icon-set"></i></a> -->
|
||||
<button class="layui-btn layui-btn-warm pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
|
||||
{% endverbatim %}
|
||||
</script>
|
||||
|
||||
<!-- 文集权限 -->
|
||||
<script type="text/html" id="project-role">
|
||||
{% verbatim %}
|
||||
{{#if (d.role == 0) { }}
|
||||
<span>公开</span>
|
||||
{{# }else if(d.role == 1){ }}
|
||||
<span>私密</span>
|
||||
{{# }else if(d.role == 2){ }}
|
||||
<span>指定用户</span>
|
||||
{{# }else if(d.role == 3){ }}
|
||||
<span>访问码</span>
|
||||
{{# } }}
|
||||
{% endverbatim %}
|
||||
</script>
|
||||
|
||||
<!-- 协作人数 -->
|
||||
<script type="text/html" id="colla-cnt">
|
||||
{% verbatim %}
|
||||
<span>{{d.colla_total}}</span> <a href="/manage_project_colla/{{d.id}}/" title="管理文集协作"><i class="layui-icon layui-icon-set"></i></a>
|
||||
{% endverbatim %}
|
||||
</script>
|
||||
|
||||
<!-- 创建时间 -->
|
||||
<script type="text/html" id="project-create-time">
|
||||
{% verbatim %}
|
||||
{{layui.util.toDateString(d.create_time, "yyyy-MM-dd HH:mm:ss")}}
|
||||
{% endverbatim %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% block custom_script %}
|
||||
<script>
|
||||
layui.use(['table','jquery','form','layer','element'], function() {
|
||||
layui.use(['table', 'form', 'jquery', 'layer'], function() {
|
||||
let table = layui.table;
|
||||
let form = layui.form;
|
||||
let $ = layui.jquery;
|
||||
let layer = layui.layer;
|
||||
let element = layui.element;
|
||||
$.ajaxSetup({
|
||||
data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
});
|
||||
let cols = [
|
||||
[
|
||||
{type: 'checkbox',width:20},
|
||||
{title: '文集名称',field: 'name',align: 'left',templet:"#project-name",minWidth:200},
|
||||
// {title: '简介',field: 'intro',align: 'left',templet:"#share-type"},
|
||||
// {title: '权限',field: 'role',align: 'left',templet:"#project-role"},
|
||||
{title: '文档数',field: 'doc_total',align: 'left',width:90},
|
||||
{title: '协作人数',field: 'colla_total',align: 'left',templet:"#colla-cnt",width:90},
|
||||
{title: '作者',field: 'create_user',align: 'left',width:90},
|
||||
{title: '创建时间',field: 'create_time',align: 'left',templet:"#project-create-time"},
|
||||
{title: '操作',toolbar: '#project-bar',align: 'left',}
|
||||
]
|
||||
]
|
||||
// 渲染表格
|
||||
table.render({
|
||||
elem: '#project-table',
|
||||
method:'post',
|
||||
where:{
|
||||
'type':1
|
||||
},
|
||||
url: "{% url 'project_manage' %}",
|
||||
page: true,
|
||||
cols: cols,
|
||||
skin: 'line',
|
||||
toolbar: '#project-toolbar',
|
||||
defaultToolbar: ['filter']
|
||||
});
|
||||
// 侦听文集删除按钮
|
||||
table.on("tool(project-table)",function(obj){
|
||||
if (obj.event === 'remove') {
|
||||
// console.log(obj)
|
||||
delProject(obj.data.id)
|
||||
}
|
||||
});
|
||||
// 侦听表格工具栏
|
||||
table.on("toolbar(project-table)",function(obj){
|
||||
if (obj.event === 'add') { // 新增文集
|
||||
createProject();
|
||||
}else if(obj.event === 'batchRemove'){ // 批量删除文集
|
||||
batchRemove(obj)
|
||||
}else if(obj.event === 'search'){ // 搜索文集
|
||||
console.log('搜索文集')
|
||||
table.reload('project-table',{
|
||||
where:{
|
||||
'type':1,'kw':$('input[name="project-search-kw"]').val()
|
||||
},
|
||||
})
|
||||
}
|
||||
});
|
||||
//创建文集
|
||||
createProject = function(){
|
||||
layer.open({
|
||||
type:1,
|
||||
@ -135,7 +157,7 @@
|
||||
'desc':$("#desc").val(),
|
||||
}
|
||||
$.post("{% url 'create_project' %}",data,function(r){
|
||||
layer.closeAll('loading');
|
||||
layer.closeAll('loading'); //关闭loading
|
||||
if(r.status){
|
||||
//创建成功
|
||||
window.location.reload();
|
||||
@ -149,6 +171,7 @@
|
||||
},
|
||||
});
|
||||
};
|
||||
//修改文集
|
||||
modifyProject = function(pro_id,pro_name,pro_intro){
|
||||
layer.open({
|
||||
type:1,
|
||||
@ -159,25 +182,28 @@
|
||||
btn:['确定','取消'], //添加按钮
|
||||
btnAlign:'c', //按钮居中
|
||||
yes:function (index,layero) {
|
||||
layer.load(1);
|
||||
data = {
|
||||
'pro_id':pro_id,
|
||||
'name':$("#pname").val(),
|
||||
'desc':$("#desc").val(),
|
||||
}
|
||||
$.post("{% url 'modify_project' %}",data,function(r){
|
||||
layer.closeAll('loading'); //关闭loading
|
||||
if(r.status){
|
||||
//修改成功
|
||||
window.location.reload();
|
||||
//layer.close(index)
|
||||
}else{
|
||||
//修改失败,提示
|
||||
console.log(r)
|
||||
// console.log(r)
|
||||
layer.msg(r.data)
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
};
|
||||
//删除文集
|
||||
delProject = function(pro_id){
|
||||
layer.open({
|
||||
type:1,
|
||||
@ -188,10 +214,12 @@
|
||||
btn:['确定','取消'], //添加按钮
|
||||
btnAlign:'c', //按钮居中
|
||||
yes:function (index,layero) {
|
||||
layer.load(1);
|
||||
data = {
|
||||
'pro_id':pro_id,
|
||||
}
|
||||
$.post("{% url 'del_project' %}",data,function(r){
|
||||
layer.closeAll('loading'); //关闭loading
|
||||
if(r.status){
|
||||
//修改成功
|
||||
window.location.reload();
|
||||
@ -205,6 +233,52 @@
|
||||
},
|
||||
});
|
||||
}
|
||||
// 批量删除文集
|
||||
batchRemove = function(obj) {
|
||||
let data = table.checkStatus(obj.config.id).data;
|
||||
if (data.length === 0) {
|
||||
layer.msg("未选中任何文集", {
|
||||
icon: 3,
|
||||
time: 1000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
let pro_id = "";
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
pro_id += data[i].id + ",";
|
||||
}
|
||||
pro_id = pro_id.substr(0, pro_id.length - 1);
|
||||
// console.log(pro_id)
|
||||
layer.confirm('确定要删除这些文集?', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function(index) {
|
||||
layer.close(index);
|
||||
let loading = layer.load();
|
||||
$.ajax({
|
||||
url: "{% url 'del_project' %}",
|
||||
dataType: 'json',
|
||||
type: 'post',
|
||||
data:{'pro_id':pro_id,'range':'multi'},
|
||||
success: function(r) {
|
||||
layer.close(loading);
|
||||
if (r.status) {
|
||||
layer.msg("删除成功", {
|
||||
icon: 1,
|
||||
time: 1000
|
||||
}, function() {
|
||||
table.reload('project-table');
|
||||
});
|
||||
} else {
|
||||
layer.msg(r.data, {
|
||||
icon: 2,
|
||||
time: 1000
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
@ -365,6 +365,7 @@
|
||||
// console.log("字符数:",this.getMarkdown().length)
|
||||
var wcnt = this.getMarkdown().length;
|
||||
$("#wordcount").text(wcnt);
|
||||
autoCacheDoc();
|
||||
},
|
||||
onload : function() {
|
||||
// this.insertValue(" ")
|
||||
|
@ -64,9 +64,9 @@
|
||||
|
||||
<!-- 表格工具栏 -->
|
||||
<script type="text/html" id="doc-toolbar">
|
||||
<button class="layui-btn layui-btn-normal pear-btn-sm" lay-event="add">
|
||||
<a class="layui-btn layui-btn-normal pear-btn-sm" href="/create_doc/" target="_blank">
|
||||
<i class="layui-icon layui-icon-add-1"></i>新增
|
||||
</button>
|
||||
</a>
|
||||
<button class="layui-btn layui-btn-warm pear-btn-sm" lay-event="batchRemove">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
|
Loading…
Reference in New Issue
Block a user