Showing
3 changed files
with
134 additions
and
1 deletions
@@ -11,6 +11,7 @@ | @@ -11,6 +11,7 @@ | ||
11 | 11 | ||
12 | <script> | 12 | <script> |
13 | import {get} from 'lodash'; | 13 | import {get} from 'lodash'; |
14 | +import Share from 'plugins/share'; | ||
14 | import Article from './components/article/article'; | 15 | import Article from './components/article/article'; |
15 | import ArticleItem from './components/article/article-item'; | 16 | import ArticleItem from './components/article/article-item'; |
16 | import {createNamespacedHelpers} from 'vuex'; | 17 | import {createNamespacedHelpers} from 'vuex'; |
@@ -28,6 +29,11 @@ export default { | @@ -28,6 +29,11 @@ export default { | ||
28 | created() { | 29 | created() { |
29 | this.id = +this.$route.params.id; | 30 | this.id = +this.$route.params.id; |
30 | }, | 31 | }, |
32 | + mounted() { | ||
33 | + if (!this.$yoho.isApp) { | ||
34 | + Share.init(); | ||
35 | + } | ||
36 | + }, | ||
31 | activated() { | 37 | activated() { |
32 | if (+this.$route.params.id !== this.id) { | 38 | if (+this.$route.params.id !== this.id) { |
33 | this.id = +this.$route.params.id; | 39 | this.id = +this.$route.params.id; |
@@ -81,7 +87,17 @@ export default { | @@ -81,7 +87,17 @@ export default { | ||
81 | this.page++; | 87 | this.page++; |
82 | 88 | ||
83 | if (!this.title) { | 89 | if (!this.title) { |
84 | - this.title = `@${get(result, 'data.detailList[0].authorName')} 在有货逛上发了一篇笔记,快点开看看!`; | 90 | + let first = get(result, 'data.detailList[0]'); |
91 | + | ||
92 | + this.title = `@${first.authorName} 在有货逛上发了一篇笔记,快点开看看!`; | ||
93 | + | ||
94 | + if (!this.$yoho.isApp) { | ||
95 | + Share.setShareInfo({ | ||
96 | + title: this.title, | ||
97 | + imgUrl: first.shareImage, | ||
98 | + desc: first.intro | ||
99 | + }); | ||
100 | + } | ||
85 | } | 101 | } |
86 | 102 | ||
87 | return Promise.resolve(result.data.detailList); | 103 | return Promise.resolve(result.data.detailList); |
@@ -74,6 +74,7 @@ | @@ -74,6 +74,7 @@ | ||
74 | 74 | ||
75 | <script> | 75 | <script> |
76 | import {throttle, get} from 'lodash'; | 76 | import {throttle, get} from 'lodash'; |
77 | +import Share from 'plugins/share'; | ||
77 | import YAS from 'utils/yas-constants'; | 78 | import YAS from 'utils/yas-constants'; |
78 | import ArticleItem from './components/article/article-item'; | 79 | import ArticleItem from './components/article/article-item'; |
79 | import ArticleItem2 from './components/article/article-item2'; | 80 | import ArticleItem2 from './components/article/article-item2'; |
@@ -114,6 +115,10 @@ export default { | @@ -114,6 +115,10 @@ export default { | ||
114 | mounted() { | 115 | mounted() { |
115 | if (this.$route.name === 'topic.share') { | 116 | if (this.$route.name === 'topic.share') { |
116 | this.share = true; | 117 | this.share = true; |
118 | + | ||
119 | + if (!this.$yoho.isApp) { | ||
120 | + Share.init(); | ||
121 | + } | ||
117 | } | 122 | } |
118 | 123 | ||
119 | if (this.$cookie && this.$cookie.get) { | 124 | if (this.$cookie && this.$cookie.get) { |
@@ -239,6 +244,14 @@ export default { | @@ -239,6 +244,14 @@ export default { | ||
239 | 244 | ||
240 | this.page = 1; | 245 | this.page = 1; |
241 | this.fetchTopicSimpleInfo({topicId: this.topicId}).then(res => { | 246 | this.fetchTopicSimpleInfo({topicId: this.topicId}).then(res => { |
247 | + if (this.share && !this.$yoho.isApp && res.code === 200) { | ||
248 | + Share.setShareInfo({ | ||
249 | + title: res.data.topicName, | ||
250 | + imgUrl: res.data.topicImageUrl, | ||
251 | + desc: '我在有货的社区发现一个热门话题。' + res.data.topicDesc, | ||
252 | + }); | ||
253 | + } | ||
254 | + | ||
242 | if (this.$refs.scroll) { | 255 | if (this.$refs.scroll) { |
243 | this.$refs.scroll.$el.scrollTop = 0; | 256 | this.$refs.scroll.$el.scrollTop = 0; |
244 | 257 |
apps/plugins/share.js
0 → 100644
1 | +let shareData = { | ||
2 | + title: '', | ||
3 | + link: '', | ||
4 | + desc: '逛', | ||
5 | + imgUrl: 'http://static.yohobuy.com/m/v1/img/touch/apple-touch-icon-144x144-precomposed-new.png' | ||
6 | +}; | ||
7 | + | ||
8 | +function loadScript(url, success) { | ||
9 | + const head = document.getElementsByTagName('head')[0]; | ||
10 | + let script = document.createElement('script'); | ||
11 | + | ||
12 | + script.type = 'text/javascript'; | ||
13 | + script.onload = script.onreadystatechange = function() { | ||
14 | + if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete" ) { | ||
15 | + success && success(); | ||
16 | + script.onload = script.onreadystatechange = null; | ||
17 | + } | ||
18 | + }; | ||
19 | + script.src= url; | ||
20 | + head.appendChild(script); | ||
21 | +} | ||
22 | + | ||
23 | +function jsonp(url, data = {}) { | ||
24 | + return new Promise((resolve, reject) => { | ||
25 | + let JSONP = document.createElement("script"); | ||
26 | + let query = []; | ||
27 | + | ||
28 | + data.callback = 'jsonCallBack'; | ||
29 | + Object.keys(data).forEach(key => { | ||
30 | + query.push(key + '=' + data[key]); | ||
31 | + }); | ||
32 | + | ||
33 | + window.jsonCallBack = (result) => { | ||
34 | + resolve(result); | ||
35 | + }; | ||
36 | + | ||
37 | + JSONP.type = "text/javascript"; | ||
38 | + JSONP.src = `${url}?${query.join('&')}`; | ||
39 | + const head = document.getElementsByTagName("head")[0]; | ||
40 | + head.appendChild(JSONP); | ||
41 | + | ||
42 | + setTimeout(() => { | ||
43 | + head.removeChild(JSONP) | ||
44 | + }, 500); | ||
45 | + }) | ||
46 | +} | ||
47 | + | ||
48 | +function init(qs) { | ||
49 | + if (/QQ/i.test(navigator.userAgent)) { | ||
50 | + loadScript('//qzonestyle.gtimg.cn/qzone/qzact/common/share/share.js', function() { | ||
51 | + window.setShareInfo && window.setShareInfo({ | ||
52 | + title: shareData.title, | ||
53 | + summary: shareData.desc, | ||
54 | + pic: shareData.imgUrl, | ||
55 | + url: shareData.link | ||
56 | + }); | ||
57 | + }); | ||
58 | + } | ||
59 | + | ||
60 | + if (/MicroMessenger/i.test(navigator.userAgent)) { | ||
61 | + loadScript('//res.wx.qq.com/open/js/jweixin-1.3.2.js', () => { | ||
62 | + jsonp(location.protocol + '//m.yohobuy.com/activity/wechat/share', { | ||
63 | + url: location.href | ||
64 | + }).then(res => { | ||
65 | + if (window.wx) { | ||
66 | + window.wx.config({ | ||
67 | + debug: false, | ||
68 | + appId: res.appId, | ||
69 | + timestamp: res.timestamp, | ||
70 | + nonceStr: res.nonceStr, | ||
71 | + signature: res.signature, | ||
72 | + jsApiList: jsApiList | ||
73 | + }); | ||
74 | + } | ||
75 | + }) | ||
76 | + }); | ||
77 | + } | ||
78 | + | ||
79 | + if (qs && qs.share_id) { | ||
80 | + jsonp(location.protocol + '//m.yohobuy.com/activity/share', { | ||
81 | + shareId: qs.share_id | ||
82 | + }).then(res => { | ||
83 | + if (res && res.code === 200 && res.data) { | ||
84 | + shareData.desc = res.data.content || res.data.title; | ||
85 | + shareData.imgUrl = res.data.pic; | ||
86 | + shareData.title = res.data.title; | ||
87 | + }; | ||
88 | + }); | ||
89 | + } | ||
90 | +} | ||
91 | + | ||
92 | +export default { | ||
93 | + init, | ||
94 | + setShareInfo(data) { | ||
95 | + Object.assign(shareData, data); | ||
96 | + | ||
97 | + window.setShareInfo && window.setShareInfo({ | ||
98 | + title: shareData.title, | ||
99 | + summary: shareData.desc, | ||
100 | + pic: shareData.imgUrl, | ||
101 | + url: shareData.link || location.href | ||
102 | + }); | ||
103 | + } | ||
104 | +} |
-
Please register or login to post a comment