Authored by shuaiguo

Merge branch 'refs/heads/feature/2019/1230-community-article' into develop

... ... @@ -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() {
... ... @@ -64,12 +66,14 @@ export default {
beforeRouteEnter(to, from, next) {
next(vm => {
// 判断页面来源,决定是否重新读取数据
if (!to.name || from.name !== 'ArticleDetail') {
if ((!to.name || from.name !== 'ArticleDetail') || !vm.articleList.length) {
vm.$store.dispatch('article/articleList/fetchArticleList', {
page: 1,
limit: 20,
reload: true
});
} else if (from.name === 'ArticleDetail') {
vm.$refs.waterFallList.scrollToOldPlace();
}
/*if (to.name === 'List') {
... ... @@ -81,14 +85,8 @@ export default {
}*/
});
},
beforeRouteLeave(to, from, next) {
if (this.$refs.waterFallList) {
console.log(this.$refs.waterFallList)
}
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 +96,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;
});
}
},
... ...
... ... @@ -33,6 +33,7 @@
<waterFallList
:listData="recommendArticleList"
:item-w="344" :gutter-w="15"
@update-praise="onUpdatePraise"
>
</waterFallList>
</ClientOnly>
... ... @@ -114,6 +115,12 @@ export default {
} else {
this.$yoho.auth();
}
},
onUpdatePraise({articleId, status}) {
this.updatePraiseStatus({
articleId,
status
});
}
}
};
... ...
... ... @@ -76,7 +76,6 @@ export default {
scrollTop: 0, // 页面滚动高度
isLogin: false, // 是否登录
loadText: '', // 加载新列表提示文字
isUpdatingPraise: false, // 是否正在调用点赞接口
};
},
computed: {
... ... @@ -116,19 +115,22 @@ export default {
}
}
},
mounted() {
console.log('mounted');
this.checkLogin();
},
methods: {
...mapActions(['updateArticlePraise']),
loadMore() {
this.$emit('load-more');
},
scroll(e) {
scroll() {
// console.log(this.$refs.waterfall.scrollTop);
this.scrollTop = this.$refs.waterfall.scrollTop;
this.$refs.waterfallComp.emitLoadMore();
},
async checkLogin() {
const user = await this.$yoho.auth();
const user = await this.$sdk.getUser(true);
console.log('userInfo=', user);
if (user.uid) {
this.isLogin = true;
}
... ... @@ -145,20 +147,25 @@ export default {
});
}
},
updatePraise(e) {
let articleId = e.currentTarget.dataset.id;
let index = e.currentTarget.dataset.index;
let status = e.currentTarget.dataset.praised === 'Y' ? 1 : 0;
updatePraise(e) { // 点赞
if (this.isLogin) {
let articleId = e.currentTarget.dataset.id;
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});
} else {
this.$yoho.auth();
}
},
scrollToOldPlace() { // 从详情页路由回来时,滚动到原来的位置
console.log('scrollTop=', this.scrollTop);
if (!this.isLogin) {
this.checkLogin();
}
routeLeave(to, from, next) {
console.log('RouteLeave:', 'to=', to, 'from=', from);
next();
this.$refs.waterfall.scrollTo(0, this.scrollTop);
}
}
};
... ...
const FETCH_DETAIL_INFO = 'FETCH_DETAIL_INFO';
const UPDATE_ARTICLE_PRAISE_INFO = 'UPDATE_ARTICLE_PRAISE_INFO';
const FETCH_RECOMMEND_ARTICLES = 'FETCH_RECOMMEND_ARTICLES';
const FETCH_RECCOMMEND_ARTICLES = 'FETCH_RECCOMMEND_ARTICLES';
const UPDATE_RECCOMMEND_ARTICLES_PRAISE = 'UPDATE_RECCOMMEND_ARTICLES_PRAISE';
import { UPDATE_ARTICLE_PRAISE } from './list/types';
... ... @@ -34,6 +35,7 @@ export default function() {
if (res.code === 200) {
commit(`article/articleList/${UPDATE_ARTICLE_PRAISE}`, {articleId, status}, {root: true});
commit(UPDATE_ARTICLE_PRAISE_INFO);
commit(UPDATE_RECCOMMEND_ARTICLES_PRAISE, {articleId, status});
}
},
async fetchRecommendArticle({commit}, {articleId}) {
... ... @@ -42,7 +44,7 @@ export default function() {
});
if (res.code === 200) {
commit(FETCH_RECOMMEND_ARTICLES, res.data);
commit(FETCH_RECCOMMEND_ARTICLES, res.data);
}
}
},
... ... @@ -60,7 +62,25 @@ export default function() {
praiseCount: hasPraise === 'Y' ? praiseCount - 1 : praiseCount + 1
};
},
[FETCH_RECOMMEND_ARTICLES](state, list = []) {
[UPDATE_RECCOMMEND_ARTICLES_PRAISE](state, {articleId, status}) {
let article = state.recommendArticleList.find(item => +item.articleId === +articleId);
if (article && article.articleId === parseInt(articleId, 10)) {
if (article.praiseCount === 0 && status === 0) {
article.praiseCount += 1;
article.hasPraised = 'Y';
} else if (article.praiseCount > 0) {
if (status === 0) {
article.praiseCount += 1;
article.hasPraised = 'Y';
} else {
article.praiseCount -= 1;
article.hasPraised = 'N';
}
}
}
},
[FETCH_RECCOMMEND_ARTICLES](state, list = []) {
state.recommendArticleList = list.map((item)=> {
let imageHeight = item.imageHeight;
let imageWidth = item.imageWidth;
... ...
... ... @@ -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);
... ...