Authored by 邱骏

feat(waterfall.vue),加入登录判断

... ... @@ -66,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') {
... ... @@ -83,12 +85,6 @@ 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', 'updateArticlePraise']),
loadMore() {
... ...
... ... @@ -115,18 +115,22 @@ export default {
}
}
},
mounted() {
console.log('mounted');
this.checkLogin();
},
methods: {
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;
}
... ... @@ -143,18 +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.$emit('update-praise', {articleId, status, index});
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);
}
}
};
... ...