码农笔录博客源码
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

101 rinda
3.4 KiB

pirms 6 gadiem
{{template "header" .}}
pirms 6 gadiem
<meta name="keywords" content="码农随笔,个人随笔,博客,个人博客,个人笔记,技术博客,免费云笔记,云笔记,随笔,IT博客,谷歌地图,码农笔录,www.aiprose.com,aiprose.com,aiprose">
<title>发布博客 - 码农随笔</title>
pirms 6 gadiem
<script src="/static/js/wangEditor.min.js"></script>
pirms 6 gadiem
</head>
<body>
<div class="root-container">
<div class="blog-title">
pirms 6 gadiem
<input type="text" id="blog-title" placeholder="请输入文章标题">
pirms 6 gadiem
<button type="button" id="newBtn" class="layui-btn layui-btn-radius layui-btn-danger layui-btn-sm " style="border-radius: 12px">
发布文章
</button>
pirms 6 gadiem
</div>
<div id="editor" class="editor">
</div>
</div>
</body>
<script>
var storage=window.localStorage
pirms 6 gadiem
var E = window.wangEditor
var editor = new E('#editor')
pirms 6 gadiem
editor.customConfig.uploadImgServer = '/file/upload'
pirms 6 gadiem
// 或者 var editor = new E( document.getElementById('editor') )
pirms 6 gadiem
editor.customConfig.uploadImgHooks = {
customInsert: function (insertImg, result, editor) {
insertImg(result.Data);
pirms 6 gadiem
}
}
pirms 6 gadiem
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();
pirms 6 gadiem
if (editor.txt.html().trim().length == 0) {
layer.msg('文章内容不能为空哦', function () {
});
return
}
tobj.blogHtml = editor.txt.html();
pirms 6 gadiem
tobj.blogDesc = editor.txt.text().substring(0,200)
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/' //iframe的url
});
}
pirms 6 gadiem
var tobj = {}
$(function () {
var oldVal = storage.getItem("blogHtml");
editor.txt.html(oldVal);
var oldTitle = storage.getItem("blogTitle");
$("#blog-title").val(oldTitle);
pirms 6 gadiem
var height = document.documentElement.clientHeight
$(".w-e-text-container").height(height - 50 - 40 - 1);
$("#newBtn").click(function () {
saveBlog()
pirms 6 gadiem
})
})
function saveBlogCallback(callback) {
pirms 6 gadiem
$.post('/api/blog/new', tobj,
pirms 6 gadiem
function (data) {
if (data.Status == 0) {
storage.removeItem("blogHtml");
storage.removeItem("blogTitle");
layer.msg("保存成功", {icon: 6});
callback(true)
pirms 6 gadiem
window.location.href = "/blog/"+ data.Data
} else if (data.Status == 401) {
window.location.href = "login"
} else if (data.Status == 500) {
layer.msg("保存失败", {icon: 6});
callback(false)
}
}, 'json')
pirms 6 gadiem
}
</script>
</html>