码农笔录博客源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.4 KiB

преди 6 години
{{template "header" .}}
преди 6 години
<meta name="keywords" content="{{.Blog.Title}}">
преди 6 години
<title>{{.Blog.Title}} - 码农随笔</title>
преди 6 години
<link type="text/css" rel="styleSheet" href="/static/css/newblog.css"/>
преди 6 години
<script src="/static/js/wangEditor.min.js"></script>
преди 6 години
</head>
<body>
<div class="root-container">
<div class="blog-title">
<input type="text" id="blog-title" placeholder="请输入文章标题" value="{{.Blog.Title}}">
преди 6 години
<button type="button" id="newBtn" class="layui-btn layui-btn-radius layui-btn-danger layui-btn-sm " style="border-radius: 12px">
发布文章
</button>
преди 6 години
</div>
<div id="editor" class="editor">
</div>
</div>
</body>
<script>
var tobj = {}
var storage = window.localStorage
var E = window.wangEditor
var editor = new E('#editor')
преди 6 години
editor.customConfig.uploadImgServer = '/file/upload'
преди 6 години
// 或者 var editor = new E( document.getElementById('editor') )
преди 6 години
editor.customConfig.uploadImgHooks = {
customInsert: function (insertImg, result, editor) {
insertImg(result.Data);
}
}
преди 6 години
editor.create()
document.onkeydown = keyDown;
function keyDown(e) {
var currKey = 0, e = e || event || window.event;
currKey = e.keyCode || e.which || e.charCode;
if (currKey == 83 && (e.ctrlKey || e.metaKey)) {
saveBlog()
return
}
}
function saveBlog() {
var title = $("#blog-title").val();
if (title.trim().length < 3) {
layer.msg('文章标题最少三个字', function () {
});
return
}
tobj.title = $("#blog-title").val();
преди 6 години
if (editor.txt.html().trim().length == 0) {
преди 6 години
layer.msg('文章内容不能为空哦', function () {
});
return
}
tobj.blogHtml = editor.txt.html();
storage.setItem("blogHtml", tobj.blogHtml);
storage.setItem("blogTitle", tobj.title);
layer.open({
type: 2,
title: '发布文章',
shadeClose: true,
shade: 0.8,
area: ['420px', '280px'],
content: '/iframe/blog.html?id={{.Blog.Id}}' //iframe的url
});
}
$(function () {
editor.txt.html({{.Blog.BlogHtml}});
tobj.id = {{.Blog.Id}};
tobj.catory = {{.Blog.CategoryId}};
tobj.labels = []
console.log({{.Blog.Lables}})
{{range .Blog.Lables}}
tobj.labels.push({{.Title}})
{{end}}
var height = document.documentElement.clientHeight
$(".w-e-text-container").height(height - 50 - 40 - 1);
$("#newBtn").click(function () {
saveBlog()
})
})
function saveBlogCallback(callback) {
преди 6 години
$.post('/api/blog/edit', tobj,
преди 6 години
function (data) {
if (data.Status == 0) {
storage.removeItem("blogHtml");
storage.removeItem("blogTitle");
layer.msg("保存成功", {icon: 6});
callback(true)
window.location.href = "/blog/{{.Blog.Id}}"
} else if (data.Status == 401) {
window.location.href = "login"
} else if (data.Status == 500) {
layer.msg("保存失败", {icon: 6});
callback(false)
}
}, 'json')
}
</script>
</html>