Authored by 杨延青

Merge branch 'hotfix/share' into 'feature/0715'

Hotfix/share



See merge request !108
@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 </template> 11 </template>
12 12
13 <script> 13 <script>
  14 +import Share from 'plugins/share';
14 import {get, find} from 'lodash'; 15 import {get, find} from 'lodash';
15 import {mapState, mapMutations} from 'vuex'; 16 import {mapState, mapMutations} from 'vuex';
16 17
@@ -35,7 +36,6 @@ export default { @@ -35,7 +36,6 @@ export default {
35 }); 36 });
36 }); 37 });
37 38
38 -  
39 const barColor = get(this.$route, 'meta.statusBarColor'); 39 const barColor = get(this.$route, 'meta.statusBarColor');
40 40
41 if (barColor) { 41 if (barColor) {
@@ -71,6 +71,10 @@ export default { @@ -71,6 +71,10 @@ export default {
71 }); 71 });
72 } 72 }
73 73
  74 + if (!this.$yoho.isApp) {
  75 + Share.init();
  76 + }
  77 +
74 this.reportEnter(); 78 this.reportEnter();
75 }, 79 },
76 methods: { 80 methods: {
@@ -82,6 +82,8 @@ @@ -82,6 +82,8 @@
82 82
83 <script> 83 <script>
84 import {get} from 'lodash'; 84 import {get} from 'lodash';
  85 +import Share from 'plugins/share';
  86 +import {getDetailShareData} from 'utils/share-handler';
85 87
86 import YAS from 'utils/yas-constants'; 88 import YAS from 'utils/yas-constants';
87 import ArticleDetailHeader from './components/detail/article-header'; 89 import ArticleDetailHeader from './components/detail/article-header';
@@ -97,8 +99,7 @@ const {mapState, mapActions, mapMutations} = createNamespacedHelpers('article'); @@ -97,8 +99,7 @@ const {mapState, mapActions, mapMutations} = createNamespacedHelpers('article');
97 export default { 99 export default {
98 name: 'ArticleDetailPage', 100 name: 'ArticleDetailPage',
99 props: { 101 props: {
100 - share: Boolean,  
101 - setShareData: Function 102 + share: Boolean
102 }, 103 },
103 data() { 104 data() {
104 return { 105 return {
@@ -124,6 +125,7 @@ export default { @@ -124,6 +125,7 @@ export default {
124 this.id = +this.$route.params.id; 125 this.id = +this.$route.params.id;
125 this.init(); 126 this.init();
126 } else { 127 } else {
  128 + this.setShareData(this.articleInfo);
127 this.reportProductShow(this.articleInfo); 129 this.reportProductShow(this.articleInfo);
128 } 130 }
129 this.$yoho.safetyInterface(() => { 131 this.$yoho.safetyInterface(() => {
@@ -286,9 +288,8 @@ export default { @@ -286,9 +288,8 @@ export default {
286 const article = get(res, 'data.detailList[0]', this.articleInfo); 288 const article = get(res, 'data.detailList[0]', this.articleInfo);
287 289
288 this.reportProductShow(article); 290 this.reportProductShow(article);
289 - if (this.share && this.setShareData) {  
290 - this.setShareData(article);  
291 - } 291 +
  292 + this.setShareData(article);
292 }); 293 });
293 }, 294 },
294 async onFetch() { 295 async onFetch() {
@@ -367,6 +368,13 @@ export default { @@ -367,6 +368,13 @@ export default {
367 this.$refs.detailNote.onComment(comment); 368 this.$refs.detailNote.onComment(comment);
368 } 369 }
369 }, 370 },
  371 + setShareData(article) {
  372 + if (this.$yoho.isApp || !article) {
  373 + return;
  374 + }
  375 +
  376 + Share.setShareInfo(getDetailShareData(article));
  377 + },
370 reportArticleShow(items) { 378 reportArticleShow(items) {
371 if (!items || !items.length) { 379 if (!items || !items.length) {
372 return; 380 return;
@@ -42,6 +42,7 @@ @@ -42,6 +42,7 @@
42 <script> 42 <script>
43 import {throttle, get} from 'lodash'; 43 import {throttle, get} from 'lodash';
44 import Share from 'plugins/share'; 44 import Share from 'plugins/share';
  45 +import {getTopicShareData} from 'utils/share-handler';
45 import YAS from 'utils/yas-constants'; 46 import YAS from 'utils/yas-constants';
46 import ArticleItem2 from './components/article/article-item2'; 47 import ArticleItem2 from './components/article/article-item2';
47 import TopicHeader from './components/topic/header'; 48 import TopicHeader from './components/topic/header';
@@ -96,6 +97,8 @@ export default { @@ -96,6 +97,8 @@ export default {
96 this.topicName = this.$route.params.topicName; 97 this.topicName = this.$route.params.topicName;
97 this.reload = true; 98 this.reload = true;
98 this.init(); 99 this.init();
  100 + } else {
  101 + this.setPageShareInfo(this.topicSimpleInfo);
99 } 102 }
100 }, 103 },
101 mounted() { 104 mounted() {
@@ -291,18 +294,12 @@ export default { @@ -291,18 +294,12 @@ export default {
291 toDownloadPage() { 294 toDownloadPage() {
292 !this.publishUrl && this.$links.toDownloadApp(); 295 !this.publishUrl && this.$links.toDownloadApp();
293 }, 296 },
294 - setPageShareInfo({topicName, topicImageUrl, topicDesc}) {  
295 - if (this.share) {  
296 - document && (document.title = topicName || '话题');  
297 -  
298 - if (!this.$yoho.isApp) {  
299 - Share.setShareInfo({  
300 - title: topicName,  
301 - imgUrl: topicImageUrl,  
302 - desc: '我在有货的社区发现一个热门话题。' + topicDesc,  
303 - });  
304 - } 297 + setPageShareInfo(topic) {
  298 + if (this.$yoho.isApp || !topic) {
  299 + return;
305 } 300 }
  301 +
  302 + Share.setShareInfo(getTopicShareData(topic));
306 }, 303 },
307 reportTopicFollow() { 304 reportTopicFollow() {
308 this.$store.dispatch('reportYas', { 305 this.$store.dispatch('reportYas', {
@@ -69,6 +69,8 @@ @@ -69,6 +69,8 @@
69 69
70 <script> 70 <script>
71 import {assign, get} from 'lodash'; 71 import {assign, get} from 'lodash';
  72 +import Share from 'plugins/share';
  73 +import {getAuthorShareData} from 'utils/share-handler';
72 import {Scroll, Loading} from 'cube-ui'; 74 import {Scroll, Loading} from 'cube-ui';
73 import FavTabBlock from './fav-tab-block'; 75 import FavTabBlock from './fav-tab-block';
74 import WaterFall from './scroll-reveal'; 76 import WaterFall from './scroll-reveal';
@@ -306,6 +308,7 @@ export default { @@ -306,6 +308,7 @@ export default {
306 data.showAvatar = true; 308 data.showAvatar = true;
307 this.authorBaseData = data; 309 this.authorBaseData = data;
308 this.isOwner = +data.userType === 1; 310 this.isOwner = +data.userType === 1;
  311 + this.setShareInfo({...data, ...this.authorInfo});
309 }); 312 });
310 313
311 this[this._apiNamePre + 'AritcleNum'](this.authorInfo).then(res => { 314 this[this._apiNamePre + 'AritcleNum'](this.authorInfo).then(res => {
@@ -421,6 +424,13 @@ export default { @@ -421,6 +424,13 @@ export default {
421 }); 424 });
422 } 425 }
423 }, 426 },
  427 + setShareInfo(author) {
  428 + if (this.$yoho.isApp || !author) {
  429 + return;
  430 + }
  431 +
  432 + Share.setShareInfo(getAuthorShareData(author));
  433 + },
424 toDownloadPage() { 434 toDownloadPage() {
425 !this.publishUrl && this.$links.toDownloadApp(); 435 !this.publishUrl && this.$links.toDownloadApp();
426 }, 436 },
1 let shareData = { 1 let shareData = {
2 - title: '', 2 + title: '来YO!社区,一起玩潮流!',
3 link: '', 3 link: '',
4 - desc: '', 4 + desc: 'Yoho!buy有货App',
5 imgUrl: 'http://static.yohobuy.com/m/v1/img/touch/apple-touch-icon-144x144-precomposed-new.png' 5 imgUrl: 'http://static.yohobuy.com/m/v1/img/touch/apple-touch-icon-144x144-precomposed-new.png'
6 }; 6 };
7 7
@@ -14,12 +14,13 @@ let jsApiList = [ @@ -14,12 +14,13 @@ let jsApiList = [
14 'onMenuShareQZone' 14 'onMenuShareQZone'
15 ]; 15 ];
16 16
17 -const setWxShareData = function() {  
18 - window.wx.onMenuShareTimeline(shareData);  
19 - window.wx.onMenuShareAppMessage(shareData);  
20 - window.wx.onMenuShareQQ(shareData);  
21 - window.wx.onMenuShareQZone(shareData);  
22 - window.wx.onMenuShareWeibo(shareData); 17 +const setWxShareData = function(shareInfo) {
  18 + shareInfo = shareInfo || shareData;
  19 + window.wx.onMenuShareTimeline(shareInfo);
  20 + window.wx.onMenuShareAppMessage(shareInfo);
  21 + window.wx.onMenuShareQQ(shareInfo);
  22 + window.wx.onMenuShareQZone(shareInfo);
  23 + window.wx.onMenuShareWeibo(shareInfo);
23 }; 24 };
24 25
25 function loadScript(url, success) { 26 function loadScript(url, success) {
@@ -114,20 +115,21 @@ function init(qs) { @@ -114,20 +115,21 @@ function init(qs) {
114 export default { 115 export default {
115 init, 116 init,
116 setShareInfo(data) { 117 setShareInfo(data) {
117 - shareData.title = data.title;  
118 - shareData.desc = data.desc || '逛';  
119 - shareData.link = data.link || location.href;  
120 - shareData.imgUrl = data.imgUrl || shareData.imgUrl; 118 + setTimeout(() => {
  119 + let shareInfo = Object.assign({}, shareData, data || {});
121 120
122 - if (window.wx) {  
123 - setWxShareData();  
124 - } 121 + shareInfo.link = shareInfo.link || location.href;
125 122
126 - window.setShareInfo && window.setShareInfo({  
127 - title: shareData.title,  
128 - summary: shareData.desc,  
129 - pic: shareData.imgUrl,  
130 - url: shareData.link  
131 - }); 123 + if (window.wx) {
  124 + setWxShareData(shareInfo);
  125 + }
  126 +
  127 + window.setShareInfo && window.setShareInfo({
  128 + title: shareInfo.title,
  129 + summary: shareInfo.desc,
  130 + pic: shareInfo.imgUrl,
  131 + url: shareInfo.link
  132 + });
  133 + }, 100);
132 } 134 }
133 }; 135 };
@@ -50,7 +50,18 @@ const getTopicShareData = (topic) => { @@ -50,7 +50,18 @@ const getTopicShareData = (topic) => {
50 }; 50 };
51 }; 51 };
52 52
  53 +const getAuthorShareData = (author) => {
  54 + return {
  55 + title: `@${author.nickName} YO!社区,一起来玩潮流!`,
  56 + imgUrl: handleProtocol(get(author, 'headIco', '').split('?')[0] || DEFAULT_SHARE_IMAGE),
  57 + link: handleProtocol(`${location.origin}/grass/author/${author.authorType}/${author.authorUid}`),
  58 + desc: author.signature || '',
  59 + hideType: ['7', '8', '9']
  60 + };
  61 +};
  62 +
53 export { 63 export {
54 getDetailShareData, 64 getDetailShareData,
55 - getTopicShareData 65 + getTopicShareData,
  66 + getAuthorShareData
56 }; 67 };