MrDoc/template/app_doc/doc.html

358 lines
15 KiB
HTML
Raw Normal View History

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 %}
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-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 %}
<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 %}">
<i class="layui-icon layui-icon-edit"></i> <span class="layui-hide-xs">{% trans "修改" %}</span>
2019-12-15 15:45:05 +08:00
</a>
<a class="btn pull-left" aria-label="" href="{% url 'create_doc' %}?pid={{project.id}}" target="_blank">
<i class="layui-icon layui-icon-add-1"></i> <span class="layui-hide-xs">{% trans "添加" %}</span>
</a>
<a class="btn pull-left" aria-label="" href="{% url 'manage_doc' %}" target="_blank">
<i class="fa fa-cubes"></i> <span class="layui-hide-xs">{% trans "管理" %}</span>
</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 %}">
<i class="layui-icon layui-icon-edit"></i> <span class="layui-hide-xs">{% trans "修改" %}</span>
</a>
{% endif %}
<a class="btn pull-left" aria-label="" href="{% url 'create_doc' %}?pid={{project.id}}" target="_blank">
<i class="layui-icon layui-icon-add-1"></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 %}
<!-- 文档目录 -->
<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-15 15:45:05 +08:00
{% block content_head %}
<h1>{{ doc.name }}</h1><hr>
{% endblock %}
2019-12-15 15:45:05 +08:00
{% block page_content %}
{% if doc.editor_mode == 3 %}
{{ doc.content | safe }}
{% else %}
<textarea style="display: none;">{{ doc.pre_content }}</textarea>
{% endif %}
{% 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 class="doc-bottom-icon">
<i class="layui-icon layui-icon-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>
<span tooltip="{% trans '更新于:' %}{{doc.modify_time}}" class="doc-bottom-icon">
<i class="layui-icon layui-icon-log"></i> {{ doc.modify_time }}
2020-08-30 13:51:26 +08:00
</span>
<button id="share" class="doc-bottom-btn" tooltip="{% trans '分享本文档' %}">
<i class="layui-icon layui-icon-share" ></i> {% trans "分享文档" %}
2020-08-30 13:51:26 +08:00
</button>
<span class="doc-bottom-icon">
{% if request.user.is_authenticated %}
{% if is_collect_doc %}
<i class="layui-icon layui-icon-star-fill collected" id="collect_doc"></i> {% trans "收藏文档" %}
{% else %}
<i class="layui-icon layui-icon-star" id="collect_doc"></i> {% trans "收藏文档" %}
{% endif %}
{% else %}
<i class="layui-icon layui-icon-star" title="请登录后收藏"></i> {% trans "收藏文档" %}
{% endif %}
</span>
2020-08-30 13:51:26 +08:00
{% if request.user == doc.create_user or request.user.is_superuser %}
<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 %}
<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 %}
<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 %}
<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 %}
<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>
{% endblock %}
2020-08-07 21:36:37 +08:00
{% block right_widget %}
<!-- 修改文档 -->
{% if doc.create_user == request.user %}
<a class="editDoc" href="{% url 'modify_doc' doc_id=doc.id %}" title="{% trans '修改文档' %}"><i class="fa fa-pencil"></i></a>
{% 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 %}
<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 %}
{% 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">
<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">
<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"
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">
<label class="layui-form-label">{% trans "链接" %}</label>
<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">
<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 %}
<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 %}
<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">
<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">
<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>
<script>
var layer = layui.layer;
2020-11-16 21:32:08 +08:00
var form = layui.form;
// Ajax默认配置
$.ajaxSetup({
data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
});
// 非小屏默认展开文档目录
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() {
console.log("切换文档目录显示")
2020-08-07 21:36:37 +08:00
$(".sidebar").toggleClass("doc-toc-hide");
});
//修改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){
layer.msg("{% trans '设置成功' %}",{offset: 't'})
2020-11-16 21:32:08 +08:00
console.log(r.data)
$("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{
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,
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 %}
$("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}}',
}
//监听链接栏被单击
$('#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("关闭分享")
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);
})
</script>
2019-12-15 15:45:05 +08:00
{% endblock %}