Authored by shuaiguo

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

@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 :item-w="344" :gutter-w="18" 7 :item-w="344" :gutter-w="18"
8 :isLoading="isFetchingArticleList" 8 :isLoading="isFetchingArticleList"
9 @load-more="loadMore" 9 @load-more="loadMore"
  10 + @update-praise="updatePraise"
10 > 11 >
11 </waterFallList> 12 </waterFallList>
12 13
@@ -37,7 +38,8 @@ export default { @@ -37,7 +38,8 @@ export default {
37 data() { 38 data() {
38 return { 39 return {
39 listData: [], 40 listData: [],
40 - needLoadingData: false 41 + needLoadingData: false,
  42 + isUpdatingPraise: false, // 是否正在调用点赞接口
41 }; 43 };
42 }, 44 },
43 mounted() { 45 mounted() {
@@ -64,12 +66,14 @@ export default { @@ -64,12 +66,14 @@ export default {
64 beforeRouteEnter(to, from, next) { 66 beforeRouteEnter(to, from, next) {
65 next(vm => { 67 next(vm => {
66 // 判断页面来源,决定是否重新读取数据 68 // 判断页面来源,决定是否重新读取数据
67 - if (!to.name || from.name !== 'ArticleDetail') { 69 + if ((!to.name || from.name !== 'ArticleDetail') || !vm.articleList.length) {
68 vm.$store.dispatch('article/articleList/fetchArticleList', { 70 vm.$store.dispatch('article/articleList/fetchArticleList', {
69 page: 1, 71 page: 1,
70 limit: 20, 72 limit: 20,
71 reload: true 73 reload: true
72 }); 74 });
  75 + } else if (from.name === 'ArticleDetail') {
  76 + vm.$refs.waterFallList.scrollToOldPlace();
73 } 77 }
74 78
75 /*if (to.name === 'List') { 79 /*if (to.name === 'List') {
@@ -81,14 +85,8 @@ export default { @@ -81,14 +85,8 @@ export default {
81 }*/ 85 }*/
82 }); 86 });
83 }, 87 },
84 - beforeRouteLeave(to, from, next) {  
85 - if (this.$refs.waterFallList) {  
86 - console.log(this.$refs.waterFallList)  
87 - }  
88 - this.$refs.waterFallList.routeLeave(to, from, next);  
89 - },  
90 methods: { 88 methods: {
91 - ...mapActions(['fetchArticleList']), 89 + ...mapActions(['fetchArticleList', 'updateArticlePraise']),
92 loadMore() { 90 loadMore() {
93 if (this.listInfo.pageNo < this.listInfo.totalPage && !this.isFetchingArticleList) { 91 if (this.listInfo.pageNo < this.listInfo.totalPage && !this.isFetchingArticleList) {
94 console.log('loadMore'); 92 console.log('loadMore');
@@ -98,6 +96,17 @@ export default { @@ -98,6 +96,17 @@ export default {
98 lastedTime: this.articleListInfo.lastedTime 96 lastedTime: this.articleListInfo.lastedTime
99 }); 97 });
100 } 98 }
  99 + },
  100 + updatePraise({articleId, status, index}) {
  101 + if (!this.isUpdatingPraise) {
  102 + this.isUpdatingPraise = true;
  103 + }
  104 + this.updateArticlePraise({articleId, status, index}).then(result => {
  105 + this.isUpdatingPraise = false;
  106 + console.log('praiseResult=', result);
  107 + }).catch(() => {
  108 + this.isUpdatingPraise = false;
  109 + });
101 } 110 }
102 }, 111 },
103 112
@@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
33 <waterFallList 33 <waterFallList
34 :listData="recommendArticleList" 34 :listData="recommendArticleList"
35 :item-w="344" :gutter-w="15" 35 :item-w="344" :gutter-w="15"
  36 + @update-praise="onUpdatePraise"
36 > 37 >
37 </waterFallList> 38 </waterFallList>
38 </ClientOnly> 39 </ClientOnly>
@@ -114,6 +115,12 @@ export default { @@ -114,6 +115,12 @@ export default {
114 } else { 115 } else {
115 this.$yoho.auth(); 116 this.$yoho.auth();
116 } 117 }
  118 + },
  119 + onUpdatePraise({articleId, status}) {
  120 + this.updatePraiseStatus({
  121 + articleId,
  122 + status
  123 + });
117 } 124 }
118 } 125 }
119 }; 126 };
@@ -76,7 +76,6 @@ export default { @@ -76,7 +76,6 @@ export default {
76 scrollTop: 0, // 页面滚动高度 76 scrollTop: 0, // 页面滚动高度
77 isLogin: false, // 是否登录 77 isLogin: false, // 是否登录
78 loadText: '', // 加载新列表提示文字 78 loadText: '', // 加载新列表提示文字
79 - isUpdatingPraise: false, // 是否正在调用点赞接口  
80 }; 79 };
81 }, 80 },
82 computed: { 81 computed: {
@@ -116,19 +115,22 @@ export default { @@ -116,19 +115,22 @@ export default {
116 } 115 }
117 } 116 }
118 }, 117 },
  118 + mounted() {
  119 + console.log('mounted');
  120 + this.checkLogin();
  121 + },
