Skip to content

Commit e732a8b

Browse files
committed
支持回复评论
1 parent b3f45a7 commit e732a8b

File tree

6 files changed

+47
-19
lines changed

6 files changed

+47
-19
lines changed

controllers/BookController.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,12 +1235,14 @@ func (this *BookController) Comment() {
12351235
this.JsonResult(1, "请先登录在评论")
12361236
}
12371237
content := this.GetString("content")
1238-
if l := len(content); l < 5 || l > 256 {
1239-
this.JsonResult(1, "评论内容限 5 - 256 个字符")
1238+
if l := len(content); l < 5 || l > 255 {
1239+
this.JsonResult(1, "评论内容限 5 - 255 个字符")
12401240
}
12411241
bookId, _ := this.GetInt(":id")
1242+
pid, _ := this.GetInt("pid")
1243+
docId, _ := this.GetInt("doc_id")
12421244
if bookId > 0 {
1243-
if err := new(models.Comments).AddComments(this.Member.MemberId, bookId, content); err != nil {
1245+
if err := new(models.Comments).AddComments(this.Member.MemberId, bookId, pid, docId, content); err != nil {
12441246
this.JsonResult(1, err.Error())
12451247
}
12461248
this.JsonResult(0, "评论成功")

controllers/api/LoginedController.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,18 @@ func (this *LoginedController) ChangeAvatar() {
149149

150150
func (this *LoginedController) PostComment() {
151151
content := this.GetString("content")
152-
if l := len(content); l < 5 || l > 256 {
153-
this.Response(http.StatusBadRequest, "点评内容限定 5 - 256 个字符")
152+
pid, _ := this.GetInt("pid")
153+
docId, _ := this.GetInt("doc_id")
154+
if l := len(content); l < 5 || l > 255 {
155+
this.Response(http.StatusBadRequest, "点评内容限定 5 - 255 个字符")
154156
}
155157
bookId := this.getBookIdByIdentify(this.GetString("identify"))
156158

157159
if bookId <= 0 {
158160
this.Response(http.StatusBadRequest, messageBadRequest)
159161
}
160162

161-
err := new(models.Comments).AddComments(this.isLogin(), bookId, content)
163+
err := new(models.Comments).AddComments(this.isLogin(), bookId, pid, docId, content)
162164
if err != nil {
163165
this.Response(http.StatusBadRequest, err.Error())
164166
}

models/comments.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import (
1616
//评论表
1717
type Comments struct {
1818
Id int
19-
Uid int `orm:"index"` //用户id
20-
BookId int `orm:"index"` //书籍id
21-
Content string //评论内容
22-
TimeCreate time.Time //评论时间
19+
Pid int `orm:"index;default(0)"` // 上一个评论的ID
20+
Uid int `orm:"index"` // 用户id
21+
BookId int `orm:"index"` // 书籍id
22+
DocId int `orm:"index;default(0)"` // 文档ID
23+
Content string // 评论内容
24+
TimeCreate time.Time // 评论时间
2325
Status int8 // 审核状态; 0,待审核,1 通过,-1 不通过
2426
}
2527

@@ -35,7 +37,7 @@ type Score struct {
3537
// 多字段唯一键
3638
func (this *Score) TableUnique() [][]string {
3739
return [][]string{
38-
[]string{"Uid", "BookId"},
40+
{"Uid", "BookId"},
3941
}
4042
}
4143

@@ -221,7 +223,7 @@ func (this *Score) AddScore(uid, bookId, score int) (err error) {
221223
}
222224

223225
//添加评论
224-
func (this *Comments) AddComments(uid, bookId int, content string) (err error) {
226+
func (this *Comments) AddComments(uid, bookId, pid, docId int, content string) (err error) {
225227
var comment Comments
226228

227229
//查询该用户现有的评论
@@ -238,6 +240,8 @@ func (this *Comments) AddComments(uid, bookId int, content string) (err error) {
238240
BookId: bookId,
239241
Content: content,
240242
TimeCreate: now,
243+
DocId: docId,
244+
Pid: pid,
241245
}
242246

243247
if _, err = o.Insert(&comments); err != nil {

static/css/main.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,17 +697,21 @@ a{color: #333}
697697
#bookstack-intro .comments-form .fa{font-size: 18px;}
698698
#bookstack-intro .comments-form .fa-star{color: #ff6600}
699699
#bookstack-intro .comments-form .cursor-pointer{cursor: pointer;}
700-
#bookstack-intro .comments-list li{padding: 30px 0px;border-bottom: 1px solid #EFEFEF;}
700+
#bookstack-intro .comments-list li{padding: 15px 0px 5px;border-bottom: 1px solid #EFEFEF;}
701701
#bookstack-intro .comments-list li>.col-xs-12{padding: 0px;}
702702
#bookstack-intro .comments-list .username{color: #333333;}
703703
#bookstack-intro .comments-list span{color: #b6b6b6;margin-left: 5px;}
704704
#bookstack-intro .comments-list img{display: inline-block;height: 50px;width: 50px;}
705-
#bookstack-intro .comments-list .comments-content{font-size: 13px;color: #999999;text-indent: 2em;line-height: 170%;margin-top:10px;}
705+
#bookstack-intro .comments-list .comments-content{
706+
font-size: 13px;color: #666;text-indent: 2em;line-height: 170%;margin-top:10px;margin-bottom: 15px;
707+
}
706708
#bookstack-intro .comments-left{padding-left: 0px;}
707709
#bookstack-intro .comments-right{padding: 0px;}
708710
#bookstack-intro .comments-right .userinfo{font-size: 16px;position: relative;top:-7px;}
709711
#bookstack-intro .comments-right .userinfo span{font-size: 14px;color: #999999;}
710712
#bookstack-intro .comments-content{color: #999999;}
713+
#bookstack-intro .repley:hover{cursor: pointer;}
714+
#bookstack-intro .comments-list form{margin-left: 2em;padding-top: 15px;}
711715

712716

713717
.friend-links a{margin-right: 8px;}

static/js/main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ $(function () {
216216
});
217217

218218
//ajax-form
219-
$(".ajax-form [type=submit]").click(function(e){
219+
$("body").on("click", ".ajax-form [type=submit]", function(e){
220220
e.preventDefault();
221221
var _this=$(this),form=$(this).parents("form"),method=form.attr("method"),action=form.attr("action"),data=form.serialize(),_url=form.attr("data-url");
222222
var require=form.find("[required=required]"),l=require.length;
@@ -370,5 +370,13 @@ $(function () {
370370
})
371371
})
372372

373+
$("#bookstack-intro .repley").click(function(){
374+
var _this = $(this),pid = _this.attr("data-pid"),ele = _this.parent().parent();
375+
if (ele.find("form").length==0){
376+
$(".comments-list").find("form").remove();
377+
ele.find(".comments-content").after($(".comment-form")[0].outerHTML)
378+
ele.find("[name=pid]").val(pid)
379+
}
380+
})
373381

374382
});

views/document/intro.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ <h1>{{.Book.BookName}}
153153
{{end}}
154154

155155
</div>
156-
<form action="{{urlfor "BookController.Comment" ":id" $.Book.BookId}}" method="post" class="ajax-form">
156+
<form action="{{urlfor "BookController.Comment" ":id" $.Book.BookId}}" method="post" class="ajax-form comment-form">
157+
<input type="hidden" name="pid" value="0">
157158
<div class="form-group">
158-
<textarea class="form-control" name="content" rows="5" placeholder="在这里,您可以给当前小编提意见和建议,以及对文档内容进行纠偏纠错提醒。"></textarea>
159+
<textarea class="form-control" name="content" rows="5" placeholder="文明评论,理性发言"></textarea>
159160
</div>
160161
<div class="form-group">
161-
<span class="pull-left text-muted">文明评论,理性发言</span>
162162
<input type="submit" class="btn btn-success pull-right" value="发表点评">
163163
</div>
164164
</form>
@@ -171,9 +171,17 @@ <h1>{{.Book.BookName}}
171171
<img src="{{showImg .Avatar "avatar"}}" class="img-thumbnail img-circle img-responsive" alt="{{.Nickname}}">
172172
<span class="username">{{.Nickname}}</span>
173173
<span>评分:<i class="bookstack-star star-{{.Score}}"></i></span>
174-
<span class="text-muted hidden-xs pull-right">{{date .TimeCreate "Y-m-d H:i:s"}}</span>
175174
</div>
176175
<div class="col-xs-12 comments-content">{{.Content}}</div>
176+
<div class="mgt-15px">
177+
<span class="text-muted">
178+
<i class="fa fa-clock-o"></i>
179+
{{date .TimeCreate "Y-m-d H:i:s"}}
180+
</span>
181+
<span class="repley" data-pid="{{.Id}}">
182+
<i class="fa fa-comments-o"></i> 回复
183+
</span>
184+
</div>
177185
</li>
178186
{{end}}
179187

0 commit comments

Comments
 (0)