|
|
<template>
|
|
|
<div class="comment-list">
|
|
|
<div class="comment-content">
|
|
|
<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>
|
|
|
<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>
|
|
|
</div>
|
|
|
<div class="comment-footer">
|
|
|
<div class="comment-input" @click="onComment">参与评论</div>
|
|
|
<CommentPlaceholder class="comment-input">
|
|
|
参与评论
|
|
|
</CommentPlaceholder>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
...
|
...
|
@@ -21,8 +23,8 @@ |
|
|
<script>
|
|
|
import CommentItem from './comment-item.vue';
|
|
|
import {Scroll} from 'cube-ui';
|
|
|
import {createNamespacedHelpers} from 'vuex';
|
|
|
import {get} from 'lodash';
|
|
|
import {createNamespacedHelpers} from 'vuex';
|
|
|
const {mapActions} = createNamespacedHelpers('comment');
|
|
|
|
|
|
export default {
|
...
|
...
|
@@ -37,36 +39,57 @@ export default { |
|
|
data() {
|
|
|
return {
|
|
|
page: 1,
|
|
|
commentList: [],
|
|
|
scrollOption: {
|
|
|
pullUpLoad: {
|
|
|
threshold: 200,
|
|
|
txt: {
|
|
|
more: '上拉加载',
|
|
|
noMore: '- 已经到底了 -'
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
show: false
|
|
|
};
|
|
|
},
|
|
|
watch: {
|
|
|
destId() {
|
|
|
this.init();
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
setTimeout(() => {
|
|
|
this.show = true;
|
|
|
this.fetchComments();
|
|
|
}, 200);
|
|
|
},
|
|
|
methods: {
|
|
|
...mapActions(['fetchCommentList', 'fetchReplayList', 'postComment']),
|
|
|
async onFetch() {
|
|
|
async fetchComments(refresh) {
|
|
|
const result = await this.fetchCommentList({
|
|
|
destId: this.destId,
|
|
|
columnType: this.columnType,
|
|
|
page: this.page,
|
|
|
});
|
|
|
let dirty = true;
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
const comments = get(result, 'data.commentInfos', []);
|
|
|
|
|
|
if (refresh) {
|
|
|
this.commentList = comments;
|
|
|
} else {
|
|
|
this.commentList = this.commentList.concat(comments);
|
|
|
}
|
|
|
|
|
|
if (comments.length) {
|
|
|
this.page++;
|
|
|
this.$emit('on-page-change', {
|
|
|
page: this.page,
|
|
|
size: result.data.total
|
|
|
});
|
|
|
return Promise.resolve(comments);
|
|
|
} else {
|
|
|
return Promise.resolve(false);
|
|
|
dirty = false;
|
|
|
}
|
|
|
this.$emit('on-page-change', {
|
|
|
page: this.page,
|
|
|
size: result.data.total
|
|
|
});
|
|
|
} else {
|
|
|
this.$createToast && this.$createToast({
|
|
|
txt: result.message || '服务器开小差了',
|
...
|
...
|
@@ -74,6 +97,11 @@ export default { |
|
|
time: 1000
|
|
|
}).show();
|
|
|
}
|
|
|
this.$refs.scroll.forceUpdate(dirty);
|
|
|
return result;
|
|
|
},
|
|
|
onPullingUp() {
|
|
|
this.fetchComments();
|
|
|
},
|
|
|
async onComment() {
|
|
|
const result = await this.postComment({
|
...
|
...
|
@@ -93,9 +121,10 @@ export default { |
|
|
}).show();
|
|
|
}
|
|
|
},
|
|
|
init() {
|
|
|
async init() {
|
|
|
this.page = 1;
|
|
|
this.$refs.comment.init();
|
|
|
await this.fetchComments(true);
|
|
|
this.$refs.scroll.forceUpdate(true);
|
|
|
},
|
|
|
async onReply({commentId}) {
|
|
|
const result = await this.fetchReplayList({
|
...
|
...
|
|