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
|
* @param status status
|
||||||
* @return page
|
* @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
|
@Override
|
||||||
public Page<Comment> findCommentsByPostAndCommentStatus(Post post, Pageable pageable, Integer status) {
|
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 cc.ryanc.halo.web.controller.core.BaseController;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.omg.PortableServer.POA;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
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.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import javax.websocket.server.PathParam;
|
import javax.websocket.server.PathParam;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
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");
|
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
|
||||||
Pageable pageable = PageRequest.of(0,999,sort);
|
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("post", post);
|
||||||
model.addAttribute("comments",comments);
|
model.addAttribute("comments",comments);
|
||||||
post.setPostViews(post.getPostViews()+1);
|
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保存
|
* Ctrl+C保存
|
||||||
*/
|
*/
|
||||||
$(document).keydown(function (event) {
|
$(document).keydown(function (event) {
|
||||||
if(event.ctrlKey&&event.keyCode === 83){
|
if(event.ctrlKey&&event.keyCode === 83){
|
||||||
push(1);
|
//autoPush();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
outline: none;
|
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;
|
-webkit-user-select:none;
|
||||||
-moz-user-select:none;
|
-moz-user-select:none;
|
||||||
-ms-user-select:none;
|
-ms-user-select:none;
|
||||||
|
@ -209,10 +209,12 @@
|
||||||
<button type="button" class="comment-submit" id="btn-push">提交</button>
|
<button type="button" class="comment-submit" id="btn-push">提交</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="native-message" style="text-align: center;padding: 20px;display: none"></div>
|
||||||
<div class="native-info">
|
<div class="native-info">
|
||||||
<span id="native-info-total" style="font-weight: 600">${comments.getTotalElements()}</span>评论
|
<span id="native-info-total" style="font-weight: 600">${comments.getTotalElements()}</span>评论
|
||||||
</div>
|
</div>
|
||||||
<ul class="native-list">
|
<ul class="native-list">
|
||||||
|
<#if comments.content?? && comments.content?size gt 0>
|
||||||
<#list comments.content as comment>
|
<#list comments.content as comment>
|
||||||
<li class="native-list-one" id="comment-id-${comment.commentId?c}">
|
<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')}">
|
<img class="native-list-one-img" src="//www.gravatar.com/avatar/${comment.commentAuthorAvatarMd5?if_exists}?s=256&d=${options.native_comment_avatar?default('mm')}">
|
||||||
|
@ -234,6 +236,7 @@
|
||||||
</section>
|
</section>
|
||||||
</li>
|
</li>
|
||||||
</#list>
|
</#list>
|
||||||
|
</#if>
|
||||||
</ul>
|
</ul>
|
||||||
<#--<div class="native-nav">-->
|
<#--<div class="native-nav">-->
|
||||||
<#--<ol class="page-nav">-->
|
<#--<ol class="page-nav">-->
|
||||||
|
@ -257,6 +260,11 @@
|
||||||
var author = $("#commentAuthor");
|
var author = $("#commentAuthor");
|
||||||
var content = $("#commentContent");
|
var content = $("#commentContent");
|
||||||
if (author.val() == '' || content.val() == '') {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
$(this).attr("disabled","disabled");
|
$(this).attr("disabled","disabled");
|
||||||
|
@ -277,7 +285,11 @@
|
||||||
},
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data == true) {
|
if (data == true) {
|
||||||
|
$(".native-message").html("<span>你的评论已经提交,待博主审核之后可显示。</span>");
|
||||||
|
$(".native-message").fadeIn(1000);
|
||||||
|
setTimeout(function () {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
},1500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -88,6 +88,8 @@
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<ul class="md-links">
|
<ul class="md-links">
|
||||||
|
<@commonTag method="links">
|
||||||
|
<#if links?? && links?size gt 0>
|
||||||
<#list links?if_exists as link>
|
<#list links?if_exists as link>
|
||||||
<li class="md-links-item">
|
<li class="md-links-item">
|
||||||
<a href="${link.linkUrl}" title="${link.linkName}" target="_blank">
|
<a href="${link.linkUrl}" title="${link.linkName}" target="_blank">
|
||||||
|
@ -97,6 +99,8 @@
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</#list>
|
</#list>
|
||||||
|
</#if>
|
||||||
|
</@commonTag>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<script type="text/ls-javascript" id="page-links-script">
|
<script type="text/ls-javascript" id="page-links-script">
|
||||||
|
|
Loading…
Reference in New Issue