comment-list.vue
2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<template>
<div class="comment-context">
<p class="comment-title">共{{commentCount}}条评论</p>
<div class="comment-list">
<CommentItem
v-for="comment in commentList"
:key="comment.parentComment.id"
:class="'comment-' + comment.parentComment.id"
:parent-comment="comment.parentComment"
:children-comments="comment.childrenComments"
:column-type="columnType"
:pos-id="0"
:article-id="articleId"
@on-reply="onReply">
</CommentItem>
</div>
<div v-show="showMore" class="more-comment hover-opacity" @click="onFetch">
<p class="loading" v-if="onFetching">
<Loading :size="20"></Loading>
加载中
</p>
<span v-else>展开{{page > 2 ? '更多' : commentCount + '条'}}评论</span>
</div>
</div>
</template>
<script>
import {Loading} from 'cube-ui';
import {createNamespacedHelpers} from 'vuex';
const {mapActions} = createNamespacedHelpers('comment');
export default {
name: 'ArticleDetailCommentList',
props: {
commentCount: [Number, String],
articleId: [Number, String],
columnType: {
type: Number,
default: 1001
},
share: Boolean
},
data() {
return {
commentList: [],
page: 1,
onFetching: false,
showMore: false
}
},
mounted() {
this.init();
},
methods: {
...mapActions(['fetchCommentList', 'fetchReplayList', 'postComment']),
init() {
this.commentList.length = 0;
this.page = 1;
this.showMore = false;
this.onFetch();
},
async onFetch() {
if (this.onFetching || (this.page > 1 && !this.showMore)) {
return;
}
this.onFetching = true;
const result = await this.fetchCommentList({
destId: this.articleId,
columnType: this.columnType,
page: this.page,
limit: 10
});
setTimeout(() => {
if (result.code === 200) {
this.showMore = result.data.totalPage > this.page;
this.page++;
this.commentList = this.commentList.concat(result.data.commentInfos || []);
}
this.onFetching = false;
}, 800);
},
onReply() {
}
},
components: {
Loading
}
};
</script>
<style :lang="scss" scoped>
.comment-title {
font-size: 28px;
margin: 0 30px;
color: #9b9b9b;
line-height: 80px;
border-top: 1px solid #f0f0f0;
}
.comment-list {
padding: 20px 30px;
}
.more-comment {
height: 100px;
line-height: 1;
font-size: 28px;
color: #4a90e2;
border-top: 1px solid #f0f0f0;
display: flex;
align-items: center;
justify-content: center;
.loading {
display: flex;
align-items: center;
justify-content: center;
color: #999;
}
}
</style>