forked from mirror/MrDoc
添加文档模板创建页面
This commit is contained in:
parent
955001c706
commit
12e1acf682
2
.gitignore
vendored
2
.gitignore
vendored
@ -113,3 +113,5 @@ dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
.idea/
|
@ -99,7 +99,7 @@ def create_doc(request):
|
||||
if request.method == 'GET':
|
||||
# doc_list = Doc.objects.filter(create_user=request.user)
|
||||
project_list = Project.objects.filter(create_user=request.user)
|
||||
doctemp_list = DocTemp.objects.filter(create_user=request.user)
|
||||
doctemp_list = DocTemp.objects.filter(create_user=request.user).values('id','name','create_time')
|
||||
return render(request,'app_doc/create_doc.html',locals())
|
||||
elif request.method == 'POST':
|
||||
project = request.POST.get('project','')
|
||||
@ -169,9 +169,9 @@ def create_doctemp(request):
|
||||
if request.method == 'GET':
|
||||
return render(request,'app_doc/create_doctemp.html',locals())
|
||||
elif request.method == 'POST':
|
||||
name = request.POST.get('name',None)
|
||||
name = request.POST.get('name','')
|
||||
content = request.POST.get('content','')
|
||||
if name:
|
||||
if name != '':
|
||||
doctemp = DocTemp.objects.create(
|
||||
name = name,
|
||||
content = content,
|
||||
|
@ -9,12 +9,12 @@
|
||||
<link href="{% static 'style.css' %}" rel="stylesheet">
|
||||
</head>
|
||||
<body class="layui-layout-body">
|
||||
<div class="layui-row">
|
||||
<ul class="layui-nav layui-bg-blue">
|
||||
<li class="layui-nav-item"><a href="">MrDoc</a></li>
|
||||
<li class="layui-nav-item"><a href="/">回到首页</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<!--<div class="layui-row">-->
|
||||
<!--<ul class="layui-nav layui-bg-blue">-->
|
||||
<!--<li class="layui-nav-item"><a href="">MrDoc</a></li>-->
|
||||
<!--<li class="layui-nav-item"><a href="/">回到首页</a></li>-->
|
||||
<!--</ul>-->
|
||||
<!--</div>-->
|
||||
<div class="layui-main">
|
||||
<div class="create-doc-form">
|
||||
{# 文档标题#}
|
||||
@ -187,6 +187,16 @@
|
||||
area:['530px','300px'],
|
||||
});
|
||||
});
|
||||
//插入模板
|
||||
insertTemp = function(doctemp_id){
|
||||
//$.post("get_doctemp",data.function(r){
|
||||
// if(r.status){
|
||||
// editor.insertValue(r.data)
|
||||
// }else{
|
||||
// }
|
||||
//});
|
||||
//layer.close()
|
||||
};
|
||||
</script>
|
||||
{% endblock %}
|
||||
</body>
|
||||
@ -213,9 +223,9 @@
|
||||
<td>{{ temp.name }}</td>
|
||||
<td>{{ temp.create_time }}</td>
|
||||
<td>
|
||||
<a href="">插入</a>
|
||||
<a href="">修改</a>
|
||||
<a href="">删除</a>
|
||||
<a href="javascript:void(0);" onclick="insertTemp('{{temp.id}}');">插入</a>
|
||||
<a href="javascript:void(0);" onclick="modifyTemp();">修改</a>
|
||||
<a href="javascript:void(0);" onclick="delTemp();">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -1,10 +1,112 @@
|
||||
{% load staticfiles %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="zh-cn">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<title>新建文档模板 - MrDoc</title>
|
||||
<link href="{% static 'layui/css/layui.css' %}" rel="stylesheet">
|
||||
<link rel="stylesheet" href="{% static 'editor.md/css/editormd.css' %}" />
|
||||
<link href="{% static 'style.css' %}" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<body class="layui-layout-body">
|
||||
<!--<div class="layui-row">-->
|
||||
<!--<ul class="layui-nav layui-bg-blue">-->
|
||||
<!--<li class="layui-nav-item"><a href="">MrDoc</a></li>-->
|
||||
<!--<li class="layui-nav-item"><a href="/">回到首页</a></li>-->
|
||||
<!--</ul>-->
|
||||
<!--</div>-->
|
||||
<div class="layui-main">
|
||||
<div class="create-doc-form">
|
||||
<div class="layui-form">
|
||||
<label class="layui-form-label">模板标题:</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="doc-name" id="doctemp-name" required lay-verify="required" placeholder="请输入模板名称" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
<label class="doc-form-label">
|
||||
<button class="layui-btn layui-btn-normal" onclick="createDocTemp()">保存</button>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div id="editor-md">
|
||||
<textarea style="display:none;"></textarea>
|
||||
<textarea class="editormd-html-textarea" name="$id-html-code"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
|
||||
<script src="{% static 'layui/layui.all.js' %}"></script>
|
||||
<script src="{% static 'editor.md/editormd.min.js' %}"></script>
|
||||
{% block custom_script %}
|
||||
<script>
|
||||
layui.config({
|
||||
base: "/static/layui/module/"
|
||||
}).extend({
|
||||
treeSelect: "treeSelect/treeSelect"
|
||||
});
|
||||
$.ajaxSetup({
|
||||
data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
});
|
||||
//初始化editormd
|
||||
var editor = editormd("editor-md", {
|
||||
width : "100%",
|
||||
height : "1000px;",
|
||||
placeholder:"开始使用Markdown书写……",
|
||||
path : "/static/editor.md/lib/",
|
||||
saveHTMLToTextarea : true,
|
||||
tex:true,//开启科学公式
|
||||
tocm:true,//开启下拉目录
|
||||
taskList:true,//开启任务列表
|
||||
tocTitle:'文章导读',
|
||||
tocContainer:'',
|
||||
tocDropdown:false,
|
||||
emoji:true,
|
||||
|
||||
});
|
||||
//粘贴上传图片
|
||||
$("#editor-md").on('paste', function (ev) {
|
||||
var data = ev.clipboardData;
|
||||
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
|
||||
for (var index in items) {
|
||||
var item = items[index];
|
||||
if (item.kind === 'file') {
|
||||
var blob = item.getAsFile();
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (event) {
|
||||
var base64 = event.target.result;
|
||||
//ajax上传图片
|
||||
$.post("{% url 'upload_doc_img' %}",{base:base64}, function (ret) {
|
||||
layer.msg(ret.message);
|
||||
if (ret.success === 1) {
|
||||
//新一行的图片显示
|
||||
editor.insertValue("\n![](" + ret.url + ")");
|
||||
}
|
||||
});
|
||||
}; // data url!
|
||||
var url = reader.readAsDataURL(blob);
|
||||
}
|
||||
}
|
||||
});
|
||||
var layer = layui.layer;
|
||||
var form = layui.form;
|
||||
//保存文档模板
|
||||
createDocTemp = function(){
|
||||
var data = {
|
||||
'name':$("#doctemp-name").val(),
|
||||
'content':editor.getMarkdown(),
|
||||
}
|
||||
$.post("{% url 'create_doctemp' %}",data,function(r){
|
||||
if(r.status){
|
||||
//创建成功
|
||||
layer.msg('保存成功',function(){
|
||||
window.location.href = "{% url 'pro_list' %}";
|
||||
});
|
||||
}else{
|
||||
//创建失败
|
||||
layer.msg('保存失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user