|
|
<template>
|
|
|
<div class="comment-context">
|
|
|
<p class="comment-title">共{{commentCount}}条评论</p>
|
|
|
<p class="comment-title">共{{totalComment}}条评论</p>
|
|
|
<div class="comment-list">
|
|
|
<CommentItem
|
|
|
v-for="comment in commentList"
|
...
|
...
|
@@ -15,19 +15,19 @@ |
|
|
</CommentItem>
|
|
|
</div>
|
|
|
<div v-show="showMore" class="more-comment hover-opacity" @click="onFetch">
|
|
|
<p class="loading" v-if="onFetching">
|
|
|
<p class="loading-wrap" v-if="onFetching">
|
|
|
<Loading :size="20"></Loading>
|
|
|
加载中
|
|
|
</p>
|
|
|
<span v-else>展开{{page > 2 ? '更多' : commentCount + '条'}}评论</span>
|
|
|
|
|
|
<span v-else>展开{{page > 2 ? '更多' : moreCommentNum + '条'}}评论</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import {get, forEach, find} from 'lodash';
|
|
|
import {Loading} from 'cube-ui';
|
|
|
import {createNamespacedHelpers} from 'vuex';
|
|
|
import {mapState as mapYohoState, mapActions as mapYohoActions, createNamespacedHelpers} from 'vuex';
|
|
|
|
|
|
const {mapActions} = createNamespacedHelpers('comment');
|
|
|
|
...
|
...
|
@@ -47,13 +47,30 @@ export default { |
|
|
commentList: [],
|
|
|
page: 1,
|
|
|
onFetching: false,
|
|
|
showMore: false
|
|
|
showMore: false,
|
|
|
addCommentNum: 0,
|
|
|
moreCommentNum: 0
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
if (!this.yoho.context.userHeadIco) {
|
|
|
this.$sdk.getUser().then(user => {
|
|
|
if (user && user.uid) {
|
|
|
this.fetchUserProfile();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
this.init();
|
|
|
},
|
|
|
computed: {
|
|
|
...mapYohoState(['yoho']),
|
|
|
totalComment() {
|
|
|
return this.commentCount + this.addCommentNum;
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
...mapYohoActions(['fetchUserProfile']),
|
|
|
...mapActions(['fetchCommentList', 'fetchReplayList', 'postComment']),
|
|
|
init() {
|
|
|
this.commentList.length = 0;
|
...
|
...
|
@@ -62,6 +79,15 @@ export default { |
|
|
|
|
|
this.onFetch();
|
|
|
},
|
|
|
updateMoreCommentNum(list = []) {
|
|
|
let moreCommentNum = this.commentCount;
|
|
|
|
|
|
forEach(list, val => {
|
|
|
val.childrenComments = val.childrenComments || [];
|
|
|
moreCommentNum -= (val.childrenComments.length + 1);
|
|
|
});
|
|
|
this.moreCommentNum = moreCommentNum;
|
|
|
},
|
|
|
async onFetch() {
|
|
|
if (this.onFetching || (this.page > 1 && !this.showMore)) {
|
|
|
return;
|
...
|
...
|
@@ -79,16 +105,45 @@ export default { |
|
|
setTimeout(() => {
|
|
|
if (result.code === 200) {
|
|
|
this.showMore = result.data.totalPage > this.page;
|
|
|
this.commentList = this.commentList.concat(result.data.commentInfos || []);
|
|
|
|
|
|
if (this.page === 1) {
|
|
|
this.updateMoreCommentNum(result.data.commentInfos);
|
|
|
}
|
|
|
|
|
|
this.page++;
|
|
|
this.commentList = this.commentList.concat(result.data.commentInfos || []);
|
|
|
}
|
|
|
|
|
|
this.onFetching = false;
|
|
|
}, 800);
|
|
|
}, this.page > 1 ? 800 : 0);
|
|
|
},
|
|
|
onReply() {
|
|
|
onReply({comment}) {
|
|
|
const parentId = comment.rootId || comment.parentId;
|
|
|
|
|
|
forEach(this.commentList, (val, index) => {
|
|
|
if (val.parentComment && val.parentComment.id == comment.parentId) {
|
|
|
this.addCommentNum++;
|
|
|
val.childrenComments.unshift(Object.assign(comment, {
|
|
|
id: comment.destId,
|
|
|
destId: this.articleId,
|
|
|
headIco: this.yoho.context.userHeadIco,
|
|
|
userName: this.yoho.context.userName,
|
|
|
parentUserName: get(find(val.childrenComments, {id: comment.parentId}), 'userName', '')
|
|
|
}));
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
addComment(comment) {
|
|
|
this.addCommentNum++;
|
|
|
this.commentList.unshift({
|
|
|
childrenComments: [],
|
|
|
parentComment: Object.assign(comment, {
|
|
|
id: comment.destId,
|
|
|
destId: this.articleId,
|
|
|
headIco: this.yoho.context.userHeadIco,
|
|
|
userName: this.yoho.context.userName
|
|
|
})
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
components: {
|
...
|
...
|
@@ -120,7 +175,7 @@ export default { |
|
|
align-items: center;
|
|
|
justify-content: center;
|
|
|
|
|
|
.loading {
|
|
|
.loading-wrap {
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
justify-content: center;
|
...
|
...
|
|