Skip to content

Commit 84b947d

Browse files
authored
fix: #976 评论增加头像 (#977)
* fix: #976 评论增加头像 * fix: update cherry markdown read comment user to avatar style
1 parent acf3c46 commit 84b947d

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

models/CommentModel.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/mindoc-org/mindoc/conf"
99
)
1010

11-
//Comment struct
11+
// Comment struct
1212
type Comment struct {
1313
CommentId int `orm:"pk;auto;unique;column(comment_id)" json:"comment_id"`
1414
Floor int `orm:"column(floor);type(unsigned);default(0)" json:"floor"`
@@ -30,11 +30,12 @@ type Comment struct {
3030
// UserAgent 评论者浏览器内容
3131
UserAgent string `orm:"column(user_agent);size(500)" json:"user_agent"`
3232
// Parent 评论所属父级
33-
ParentId int `orm:"column(parent_id);type(int);default(0)" json:"parent_id"`
34-
AgreeCount int `orm:"column(agree_count);type(int);default(0)" json:"agree_count"`
35-
AgainstCount int `orm:"column(against_count);type(int);default(0)" json:"against_count"`
36-
Index int `orm:"-" json:"index"`
37-
ShowDel int `orm:"-" json:"show_del"`
33+
ParentId int `orm:"column(parent_id);type(int);default(0)" json:"parent_id"`
34+
AgreeCount int `orm:"column(agree_count);type(int);default(0)" json:"agree_count"`
35+
AgainstCount int `orm:"column(against_count);type(int);default(0)" json:"against_count"`
36+
Index int `orm:"-" json:"index"`
37+
ShowDel int `orm:"-" json:"show_del"`
38+
Avatar string `orm:"-" json:"avatar"`
3839
}
3940

4041
// TableName 获取对应数据库表名.
@@ -90,6 +91,7 @@ func (m *Comment) QueryCommentByDocumentId(doc_id, page, pagesize int, member *M
9091
comments[i].Index = (i + 1) + (page-1)*pagesize
9192
if member != nil && comments[i].CanDelete(member.MemberId, bookRole) {
9293
comments[i].ShowDel = 1
94+
comments[i].Avatar = member.Avatar
9395
}
9496
}
9597
return
@@ -103,7 +105,7 @@ func (m *Comment) Update(cols ...string) error {
103105
return err
104106
}
105107

106-
//Insert 添加一条评论.
108+
// Insert 添加一条评论.
107109
func (m *Comment) Insert() error {
108110
if m.DocumentId <= 0 {
109111
return errors.New("评论文档不存在")

static/css/kancloud.css

+7
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,13 @@ table>tbody>tr:hover {
798798
line-height: 24px
799799
}
800800

801+
.m-comment .comment-item .info img {
802+
height: 22px;
803+
border-radius: 50%;
804+
margin-right: 4px;
805+
display: ruby;
806+
}
807+
801808
.m-comment .comment-item .vote {
802809
display: inline-block;
803810
margin-right: 12px

static/js/kancloud.js

+28-16
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,39 @@ function pageClicked($page, $docid) {
7777
});
7878
}
7979

80+
function renderOperateSection(comment) {
81+
const deleteIcon = comment.show_del == 1
82+
? `<i class="delete e-delete glyphicon glyphicon-remove" onclick="onDelComment(${comment.comment_id})"></i>`
83+
: '';
84+
85+
return `
86+
<span class="operate ${comment.show_del == 1 ? 'toggle' : ''}">
87+
<span class="number">${comment.index}#</span>
88+
${deleteIcon}
89+
</span>`;
90+
}
91+
8092
// 加载评论
8193
function loadComment($page, $docid) {
8294
$("#commentList").empty();
83-
var html = ""
84-
var c = $page.List;
85-
for (var i = 0; c && i < c.length; i++) {
86-
html += "<div class=\"comment-item\" data-id=\"" + c[i].comment_id + "\">";
87-
html += "<p class=\"info\"><a class=\"name\">" + c[i].author + "</a><span class=\"date\">" + timeFormat(c[i].comment_date) + "</span></p>";
88-
html += "<div class=\"content\">" + c[i].content + "</div>";
89-
html += "<p class=\"util\">";
90-
if (c[i].show_del == 1) html += "<span class=\"operate toggle\">";
91-
else html += "<span class=\"operate\">";
92-
html += "<span class=\"number\">" + c[i].index + "#</span>";
93-
if (c[i].show_del == 1) html += "<i class=\"delete e-delete glyphicon glyphicon-remove\" style=\"color:red\" onclick=\"onDelComment(" + c[i].comment_id + ")\"></i>";
94-
html += "</span>";
95-
html += "</p>";
96-
html += "</div>";
95+
let html = ""
96+
let c = $page.List;
97+
for (let i = 0; c && i < c.length; i++) {
98+
const comment = c[i];
99+
html += `
100+
<div class="comment-item" data-id="${comment.comment_id}">
101+
<p class="info">
102+
<img src="${comment.avatar}" alt="">
103+
<a class="name">${comment.author}</a>
104+
<span class="date">${timeFormat(comment.comment_date)}</span>
105+
</p>
106+
<div class="content">${comment.content}</div>
107+
<p class="util">
108+
${renderOperateSection(comment)}
109+
</p>
110+
</div>`;
97111
}
98112
$("#commentList").append(html);
99-
100113
if ($page.TotalPage > 1) {
101114
$("#page").bootstrapPaginator({
102115
currentPage: $page.PageNo,
@@ -114,7 +127,6 @@ function loadComment($page, $docid) {
114127

115128
// 删除评论
116129
function onDelComment($id) {
117-
console.log($id);
118130
$.ajax({
119131
url: "/comment/delete",
120132
data: { "id": $id },

views/document/default_read.tpl

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
window.IS_DOCUMENT_INDEX = '{{if .IS_DOCUMENT_INDEX}}true{{end}}' === 'true';
3636
window.IS_DISPLAY_COMMENT = '{{if .Model.IsDisplayComment}}true{{end}}' === 'true';
3737
</script>
38-
<script type="text/javascript">window.book={"identify":"{{.Model.Identify}}"};</script>
38+
<script type="text/javascript">window.book={"identify": '{{.Model.Identify}}'};</script>
3939
<style>
4040
.btn-mobile {
4141
position: absolute;
@@ -53,13 +53,13 @@
5353
}
5454
}
5555
56-
.svg {
56+
.svg {
5757
display: inline-block;
5858
position: relative;
5959
width: 100%;
6060
height: 100%;
61-
vertical-align: middle;
62-
overflow: auto;
61+
vertical-align: middle;
62+
overflow: auto;
6363
}
6464
</style>
6565
</head>

0 commit comments

Comments
 (0)