Authored by 邱骏

feat(waterfall.vue, list/mutation.js), 修改点赞方法为调用父级emit,reviewed by 郭帅

... ... @@ -7,6 +7,7 @@
:item-w="344" :gutter-w="18"
:isLoading="isFetchingArticleList"
@load-more="loadMore"
@update-praise="updatePraise"
>
</waterFallList>
... ... @@ -37,7 +38,8 @@ export default {
data() {
return {
listData: [],
needLoadingData: false
needLoadingData: false,
isUpdatingPraise: false, // 是否正在调用点赞接口
};
},
mounted() {
... ... @@ -88,7 +90,7 @@ export default {
this.$refs.waterFallList.routeLeave(to, from, next);
},
methods: {
...mapActions(['fetchArticleList']),
...mapActions(['fetchArticleList', 'updateArticlePraise']),
loadMore() {
if (this.listInfo.pageNo < this.listInfo.totalPage && !this.isFetchingArticleList) {
console.log('loadMore');
... ... @@ -98,6 +100,17 @@ export default {
lastedTime: this.articleListInfo.lastedTime
});
}
},
updatePraise({articleId, status, index}) {
if (!this.isUpdatingPraise) {
this.isUpdatingPraise = true;
}
this.updateArticlePraise({articleId, status, index}).then(result => {
this.isUpdatingPraise = false;
console.log('praiseResult=', result);
}).catch(() => {
this.isUpdatingPraise = false;
});
}
},
... ...
... ... @@ -76,7 +76,6 @@ export default {
scrollTop: 0, // 页面滚动高度
isLogin: false, // 是否登录
loadText: '', // 加载新列表提示文字
isUpdatingPraise: false, // 是否正在调用点赞接口
};
},
computed: {
... ... @@ -117,7 +116,6 @@ export default {
}
},
methods: {
...mapActions(['updateArticlePraise']),
loadMore() {
this.$emit('load-more');
},
... ... @@ -150,10 +148,8 @@ export default {
let index = e.currentTarget.dataset.index;
let status = e.currentTarget.dataset.praised === 'Y' ? 1 : 0;
console.log(articleId,index, status);
this.updateArticlePraise({articleId, status, index}).then(result => {
console.log(result);
});
console.log(articleId, index, status);
this.$emit('update-praise', {articleId, status, index});
},
routeLeave(to, from, next) {
... ...
... ... @@ -35,7 +35,7 @@ export default {
[Types.UPDATE_ARTICLE_PRAISE](state, {articleId, status, index}) {
let article = null;
if (index) {
if (index && index != 0) {
article = state.articleList[index];
} else {
article = state.articleList.find(item => +item.articleId === +articleId);
... ...