|
|
<template>
|
|
|
<div class="comment-list">
|
|
|
<div class="comment-content">
|
|
|
<Scroll ref="scroll" :data="commentList" :options="scrollOption" @pulling-up="onPullingUp">
|
|
|
<CommentItem
|
|
|
v-for="(comment, index) in commentList"
|
|
|
:key="index"
|
|
|
:parent-comment="comment.parentComment"
|
|
|
:children-comments="comment.childrenComments"
|
|
|
:column-type="columnType"
|
|
|
@on-reply="onReply">
|
|
|
</CommentItem>
|
|
|
</Scroll>
|
|
|
<LayoutRecycleList v-if="show" ref="comment" :offset="500" :on-fetch="onFetch">
|
|
|
<template class="article-item" v-slot:item="{ data }">
|
|
|
<CommentItem
|
|
|
:parent-comment="data.parentComment"
|
|
|
:children-comments="data.childrenComments"
|
|
|
:column-type="columnType"
|
|
|
@on-reply="onReply">
|
|
|
</CommentItem>
|
|
|
</template>
|
|
|
</LayoutRecycleList>
|
|
|
</div>
|
|
|
<div class="comment-footer">
|
|
|
<div class="comment-input" @click="onComment">参与评论</div>
|
...
|
...
|
@@ -37,49 +37,36 @@ export default { |
|
|
data() {
|
|
|
return {
|
|
|
page: 1,
|
|
|
commentList: [],
|
|
|
scrollOption: {
|
|
|
pullUpLoad: {
|
|
|
threshold: 200,
|
|
|
txt: {
|
|
|
more: '上拉加载',
|
|
|
noMore: '- 已经到底了 -'
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
show: false
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
|
this.fetchComments();
|
|
|
setTimeout(() => {
|
|
|
this.show = true;
|
|
|
}, 200);
|
|
|
},
|
|
|
methods: {
|
|
|
...mapActions(['fetchCommentList', 'fetchReplayList', 'postComment']),
|
|
|
async fetchComments(refresh) {
|
|
|
async onFetch() {
|
|
|
const result = await this.fetchCommentList({
|
|
|
destId: this.destId,
|
|
|
columnType: this.columnType,
|
|
|
page: this.page,
|
|
|
});
|
|
|
let dirty = true;
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
const appendComments = get(result, 'data.commentInfos', []);
|
|
|
const comments = get(result, 'data.commentInfos', []);
|
|
|
|
|
|
if (refresh) {
|
|
|
this.commentList = appendComments;
|
|
|
} else {
|
|
|
this.commentList = this.commentList.concat(appendComments);
|
|
|
}
|
|
|
|
|
|
if (appendComments.length) {
|
|
|
if (comments.length) {
|
|
|
this.page++;
|
|
|
this.$emit('on-page-change', {
|
|
|
page: this.page,
|
|
|
size: result.data.total
|
|
|
});
|
|
|
return Promise.resolve(comments);
|
|
|
} else {
|
|
|
dirty = false;
|
|
|
return Promise.resolve(false);
|
|
|
}
|
|
|
this.$emit('on-page-change', {
|
|
|
page: this.page,
|
|
|
size: result.data.total
|
|
|
});
|
|
|
} else {
|
|
|
this.$createToast && this.$createToast({
|
|
|
txt: result.message || '服务器开小差了',
|
...
|
...
|
@@ -87,12 +74,6 @@ export default { |
|
|
time: 1000
|
|
|
}).show();
|
|
|
}
|
|
|
|
|
|
this.$refs.scroll.forceUpdate(dirty);
|
|
|
return result;
|
|
|
},
|
|
|
onPullingUp() {
|
|
|
this.fetchComments();
|
|
|
},
|
|
|
async onComment() {
|
|
|
const result = await this.postComment({
|
...
|
...
|
@@ -103,7 +84,7 @@ export default { |
|
|
});
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
this.onRefresh();
|
|
|
this.init();
|
|
|
} else {
|
|
|
this.$createToast({
|
|
|
txt: result.message || '服务器开小差了',
|
...
|
...
|
@@ -112,10 +93,9 @@ export default { |
|
|
}).show();
|
|
|
}
|
|
|
},
|
|
|
async onRefresh() {
|
|
|
init() {
|
|
|
this.page = 1;
|
|
|
await this.fetchComments(true);
|
|
|
this.$refs.scroll.forceUpdate(true);
|
|
|
this.$refs.comment.init();
|
|
|
},
|
|
|
async onReply({commentId}) {
|
|
|
const result = await this.fetchReplayList({
|
...
|
...
|
|