动机
抖音的评论只有按照点赞数降序,没有按照回复数降序。
页面
点击“点赞”,点赞数+1.点击“回复”,回复数+1.
排序方式提供了两种:点赞数降序和回复数降序。
页面代码
<% layout('/layouts/default.html', {title: '评论管理', libs: ['dataGrid']}){ %>
<div class="main-content">
<div class="box box-main">
<div class="box-header">
<div class="box-title">
<i class="fa icon-notebook"></i> ${text('评论管理')}
</div>
<div class="box-tools pull-right">
<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
<% if(hasPermi('comments:comments:edit')){ %>
<a href="${ctx}/comments/comments/form" class="btn btn-default btnTool" title="${text('新增评论')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
<% } %>
<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
</div>
</div>
<div class="box-body">
<#form:form id="searchForm" model="${comments}" action="${ctx}/comments/comments/listData" method="post" class="form-inline hide"
data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
<div class="form-group">
<label class="control-label">${text('评论')}:</label>
<div class="control-inline">
<#form:input path="commentText" maxlength="450" class="form-control width-120"/>
</div>
</div>
<div class="form-group">
<label class="control-label">${text('创建时间')}:</label>
<div class="control-inline">
<#form:input path="createTime" readonly="true" maxlength="20" class="form-control laydate width-datetime"
dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
</div>
</div>
<div class="form-group">
<label class="control-label">${text('点赞数')}:</label>
<div class="control-inline">
<#form:input path="goodNum" class="form-control width-120"/>
</div>
</div>
<div class="form-group">
<label class="control-label">${text('排序方式')}:</label>
<div class="control-inline">
<#form:select path="orderBy" dictType="commentOrder" class="form-control required " />
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-search"></i> ${text('查询')}</button>
<button type="reset" class="btn btn-default btn-sm isQuick"><i class="glyphicon glyphicon-repeat"></i> ${text('重置')}</button>
</div>
</#form:form>
<table id="dataGrid"></table>
<div id="dataGridPage"></div>
</div>
</div>
</div>
<% } %>
<script>
//# // 初始化DataGrid对象
$('#dataGrid').dataGrid({
searchForm: $('#searchForm'),
columnModel: [
{header:'${text("评论")}', name:'commentText', index:'a.comment_text', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
return '<a href="${ctx}/comments/comments/form?commentId='+row.commentId+'" class="btnList" data-title="${text("编辑评论")}">'+(val||row.id)+'</a>';
}},
{header:'${text("创建时间")}', name:'createTime', index:'a.create_time', width:150, align:"center"},
{header:'${text("点赞数")}', name:'goodNum', index:'a.good_num', width:150, align:"center"},
{header:'${text("回复数")}', name:'replyNum', index:'a.reply_num', width:150, align:"center"},
{header:'${text("操作")}', name:'actions', width:120, formatter: function(val, obj, row, act){
var actions = [];
//# if(hasPermi('comments:comments:edit')){
actions.push('<a href="${ctx}/comments/comments/form?commentId='+row.commentId+'" class="btnList" title="${text("编辑评论")}"><i class="fa fa-pencil"></i></a> ');
actions.push('<a href="${ctx}/comments/comments/delete?commentId='+row.commentId+'" class="btnList" title="${text("点赞")}" >点赞</a> ');
actions.push('<a href="${ctx}/comments/comments/reply?commentId='+row.commentId+'" class="btnList" title="${text("回复")}" >回复</a> ');
//# }
return actions.join('');
}}
],
//# // 加载成功后执行事件
ajaxSuccess: function(data){
}
});
</script>
新增字典CommentOrder
页面中用到了字典CommentOrder
后端代码
/**
* 点赞
*/
@RequiresPermissions("comments:comments:edit")
@RequestMapping(value = "delete")
@ResponseBody
public String delete(Comments comments) {
//commentsService.delete(comments);
Comments oldComment = commentsService.get(comments.getId());
oldComment.setGoodNum(oldComment.getGoodNum()+1);
commentsService.save(oldComment);
return renderResult(Global.TRUE, text("点赞评论成功!"));
}
/**
* 回复
*/
@RequiresPermissions("comments:comments:edit")
@RequestMapping(value = "reply")
@ResponseBody
public String reply(Comments comments) {
Comments oldComment = commentsService.get(comments.getId());
oldComment.setReplyNum(oldComment.getReplyNum()+1);
commentsService.save(oldComment);
return renderResult(Global.TRUE, text("回复评论成功!"));
}