mirror of https://github.com/halo-dev/halo
👽 更改显示评论的逻辑,即评论之后需审核通过之后才能显示,并提升了用户体验。
parent
72df84c26a
commit
1b065a4214
|
@ -50,7 +50,7 @@ public interface CommentRepository extends JpaRepository<Comment,Long> {
|
|||
* @param status status
|
||||
* @return page
|
||||
*/
|
||||
Page<Comment> findCommentsByPostAndCommentStatusNot(Post post,Pageable pageable,Integer status);
|
||||
Page<Comment> findCommentsByPostAndCommentStatus(Post post,Pageable pageable,Integer status);
|
||||
|
||||
/**
|
||||
* 查询最新的前五条评论
|
||||
|
|
|
@ -124,7 +124,7 @@ public class CommentServiceImpl implements CommentService {
|
|||
*/
|
||||
@Override
|
||||
public Page<Comment> findCommentsByPostAndCommentStatus(Post post, Pageable pageable, Integer status) {
|
||||
return commentRepository.findCommentsByPostAndCommentStatusNot(post, pageable, status);
|
||||
return commentRepository.findCommentsByPostAndCommentStatus(post, pageable, status);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,6 +11,7 @@ import cc.ryanc.halo.utils.HaloUtils;
|
|||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.omg.PortableServer.POA;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
@ -23,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.websocket.server.PathParam;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
@ -192,6 +194,35 @@ public class PostController extends BaseController{
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自动保存文章为草稿
|
||||
* @param post post
|
||||
* @param session session
|
||||
* @return 文章的编号
|
||||
*/
|
||||
@PostMapping(value = "/new/autoPush")
|
||||
@ResponseBody
|
||||
public Post autoPushPost(@ModelAttribute Post post, HttpSession session){
|
||||
User user = (User)session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
try{
|
||||
if(StringUtils.isEmpty(post.getPostTitle())){
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
post.setPostTitle("草稿:"+dateFormat.format(new Date()));
|
||||
}
|
||||
if(StringUtils.isEmpty(post.getPostUrl())){
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
post.setPostTitle(dateFormat.format(new Date()));
|
||||
}
|
||||
post.setPostDate(new Date());
|
||||
post.setPostUpdate(new Date());
|
||||
post.setUser(user);
|
||||
}catch (Exception e){
|
||||
log.error("未知错误:", e.getMessage());
|
||||
}
|
||||
return postService.saveByPost(post);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理移至回收站的请求
|
||||
*
|
||||
|
|
|
@ -118,7 +118,7 @@ public class FrontArchiveController extends BaseController {
|
|||
}
|
||||
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
|
||||
Pageable pageable = PageRequest.of(0,999,sort);
|
||||
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,2);
|
||||
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,0);
|
||||
model.addAttribute("post", post);
|
||||
model.addAttribute("comments",comments);
|
||||
post.setPostViews(post.getPostViews()+1);
|
||||
|
|
|
@ -342,13 +342,50 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
//setInterval("autoPush()","5000");
|
||||
/**
|
||||
* 自动保存文章
|
||||
*/
|
||||
function autoPush() {
|
||||
var Title = "";
|
||||
if(postTitle.val()){
|
||||
Title = postTitle.val();
|
||||
}
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/admin/posts/new/autoPush',
|
||||
async: false,
|
||||
data: {
|
||||
<#--<#if post??>-->
|
||||
<#--'postId': $('#postId').val(),-->
|
||||
<#--</#if>-->
|
||||
'postStatus': 1,
|
||||
'postTitle': Title,
|
||||
'postUrl' : $('#postUrl').html().toString(),
|
||||
'postContentMd': editor.getMarkdown(),
|
||||
'postContent': editor.getHTML(),
|
||||
'postThumbnail': $('#selectImg')[0].src
|
||||
},
|
||||
success: function (data) {
|
||||
if(!$("#post_title").val()){
|
||||
$("#post_title").val(data.postTitle);
|
||||
}
|
||||
if(!$("#postId").val()){
|
||||
$("#postId").val(data.postId);
|
||||
}
|
||||
if($("#postUrl").html()==null || $("#postUrl").html()==""){
|
||||
$("#postUrl").val(data.postUrl);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ctrl+C保存
|
||||
*/
|
||||
$(document).keydown(function (event) {
|
||||
if(event.ctrlKey&&event.keyCode === 83){
|
||||
push(1);
|
||||
//autoPush();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
outline: none;
|
||||
}
|
||||
|
||||
.comment-submit,.native-list-one-img,.native-list-one-footer-time,.native-list-one-footer-reback,.native-info,.native-nav,.ua{
|
||||
.comment-submit,.native-list-one-img,.native-list-one-footer-time,.native-list-one-footer-reback,.native-info,.native-nav,.ua,.native-message{
|
||||
-webkit-user-select:none;
|
||||
-moz-user-select:none;
|
||||
-ms-user-select:none;
|
||||
|
@ -209,31 +209,34 @@
|
|||
<button type="button" class="comment-submit" id="btn-push">提交</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="native-message" style="text-align: center;padding: 20px;display: none"></div>
|
||||
<div class="native-info">
|
||||
<span id="native-info-total" style="font-weight: 600">${comments.getTotalElements()}</span>评论
|
||||
</div>
|
||||
<ul class="native-list">
|
||||
<#list comments.content as comment>
|
||||
<li class="native-list-one" id="comment-id-${comment.commentId?c}">
|
||||
<img class="native-list-one-img" src="//www.gravatar.com/avatar/${comment.commentAuthorAvatarMd5?if_exists}?s=256&d=${options.native_comment_avatar?default('mm')}">
|
||||
<section>
|
||||
<div class="native-list-one-head">
|
||||
<a class="native-list-one-head-name" rel="nofollow" href="${comment.commentAuthorUrl?if_exists}">${comment.commentAuthor?if_exists}</a>
|
||||
<span class="native-comment-ua-info" style="display: none">${comment.commentAgent?if_exists}</span>
|
||||
<#if comment.isAdmin==1>
|
||||
<label class="native-list-one-head-admin">博主</label>
|
||||
</#if>
|
||||
</div>
|
||||
<div class="native-list-one-content">
|
||||
<p>${comment.commentContent?if_exists}</p>
|
||||
</div>
|
||||
<div class="native-list-one-footer">
|
||||
<span class="native-list-one-footer-time">${comment.commentDate?string("yyyy-MM-dd HH:mm")}</span>
|
||||
<span at="${comment.commentId?c}" class="native-list-one-footer-reback">回复</span>
|
||||
</div>
|
||||
</section>
|
||||
</li>
|
||||
</#list>
|
||||
<#if comments.content?? && comments.content?size gt 0>
|
||||
<#list comments.content as comment>
|
||||
<li class="native-list-one" id="comment-id-${comment.commentId?c}">
|
||||
<img class="native-list-one-img" src="//www.gravatar.com/avatar/${comment.commentAuthorAvatarMd5?if_exists}?s=256&d=${options.native_comment_avatar?default('mm')}">
|
||||
<section>
|
||||
<div class="native-list-one-head">
|
||||
<a class="native-list-one-head-name" rel="nofollow" href="${comment.commentAuthorUrl?if_exists}">${comment.commentAuthor?if_exists}</a>
|
||||
<span class="native-comment-ua-info" style="display: none">${comment.commentAgent?if_exists}</span>
|
||||
<#if comment.isAdmin==1>
|
||||
<label class="native-list-one-head-admin">博主</label>
|
||||
</#if>
|
||||
</div>
|
||||
<div class="native-list-one-content">
|
||||
<p>${comment.commentContent?if_exists}</p>
|
||||
</div>
|
||||
<div class="native-list-one-footer">
|
||||
<span class="native-list-one-footer-time">${comment.commentDate?string("yyyy-MM-dd HH:mm")}</span>
|
||||
<span at="${comment.commentId?c}" class="native-list-one-footer-reback">回复</span>
|
||||
</div>
|
||||
</section>
|
||||
</li>
|
||||
</#list>
|
||||
</#if>
|
||||
</ul>
|
||||
<#--<div class="native-nav">-->
|
||||
<#--<ol class="page-nav">-->
|
||||
|
@ -257,6 +260,11 @@
|
|||
var author = $("#commentAuthor");
|
||||
var content = $("#commentContent");
|
||||
if (author.val() == '' || content.val() == '') {
|
||||
$(".native-message").html("<span style='color:red'>请输入必填项!</span>");
|
||||
$(".native-message").fadeIn(1000);
|
||||
setTimeout(function () {
|
||||
$(".native-message").fadeOut(1000);
|
||||
},1500);
|
||||
return;
|
||||
}
|
||||
$(this).attr("disabled","disabled");
|
||||
|
@ -277,7 +285,11 @@
|
|||
},
|
||||
success: function (data) {
|
||||
if (data == true) {
|
||||
window.location.reload();
|
||||
$(".native-message").html("<span>你的评论已经提交,待博主审核之后可显示。</span>");
|
||||
$(".native-message").fadeIn(1000);
|
||||
setTimeout(function () {
|
||||
window.location.reload();
|
||||
},1500);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -88,15 +88,19 @@
|
|||
</style>
|
||||
|
||||
<ul class="md-links">
|
||||
<#list links?if_exists as link>
|
||||
<li class="md-links-item">
|
||||
<a href="${link.linkUrl}" title="${link.linkName}" target="_blank">
|
||||
<img src="${link.linkPic}" alt="${link.linkName}" height="72px"/>
|
||||
<span class="md-links-title">${link.linkName}</span><br/>
|
||||
<span>${link.linkDesc?if_exists}</span>
|
||||
</a>
|
||||
</li>
|
||||
</#list>
|
||||
<@commonTag method="links">
|
||||
<#if links?? && links?size gt 0>
|
||||
<#list links?if_exists as link>
|
||||
<li class="md-links-item">
|
||||
<a href="${link.linkUrl}" title="${link.linkName}" target="_blank">
|
||||
<img src="${link.linkPic}" alt="${link.linkName}" height="72px"/>
|
||||
<span class="md-links-title">${link.linkName}</span><br/>
|
||||
<span>${link.linkDesc?if_exists}</span>
|
||||
</a>
|
||||
</li>
|
||||
</#list>
|
||||
</#if>
|
||||
</@commonTag>
|
||||
</ul>
|
||||
|
||||
<script type="text/ls-javascript" id="page-links-script">
|
||||
|
|
Loading…
Reference in New Issue