优化编辑器切换相关代码

This commit is contained in:
yangjian 2020-12-16 22:05:36 +08:00
parent 91c80aaff1
commit 10b428ddf6
3 changed files with 20 additions and 29 deletions

View File

@ -890,14 +890,11 @@ def create_doc(request):
except ObjectDoesNotExist:
editor_mode = 1
if request.method == 'GET':
try:
# 获取url中自定义编辑器模式
eid = request.GET.get('eid',0)
if eid in [1,2,3,'1','2','3']:
editor_mode = int(eid)
except Exception as e:
# 异常直接跳过使用设置中的mode
pass
# 获取url切换的编辑器模式
eid = request.GET.get('eid',editor_mode)
if eid in [1,2,3,'1','2','3']:
editor_mode = int(eid)
try:
editor_type = "新建文档"
pid = request.GET.get('pid',-999)
@ -917,7 +914,7 @@ def create_doc(request):
doc_content = request.POST.get('content','') # 文档内容
pre_content = request.POST.get('pre_content','') # 文档Markdown内容
sort = request.POST.get('sort','') # 文档排序
editor_mode = request.POST.get('editor_mode','') #获取文档编辑器
editor_mode = request.POST.get('editor_mode',editor_mode) #获取文档编辑器
status = request.POST.get('status',1) # 文档状态
open_children = request.POST.get('open_children', False) # 展示下级目录
show_children = request.POST.get('show_children', False) # 展示下级目录
@ -981,17 +978,11 @@ def create_doc(request):
@require_http_methods(['GET',"POST"])
def modify_doc(request,doc_id):
editor_type = "修改文档"
# 获取用户的编辑器模式
# try:
# user_opt = UserOptions.objects.get(user=request.user)
# editor_mode = user_opt.editor_mode
# except ObjectDoesNotExist:
# editor_mode = 1
if request.method == 'GET':
try:
doc = Doc.objects.get(id=doc_id) # 查询文档信息
editor_mode = doc.editor_mode
eid = request.GET.get('eid',0)
editor_mode = doc.editor_mode # 设置文档编辑器为文档上一次使用的编辑模式
eid = request.GET.get('eid',editor_mode)
if eid in [1,2,3,'1','2','3']:
editor_mode = int(eid)
doc_tags = ','.join([i.tag.name for i in DocTag.objects.filter(doc=doc)]) # 查询文档标签信息
@ -1029,7 +1020,7 @@ def modify_doc(request,doc_id):
doc_content = request.POST.get('content', '') # 文档内容
pre_content = request.POST.get('pre_content', '') # 文档Markdown格式内容
sort = request.POST.get('sort', '') # 文档排序
editor_mode = request.POST.get('editor_mode','') #获取文档编辑器
editor_mode = request.POST.get('editor_mode',1) #获取文档编辑器
status = request.POST.get('status',1) # 文档状态
open_children = request.POST.get('open_children',False) # 展示下级目录
show_children = request.POST.get('show_children', False) # 展示下级目录

View File

@ -32,7 +32,7 @@
</button>
</div>
<div class="layui-form-item">
<label class="layui-form-label" style="padding-left: 0px;">编辑器选择</label>
<label class="layui-form-label" style="padding-left: 0px;">编辑器切换</label>
<div class="layui-input-block">
<select name="select_editor_mode" lay-verify="required" lay-filter="select_editor_mode">
<option value="1">EditorMD(Markdown)</option>
@ -194,25 +194,25 @@
{% block custom_script %}
<script>
form.val("left_form",{
"select_editor_mode":{{editor_mode}}
"select_editor_mode":'{{editor_mode}}'
})
form.on('select(select_editor_mode)',function(data){
//console.log(data.value)
layer.open({
type:0,
title:'换编辑器',
title:'换编辑器',
area:'300px;',
id:'change_editor',//配置ID
content: "为保证更换后格式兼容,更换编辑器将导致内容丢失!",
btn:['确定更换','取消返回'], //添加按钮
content: "为确保格式兼容,切换编辑器将导致未保存内容丢失!",
btn:['确定切换','取消'], //添加按钮
btnAlign:'c', //按钮居中
yes:function (index,layero) {
eurl = "{% url 'create_doc' %}?pid={{pid}}&eid=" + data.value.toString();
$(location).attr('href', eurl);
},
btn2: function(index, layero){
//暂时不需要返回
}
//暂时不需要返回
}
});
})
var tree = layui.tree;

View File

@ -52,7 +52,7 @@
</button>
</div>
<div class="layui-form-item">
<label class="layui-form-label" style="padding-left: 0px;">编辑器选择</label>
<label class="layui-form-label" style="padding-left: 0px;">编辑器切换</label>
<div class="layui-input-block">
<select name="select_editor_mode" lay-verify="required" lay-filter="select_editor_mode">
<option value="1">EditorMD(Markdown)</option>
@ -217,17 +217,17 @@
{% block custom_script %}
<script>
form.val("left_form",{
"select_editor_mode":{{editor_mode}}
"select_editor_mode": '{{editor_mode}}'
})
form.on('select(select_editor_mode)',function(data){
//console.log(data.value)
layer.open({
type:0,
title:'换编辑器',
title:'换编辑器',
area:'300px;',
id:'change_editor',//配置ID
content: "页面将重载,未提交的修改将丢失!",
btn:['确定换','取消返回'], //添加按钮
btn:['确定换','取消返回'], //添加按钮
btnAlign:'c', //按钮居中
yes:function (index,layero) {
eurl = "{% url 'modify_doc' doc_id=doc.id %}"+"?eid=" + data.value.toString();