119 methods: { 122 methods: {
120 - ...mapActions(['updateArticlePraise']),  
121 loadMore() { 123 loadMore() {
122 this.$emit('load-more'); 124 this.$emit('load-more');
123 }, 125 },
124 - scroll(e) { 126 + scroll() {
125 // console.log(this.$refs.waterfall.scrollTop); 127 // console.log(this.$refs.waterfall.scrollTop);
126 this.scrollTop = this.$refs.waterfall.scrollTop; 128 this.scrollTop = this.$refs.waterfall.scrollTop;
127 this.$refs.waterfallComp.emitLoadMore(); 129 this.$refs.waterfallComp.emitLoadMore();
128 }, 130 },
129 async checkLogin() { 131 async checkLogin() {
130 - const user = await this.$yoho.auth();  
131 - 132 + const user = await this.$sdk.getUser(true);
  133 + console.log('userInfo=', user);
132 if (user.uid) { 134 if (user.uid) {
133 this.isLogin = true; 135 this.isLogin = true;
134 } 136 }
@@ -145,20 +147,25 @@ export default { @@ -145,20 +147,25 @@ export default {
145 }); 147 });
146 } 148 }
147 }, 149 },
148 - updatePraise(e) {  
149 - let articleId = e.currentTarget.dataset.id;  
150 - let index = e.currentTarget.dataset.index;  
151 - let status = e.currentTarget.dataset.praised === 'Y' ? 1 : 0; 150 + updatePraise(e) { // 点赞
  151 + if (this.isLogin) {
  152 + let articleId = e.currentTarget.dataset.id;
  153 + let index = e.currentTarget.dataset.index;
  154 + let status = e.currentTarget.dataset.praised === 'Y' ? 1 : 0;
152 155
153 - console.log(articleId,index, status);  
154 - this.updateArticlePraise({articleId, status, index}).then(result => {  
155 - console.log(result);  
156 - }); 156 + console.log(articleId, index, status);
  157 + this.$emit('update-praise', {articleId, status, index});
  158 + } else {
  159 + this.$yoho.auth();
  160 + }
157 }, 161 },
  162 + scrollToOldPlace() { // 从详情页路由回来时,滚动到原来的位置
  163 + console.log('scrollTop=', this.scrollTop);
  164 + if (!this.isLogin) {
  165 + this.checkLogin();
  166 + }
158 167
159 - routeLeave(to, from, next) {  
160 - console.log('RouteLeave:', 'to=', to, 'from=', from);  
161 - next(); 168 + this.$refs.waterfall.scrollTo(0, this.scrollTop);
162 } 169 }
163 } 170 }
164 }; 171 };
1 const FETCH_DETAIL_INFO = 'FETCH_DETAIL_INFO'; 1 const FETCH_DETAIL_INFO = 'FETCH_DETAIL_INFO';
2 const UPDATE_ARTICLE_PRAISE_INFO = 'UPDATE_ARTICLE_PRAISE_INFO'; 2 const UPDATE_ARTICLE_PRAISE_INFO = 'UPDATE_ARTICLE_PRAISE_INFO';
3 -const FETCH_RECOMMEND_ARTICLES = 'FETCH_RECOMMEND_ARTICLES'; 3 +const FETCH_RECCOMMEND_ARTICLES = 'FETCH_RECCOMMEND_ARTICLES';
  4 +const UPDATE_RECCOMMEND_ARTICLES_PRAISE = 'UPDATE_RECCOMMEND_ARTICLES_PRAISE';
