2019-12-15 15:45:05 +08:00
<!-- 继承自模板: app_doc/docs_base.html -->
{% extends 'app_doc/docs_base.html' %}
<!-- 引入静态文件 -->
2020-10-18 08:05:41 +08:00
{% load static %}
2020-12-02 21:25:59 +08:00
{% load i18n %}
2019-12-08 18:59:49 +08:00
2020-02-17 23:02:53 +08:00
{% block keyword %}{{ doc.name }},{{ project.name }},{% endblock %}
{% block description %}{{doc.pre_content | slice:"0:100"}}{% endblock %}
2019-12-15 15:45:05 +08:00
{% block title %}{{ doc.name }} - {{ project.name }}{% endblock %}
2019-12-08 18:59:49 +08:00
2019-12-15 15:45:05 +08:00
{% block head_toolbar %}
2020-08-07 21:36:37 +08:00
{% if request.user == doc.create_user or request.user == project.create_user %}
2020-04-03 21:05:27 +08:00
< span class = "btn pull-left" > |< / span >
2019-12-15 15:45:05 +08:00
< a class = "btn pull-left" aria-label = "" href = "{% url 'modify_doc' doc_id=doc.id %}" >
2020-12-06 01:33:59 +08:00
< i class = "fa fa-edit" > < / i > < span class = "layui-hide-xs" > {% trans "修改" %}< / span >
2019-12-15 15:45:05 +08:00
< / a >
2020-02-27 20:58:37 +08:00
< a class = "btn pull-left" aria-label = "" href = "{% url 'create_doc' %}?pid={{project.id}}" target = "_blank" >
2020-12-06 01:33:59 +08:00
< i class = "fa fa-plus-square" > < / i > < span class = "layui-hide-xs" > {% trans "添加" %}< / span >
2020-04-03 21:05:27 +08:00
< / a >
< a class = "btn pull-left" aria-label = "" href = "{% url 'manage_doc' %}" target = "_blank" >
2020-12-06 01:33:59 +08:00
< i class = "fa fa-cubes" > < / i > < span class = "layui-hide-xs" > {% trans "管理" %}< / span >
2020-04-03 21:05:27 +08:00
< / a >
{% elif colla_user > 0 %}
< span class = "btn pull-left" > |< / span >
{% if colla_user_role == 1 %}
< a class = "btn pull-left" aria-label = "" href = "{% url 'modify_doc' doc_id=doc.id %}" >
2020-12-06 01:33:59 +08:00
< i class = "fa fa-edit" > < / i > < span class = "layui-hide-xs" > {% trans "修改" %}< / span >
2020-04-03 21:05:27 +08:00
< / a >
{% endif %}
< a class = "btn pull-left" aria-label = "" href = "{% url 'create_doc' %}?pid={{project.id}}" target = "_blank" >
2020-12-06 01:33:59 +08:00
< i class = "fa fa-plus-square" > < / i > < span class = "layui-hide-xs" > {% trans "添加" %}< / span >
2019-12-15 15:45:05 +08:00
< / a >
2020-03-21 16:52:11 +08:00
{% endif %}
2020-03-21 16:11:21 +08:00
<!-- 文档目录 -->
2020-11-28 08:10:11 +08:00
< div id = "toc-container" class = 'sidebar doc-toc-hide' > < / div >
2020-08-30 13:51:26 +08:00
2019-12-15 15:45:05 +08:00
{% endblock %}
2019-12-08 18:59:49 +08:00
2019-12-15 15:45:05 +08:00
{% block content_head %}
< h1 > {{ doc.name }}< / h1 > < hr >
{% endblock %}
2019-12-08 18:59:49 +08:00
2019-12-15 15:45:05 +08:00
{% block page_content %}
2020-12-13 15:43:59 +08:00
{% if doc.editor_mode == 3 %}
{{ doc.pre_content | safe }}
{% else %}
2020-03-21 16:11:21 +08:00
< textarea style = "display: none;" > {{ doc.pre_content }}< / textarea >
2020-12-13 15:43:59 +08:00
{% endif %}
2020-12-15 20:48:47 +08:00
{% endblock %}
{% block children_content %}
{% if doc.show_children %}
{% load doc_filter %}
{% for children in doc.id|get_next_doc %}
< li style = "list-style: disc;font-size: 15px;" > < a href = "{% url 'doc' pro_id=pro_id doc_id=children.id %}" title = "{{children.name}}" > {{ children.name }}< / a > < / li >
{% endfor %}
{% endif %}
2020-01-15 21:03:44 +08:00
{% endblock %}
2020-07-31 20:23:23 +08:00
{% block doc_bottom_block %}
2020-08-30 13:51:26 +08:00
< div class = "layui-row" style = "margin-bottom: 10px;padding-left: 20px;" >
{% if doc_tags.count > 0 %}
< i class = "fa fa-tag" > < / i >
{% for tag in doc_tags %}
< a href = "{% url 'tag_docs' tag.tag.id %}" style = "font-size: 12px;line-height: 14px;height: 16px;padding: 0 5px;margin-left: 0;" > {{tag.tag.name}}< / a >
{% endfor %}
{% endif %}
< / div >
< div class = "layui-row layui-col-space20" style = "padding-left: 20px;" >
< span >
2020-10-18 08:05:41 +08:00
< i class = "fa fa-user" > < / i > {% if doc.create_user.first_name != '' %} {{doc.create_user.first_name}} {% else %} {{doc.create_user.username}}{% endif %}
2020-08-30 13:51:26 +08:00
< / span >
2020-12-06 01:33:59 +08:00
< span tooltip = "{% trans '更新于:' %}{{doc.modify_time}}" >
2020-08-30 13:51:26 +08:00
< i class = "fa fa-clock-o" > < / i > {{ doc.modify_time }}
< / span >
2020-12-06 01:33:59 +08:00
< button id = "share" class = "doc-bottom-btn" tooltip = "{% trans '分享本文档' %}" >
< i class = "fa fa-share-alt" > < / i > {% trans "分享" %}
2020-08-30 13:51:26 +08:00
< / button >
{% if request.user == doc.create_user or request.user.is_superuser %}
2020-12-06 01:33:59 +08:00
< button class = "doc-bottom-btn" tooltip = "{% trans '下载文档' %}" id = "download_doc" >
< i class = "fa fa-download" > < / i > {% trans "下载" %}
2020-08-30 13:51:26 +08:00
< / button >
{% endif %}
< / div >
2020-07-31 20:23:23 +08:00
{% endblock %}
2020-01-15 21:03:44 +08:00
{% block doc_previous_next %}
{% load doc_filter %}
2020-07-20 21:38:29 +08:00
< div class = "layui-row" style = "margin-top: 10px;padding:10px;display:flex;justify-content:space-around;" >
<!-- <hr> -->
2020-01-15 21:03:44 +08:00
< div >
{% if doc.id|get_doc_previous == None %}
2020-12-06 01:33:59 +08:00
< button class = "layui-btn layui-btn-disabled layui-btn-sm layui-btn-radius" > < i class = "layui-icon layui-icon-prev " > < / i > {% trans "上一篇" %}< / button >
2020-01-15 21:03:44 +08:00
{% else %}
2020-12-06 01:33:59 +08:00
< a href = "{% url 'doc' doc.top_doc doc.id|get_doc_previous %}" class = "layui-btn layui-btn-primary layui-btn-sm layui-btn-radius" > < i class = "layui-icon layui-icon-prev " > < / i > {% trans "上一篇" %}< / a >
2020-01-15 21:03:44 +08:00
{% endif %}
< / div >
< div >
{% if doc.id|get_doc_next == None %}
2020-12-06 01:33:59 +08:00
< button class = "layui-btn layui-btn-disabled layui-btn-sm layui-btn-radius" > {% trans "下一篇" %}< i class = "layui-icon layui-icon-next" > < / i > < / button >
2020-01-15 21:03:44 +08:00
{% else %}
2020-12-06 01:33:59 +08:00
< a href = "{% url 'doc' doc.top_doc doc.id|get_doc_next %}" class = "layui-btn layui-btn-primary layui-btn-sm layui-btn-radius" > {% trans "下一篇" %}< i class = "layui-icon layui-icon-next" > < / i > < / a >
2020-01-15 21:03:44 +08:00
{% endif %}
< / div >
< / div >
2020-03-21 16:11:21 +08:00
{% endblock %}
2020-08-07 21:36:37 +08:00
{% block right_widget %}
2020-11-21 21:27:53 +08:00
<!-- 修改文档 -->
{% if doc.create_user == request.user %}
2020-12-06 01:33:59 +08:00
< a class = "editDoc" href = "{% url 'modify_doc' doc_id=doc.id %}" title = "{% trans '修改文档' %}" > < i class = "fa fa-pencil" > < / i > < / a >
2020-11-21 21:27:53 +08:00
{% endif %}
2020-10-18 08:05:41 +08:00
<!-- 目录 -->
< div class = "tocMenu" style = "display: none;" > < i class = "fa fa-list" > < / i > < / div >
<!-- 分享按钮 -->
2020-11-16 21:32:08 +08:00
{% if project.role == 1 and request.user == doc.create_user %}
2020-11-21 21:27:53 +08:00
< div class = "shareDoc" id = "shareDoc" > < i class = "fa fa-share" > < / i > < / div >
2020-11-16 21:32:08 +08:00
{% endif %}
2020-08-07 21:36:37 +08:00
{% endblock %}
2020-03-21 16:11:21 +08:00
{% block custom_script %}
2020-07-31 20:23:23 +08:00
<!-- 下载选项卡模板 -->
< div id = "download_div" style = "display: none;" >
< div class = "layui-row" style = "margin: 10px;" >
< a class = "" download = '{{doc.name}}.md' href = "{% url 'download_doc_md' doc.id %}" target = "_blank" >
2020-12-06 01:33:59 +08:00
< i class = "fa fa-download" > < / i > {% trans "下载Markdown文件" %}
2020-07-31 20:23:23 +08:00
< / a >
< / div >
< / div >
2020-11-16 21:32:08 +08:00
<!-- 分享文档选项卡模板 -->
< div id = "share_doc_div" style = "display: none;" >
< div class = "layui-tab-content" >
< div class = "layui-form layui-form-pane" >
< div class = "layui-form-item" >
2020-12-06 01:33:59 +08:00
< label class = "layui-form-label" > {% trans "分享" %}< / label >
2020-11-16 21:32:08 +08:00
< div class = "layui-input-block" >
< input type = "checkbox" name = "switch"
2020-12-06 01:33:59 +08:00
lay-skin="switch" lay-text="{% trans '开启|关闭' %}" lay-filter="share-switch"
2020-11-16 21:32:08 +08:00
{% if is_share and doc_share.is_enable %}checked{%endif%}
>
< / div >
< / div >
< div class = "layui-form" style = "display: {% if is_share and doc_share.is_enable %}block;{% else %}none;{% endif %}" id = "share-link" >
< div class = "layui-form-item" >
2020-12-06 01:33:59 +08:00
< label class = "layui-form-label" > {% trans "链接" %}< / label >
2020-12-16 12:32:57 +08:00
< div class = "layui-input-block" id = 'copy_link' >
< input type = "text" name = "share_link" class = "layui-input" id = "share_link" readonly >
2020-11-16 21:32:08 +08:00
< / div >
< / div >
< / div >
< div class = "layui-form-item" style = "display:{% if is_share and doc_share.is_enable %}block;{% else %}none;{% endif %}" id = "share-type" >
2020-12-06 01:33:59 +08:00
< label class = "layui-form-label" > {% trans "类型" %}< / label >
2020-11-16 21:32:08 +08:00
< div class = "layui-input-block" >
{% if doc_share.share_type == 1 %}
2020-12-06 01:33:59 +08:00
< input type = "radio" name = "share_type" value = "0" title = "{% trans '公开' %}" lay-filter = "share_type" >
< input type = "radio" name = "share_type" value = "1" title = "{% trans '私密' %}" checked lay-filter = "share_type" >
2020-11-16 21:32:08 +08:00
{% else %}
2020-12-06 01:33:59 +08:00
< input type = "radio" name = "share_type" value = "0" title = "{% trans '公开' %}" checked lay-filter = "share_type" >
< input type = "radio" name = "share_type" value = "1" title = "{% trans '私密' %}" lay-filter = "share_type" >
2020-11-16 21:32:08 +08:00
{% endif %}
< / div >
< / div >
< div class = "layui-form" style = "display:{% if is_share and doc_share.is_enable and doc_share.share_type == 1 %}block;{% else %}none;{% endif %}" id = "share_value_item" >
< div class = "layui-form-item" >
2020-12-06 01:33:59 +08:00
< label class = "layui-form-label" > {% trans "密码" %}< / label >
2020-11-16 21:32:08 +08:00
< div class = "layui-input-inline" >
< input type = "text" name = "share_value" value = '{{doc_share.share_value}}' disabled class = "layui-input" id = "share_doc_value" >
< / div >
< div class = "layui-form-mid layui-word-aux" >
2020-12-06 01:33:59 +08:00
< button class = "layui-btn layui-btn-xs layui-btn-primary" id = "updateShareValue" > < i class = "fa fa-repeat" > < / i > {% trans "更新密码" %}< / button >
2020-11-16 21:32:08 +08:00
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
2020-08-07 21:36:37 +08:00
< script src = "{% static 'toc/doctoc.js' %}" > < / script >
2020-03-21 16:11:21 +08:00
< script >
2020-12-06 09:06:28 +08:00
// layui.use(['jquery','layer','form'],function(){
2020-03-21 16:11:21 +08:00
var layer = layui.layer;
2020-11-16 21:32:08 +08:00
var form = layui.form;
2020-12-06 09:06:28 +08:00
// var $ = layui.jquery;
2020-12-06 01:33:59 +08:00
// Ajax默认配置
$.ajaxSetup({
data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
});
2020-11-28 08:10:11 +08:00
// 非小屏默认展开文档目录
if(window.innerWidth > 1650){
2020-08-07 21:36:37 +08:00
$(".sidebar").toggleClass("doc-toc-hide");
2020-06-07 09:50:32 +08:00
}
2020-08-07 21:36:37 +08:00
// 切换文档目录显示与否
$(".tocMenu").click(function() {
2020-11-28 08:10:11 +08:00
console.log("切换文档目录显示")
2020-08-07 21:36:37 +08:00
$(".sidebar").toggleClass("doc-toc-hide");
});
2020-04-03 21:05:27 +08:00
//修改a标签链接新窗口打开
$('#content').on('click','a',function(e){
e.target.target = '_blank';
});
2020-07-31 20:23:23 +08:00
// 显示文档下载弹出框
$("#download_doc").click(function(r){
var layer = layui.layer;
layer.open({
type: 1,
title: false,
closeBtn: 0,
area: ['350px','150px'],
shadeClose: true,
content: $('#download_div')
});
});
2020-11-16 21:32:08 +08:00
// 生成随机分享码
function randomWord(randomFlag, min, max){
var str = "",
range = min,
arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
// 随机产生
if(randomFlag){
range = Math.round(Math.random() * (max-min)) + min;
}
for(var i=0; i< range ; i + + ) {
pos = Math.round(Math.random() * (arr.length-1));
str += arr[pos];
}
return str;
};
// 更新文档分享状态
function updateDocShare(data){
$.post("{% url 'share_doc' %}",data,function(r){
if(r.status){
2020-12-06 01:33:59 +08:00
layer.msg("{% trans '设置成功' %}",{offset: 't'})
2020-11-16 21:32:08 +08:00
console.log(r.data)
2020-12-16 12:32:57 +08:00
$("input[name=share_link]").val(document.location.protocol + '//' + document.location.host + '/share_doc/?token=' + r.data.doc)
2020-11-16 21:32:08 +08:00
}else{
2020-12-06 01:33:59 +08:00
layer.msg("{% trans '设置出错' %}")
2020-11-16 21:32:08 +08:00
}
})
}
2020-10-18 08:05:41 +08:00
// 分享文档
$("#shareDoc").click(function(){
layer.open({
type:1,
2020-12-06 01:33:59 +08:00
title:'{% trans "分享文档" %}:{{doc.name}}',
2020-11-16 21:32:08 +08:00
content:$("#share_doc_div"),
area:'450px',
success : function(index, layero) { // 成功弹出后回调
form.render();
},
2020-10-18 08:05:41 +08:00
})
})
2020-11-16 21:32:08 +08:00
{% if is_share %}
2020-12-16 12:32:57 +08:00
$("input[name=share_link]").val(window.location.protocol + '//' + document.location.host + '/share_doc/?token={{doc_share.token}}')
2020-11-16 21:32:08 +08:00
{% endif %}
var share_data = {
'id':'{{doc.id}}',
}
2020-12-16 12:32:57 +08:00
//监听链接栏被单击
$('#copy_link').click(function(){
var target = document.getElementById("share_link");
// 选择内容
target.focus();
target.setSelectionRange(0, target.value.length);
document.execCommand("copy");
layer.msg('链接地址已复制', {
time: 2000, //2s后自动关闭
btn: '好的',
btnAlign: 'c'
});
})
2020-11-16 21:32:08 +08:00
//监听分享框分享类型的单选事件
form.on('radio(share_type)', function(data){
// console.log(data.value); //被点击的radio的value值
if(data.value == 0){ // 公开
$("#share_value_item").css("display","none");
share_data['share_type'] = 0;
share_data['share_value'] = $("#share_doc_value").val();
share_data['is_enable'] = true
updateDocShare(share_data);
}else if(data.value == 1){ // 私密
$("#share_value_item").css("display","block");
{% if doc_share.share_value == '' or doc_share is None %}
$("#share_doc_value").val(randomWord(false,4))
{% endif %}
share_data['share_type'] = 1;
share_data['share_value'] = $("#share_doc_value").val();
share_data['is_enable'] = true
updateDocShare(share_data);
}
});
// 监听分享开关事件
form.on('switch(share-switch)', function(data){
console.log(data.elem.checked); //开关是否开启, true或者false
if(data.elem.checked){ // 开启
console.log("开启分享")
$("#share-type").css('display',"block");
$("#share-expire").css('display',"block");
$("#share-link").css("display","block");
if($("input[name='share_type']:checked").val() == 1){
$("#share_value_item").css("display","block");
}
// 开启
share_data['share_type'] = $("input[name='share_type']:checked").val();
share_data['share_value'] = $("#share_doc_value").val();
share_data['is_enable'] = true
updateDocShare(share_data);
}else{
console.log("关闭分享")
2020-12-06 01:33:59 +08:00
layer.msg("{% trans '关闭分享' %}",{offset: 't'})
2020-11-16 21:32:08 +08:00
$("#share-type").css('display',"none")
$("#share-expire").css('display',"none")
$("#share_value_item").css("display","none");
$("#share-link").css("display","none");
share_data['share_type'] = $("input[name='share_type']:checked").val();
share_data['share_value'] = $("#share_doc_value").val();
share_data['is_enable'] = false
updateDocShare(share_data);
}
});
// 更新文档分享密码
$("#updateShareValue").click(function(){
$("#share_doc_value").val(randomWord(false,4));
share_data['share_type'] = 1;
share_data['share_value'] = $("#share_doc_value").val();
share_data['is_enable'] = true
updateDocShare(share_data);
})
2020-12-06 09:06:28 +08:00
// })
2020-03-21 16:11:21 +08:00
< / script >
2019-12-15 15:45:05 +08:00
{% endblock %}