liteblog/views/comment.html

76 lines
2.4 KiB
HTML
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>评论-闲言轻博客</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
{{template "shares/link.html".}}
</head>
<body class="lay-blog">
{{template "shares/header.html".}}
<div class="container-wrap">
<div class="container container-message container-details container-comment">
<div class="contar-wrap">
<div class="item">
{{ template "shares/note_summary_tpl.html" .note}}
</div>
<form class="layui-form" action="">
<input type="hidden" name="key" value="{{ .note.Key }}">
<div class="layui-form-item layui-form-text">
<textarea class="layui-textarea" name="content" style="resize:none" placeholder="写点什么啊"></textarea>
</div>
<div class="btnbox">
<button lay-submit="" class="layui-btn" lay-filter="comment" >
确定
</button>
</div>
</form>
</div>
</div>
</div>
{{template "shares/footer.html".}}
<script id="LAY-msg-tpl" type="text/html">
<div class="info-box">
<div class="info-item">
<img class="info-img" src="{{ .Avatar }}" alt="">
<div class="info-text">
<p class="title">
<span class="name">{{ .Username }}</span>
<span class="info-img">
<i class="layui-icon layui-icon-praise"></i>
{{ .Praise }}
</span>
</p>
<p class="info-intr">
{{ .Content }}
</p>
</div>
</div>
</div>
</script>
<script>
layui.use(['form',"jquery","layer"],function () {
var form = layui.form,$= layui.jquery,layer = layui.layer;
// 监听评论的form表单提交事件。
form.on("submit(comment)",function (formData) {
//我们假定评论新增路由的路径为 "/message/new/:key" key是文章的key
$.post("/comment/new/"+formData.field.key,{content:formData.field.content},function (data) {
if(data.code === 0){
layer.msg("评论成功!");
//评论成功就 跳转到文章详情页面
setTimeout(function () {
window.location.href = "/details/"+formData.field.key;
},300)
}else{
layer.msg(data.msg);
}
},"json").error(function () {
layer.msg("网络异常")
});
// 此处一定要return false阻止浏览器默认事件如果没有这段代码form表单提交会直接刷新页面走浏览器默认事件。
return false;
})
})
</script>
</body>
</html>