Authored by yyq

fix comment

... ... @@ -2,7 +2,7 @@ import {get, trim} from 'lodash';
import {createNamespacedHelpers} from 'vuex';
const {mapActions} = createNamespacedHelpers('comment');
import YAS from 'utils/yas-constants';
const {mapActions: articleMapActions} = createNamespacedHelpers('article');
const {mapActions: articleMapActions, mapMutations: articleMapMutations} = createNamespacedHelpers('article');
export default {
name: 'CommentPlaceholder',
... ... @@ -35,6 +35,7 @@ export default {
methods: {
...mapActions(['postComment']),
...articleMapActions(['fetchArticleUpdate']),
...articleMapMutations(['UPDATE_ARTICLE_COMMENT_COUNT']),
async openComentInput() {
if (this.share) {
return this.$links.toDownloadApp();
... ... @@ -99,6 +100,8 @@ export default {
};
if (result.code === 200) {
this.UPDATE_ARTICLE_COMMENT_COUNT({articleId: this.destId});
if (this.autoUpdate && this.addType === 0) {
await this.fetchArticleUpdate({articleId: this.destId});
}
... ...
... ... @@ -77,9 +77,9 @@ router.onReady(() => {
params: {
appop: 'YB_H5_PAGE_OPEN_L',
param: {
F_URL: `${location.origin}${to.fullPath}`,
PAGE_URL: `${location.origin}${from.fullPath}`,
PAGE_NAME: from.name
F_URL: `${location.origin}${from.fullPath}`,
PAGE_URL: `${location.origin}${to.fullPath}`,
PAGE_NAME: to.name
}
}
});
... ...
... ... @@ -193,9 +193,9 @@ export default {
},
footerData() {
return {
favoriteCount: this.data.favoriteCount,
praiseCount: this.data.praiseCount,
commentCount: this.data.commentCount,
favoriteCount: this.articleState.favoriteCount,
praiseCount: this.articleState.praiseCount,
commentCount: this.articleState.commentCount,
hasFavor: this.articleState.hasFavor,
hasPraise: this.articleState.hasPraise,
articleId: this.data.articleId
... ...
... ... @@ -25,7 +25,7 @@
</div>
</div>
<p class="publish-time">{{publishTime}}</p>
<ArticleDetailCommentList ref="commentList" v-if="data.commentCount" :article-id="data.articleId" :comment-count="data.commentCount"></ArticleDetailCommentList>
<ArticleDetailCommentList ref="commentList" v-if="data.articleId" :article-id="data.articleId" :comment-count="articleState.commentCount"></ArticleDetailCommentList>
</div>
<div v-if="listTitle" class="rec-article-title">
... ... @@ -146,9 +146,9 @@ export default {
},
footerData() {
return {
favoriteCount: this.data.favoriteCount,
praiseCount: this.data.praiseCount,
commentCount: this.data.commentCount,
favoriteCount: this.articleState.favoriteCount,
praiseCount: this.articleState.praiseCount,
commentCount: this.articleState.commentCount,
hasFavor: this.articleState.hasFavor,
hasPraise: this.articleState.hasPraise,
articleId: this.data.articleId
... ...
<template>
<div class="comment-context">
<p class="comment-title">共{{totalComment}}条评论</p>
<div v-if="commentCount" class="comment-context">
<p class="comment-title">共{{commentCount}}条评论</p>
<div class="comment-list">
<CommentItem
v-for="comment in commentList"
... ... @@ -48,7 +48,6 @@ export default {
page: 1,
onFetching: false,
showMore: false,
addCommentNum: 0,
moreCommentNum: 0
}
},
... ... @@ -65,9 +64,6 @@ export default {
},
computed: {
...mapYohoState(['yoho']),
totalComment() {
return this.commentCount + this.addCommentNum;
}
},
methods: {
...mapYohoActions(['fetchUserProfile']),
... ... @@ -89,7 +85,7 @@ export default {
this.moreCommentNum = moreCommentNum;
},
async onFetch() {
if (this.onFetching || (this.page > 1 && !this.showMore)) {
if (!this.articleId || this.onFetching || (this.page > 1 && !this.showMore)) {
return;
}
... ... @@ -122,7 +118,6 @@ export default {
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,
... ... @@ -134,7 +129,6 @@ export default {
});
},
addComment(comment) {
this.addCommentNum++;
this.commentList.unshift({
childrenComments: [],
parentComment: Object.assign(comment, {
... ...
... ... @@ -23,16 +23,18 @@ function updateAuthorStates(state, item) {
}
function updateArticleState(state, item) {
updateAuthorStates(state, item);
let articleState = state.articleStates[item.articleId] || {};
Vue.set(state.articleStates, item.articleId, {
hasAttention: item.hasAttention,
hasFavor: item.hasFavor,
hasPraise: item.hasPraise,
commentCount: item.commentCount,
favoriteCount: item.favoriteCount,
praiseCount: item.praiseCount,
comments: item.comments
hasAttention: item.hasAttention || articleState.hasAttention,
hasFavor: item.hasFavor || articleState.hasFavor,
hasPraise: item.hasPraise || articleState.hasPraise,
commentCount: item.commentCount || articleState.commentCount || 0,
favoriteCount: item.favoriteCount || articleState.favoriteCount || 0,
praiseCount: item.praiseCount || articleState.praiseCount || 0,
comments: item.comments || articleState.comments
});
updateAuthorStates(state, item);
}
function setArticleList(state, data, type, thumb) {
... ... @@ -173,6 +175,14 @@ export default {
[Types.UPDATE_ARTICLE_STATE](state, {data}) {
updateArticleState(state, data);
},
[Types.UPDATE_ARTICLE_COMMENT_COUNT](state, {articleId, commentCount}) {
let article = state.articleStates[articleId];
if (article) {
article.commentCount = commentCount ? commentCount : (article.commentCount + 1);
updateArticleState(state, article);
}
},
[Types.ASYNC_ARTICLE_COMMENT](state, {articleId, type}) {
state[articlefield(type)].forEach(article => {
if (article.articleId === articleId) {
... ...
... ... @@ -25,6 +25,7 @@ export const CHANGE_AUTHOR_FOLLOW = 'CHANGE_AUTHOR_FOLLOW';
export const CHANGE_ARTICLE_LIST_SLIDE = 'CHANGE_ARTICLE_LIST_SLIDE';
export const UPDATE_ARTICLE_STATE = 'UPDATE_ARTICLE_STATE';
export const UPDATE_ARTICLE_COMMENT_COUNT = 'UPDATE_ARTICLE_COMMENT_COUNT';
export const ASYNC_ARTICLE_COMMENT = 'ASYNC_ARTICLE_COMMENT';
export const CHANGE_ARTICLE_LIST_INTRO = 'CHANGE_ARTICLE_LIST_INTRO';
export const CHANGE_ARTICLE_LIST_INTRO_HEIGHT = 'CHANGE_ARTICLE_LIST_INTRO_HEIGHT';
... ...