4 5
5 import { UPDATE_ARTICLE_PRAISE } from './list/types'; 6 import { UPDATE_ARTICLE_PRAISE } from './list/types';
6 7
@@ -34,6 +35,7 @@ export default function() { @@ -34,6 +35,7 @@ export default function() {
34 if (res.code === 200) { 35 if (res.code === 200) {
35 commit(`article/articleList/${UPDATE_ARTICLE_PRAISE}`, {articleId, status}, {root: true}); 36 commit(`article/articleList/${UPDATE_ARTICLE_PRAISE}`, {articleId, status}, {root: true});
36 commit(UPDATE_ARTICLE_PRAISE_INFO); 37 commit(UPDATE_ARTICLE_PRAISE_INFO);
  38 + commit(UPDATE_RECCOMMEND_ARTICLES_PRAISE, {articleId, status});
37 } 39 }
38 }, 40 },
39 async fetchRecommendArticle({commit}, {articleId}) { 41 async fetchRecommendArticle({commit}, {articleId}) {
@@ -42,7 +44,7 @@ export default function() { @@ -42,7 +44,7 @@ export default function() {
42 }); 44 });
43 45
44 if (res.code === 200) { 46 if (res.code === 200) {
45 - commit(FETCH_RECOMMEND_ARTICLES, res.data); 47 + commit(FETCH_RECCOMMEND_ARTICLES, res.data);
46 } 48 }
47 } 49 }
48 }, 50 },
@@ -60,7 +62,25 @@ export default function() { @@ -60,7 +62,25 @@ export default function() {
60 praiseCount: hasPraise === 'Y' ? praiseCount - 1 : praiseCount + 1 62 praiseCount: hasPraise === 'Y' ? praiseCount - 1 : praiseCount + 1
61 }; 63 };
62 }, 64 },
63 - [FETCH_RECOMMEND_ARTICLES](state, list = []) { 65 + [UPDATE_RECCOMMEND_ARTICLES_PRAISE](state, {articleId, status}) {
  66 + let article = state.recommendArticleList.find(item => +item.articleId === +articleId);
  67 +
  68 + if (article && article.articleId === parseInt(articleId, 10)) {
  69 + if (article.praiseCount === 0 && status === 0) {
  70 + article.praiseCount += 1;
  71 + article.hasPraised = 'Y';
  72 + } else if (article.praiseCount > 0) {
  73 + if (status === 0) {
  74 + article.praiseCount += 1;
  75 + article.hasPraised = 'Y';
  76 + } else {
  77 + article.praiseCount -= 1;
  78 + article.hasPraised = 'N';
  79 + }
  80 + }
  81 + }
  82 + },
  83 + [FETCH_RECCOMMEND_ARTICLES](state, list = []) {
64 state.recommendArticleList = list.map((item)=> { 84 state.recommendArticleList = list.map((item)=> {
65 let imageHeight = item.imageHeight; 85 let imageHeight = item.imageHeight;
66 let imageWidth = item.imageWidth; 86 let imageWidth = item.imageWidth;
@@ -35,7 +35,7 @@ export default { @@ -35,7 +35,7 @@ export default {
35 [Types.UPDATE_ARTICLE_PRAISE](state, {articleId, status, index}) { 35 [Types.UPDATE_ARTICLE_PRAISE](state, {articleId, status, index}) {
36 let article = null; 36 let article = null;
37 37
38 - if (index) { 38 + if (index && index != 0) {
39 article = state.articleList[index]; 39 article = state.articleList[index];
40 } else { 40 } else {
41 article = state.articleList.find(item => +item.articleId === +articleId); 41 article = state.articleList.find(item => +item.articleId === +articleId);