Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-community-web
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Plain Diff
Browse Files
Authored by
杨延青
6 years ago
Commit
22c80e25c21fe13a1e10e3916608e05ff1b16bd7
2 parents
0ad917db
eb46c445
Merge branch 'feature/0430' into 'release/6.9.2'
share See merge request
!58
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
143 additions
and
1 deletions
apps/pages/article/article-share.vue
apps/pages/article/topic.vue
apps/plugins/share.js
apps/pages/article/article-share.vue
View file @
22c80e2
...
...
@@ -11,6 +11,7 @@
<script>
import {get} from 'lodash';
import Share from 'plugins/share';
import Article from './components/article/article';
import ArticleItem from './components/article/article-item';
import {createNamespacedHelpers} from 'vuex';
...
...
@@ -28,6 +29,11 @@ export default {
created() {
this.id = +this.$route.params.id;
},
mounted() {
if (!this.$yoho.isApp) {
Share.init();
}
},
activated() {
if (+this.$route.params.id !== this.id) {
this.id = +this.$route.params.id;
...
...
@@ -81,7 +87,17 @@ export default {
this.page++;
if (!this.title) {
this.title = `@${get(result, 'data.detailList[0].authorName')} 在有货逛上发了一篇笔记,快点开看看!`;
let first = get(result, 'data.detailList[0]');
this.title = `@${first.authorName} 在有货逛上发了一篇笔记,快点开看看!`;
if (!this.$yoho.isApp) {
Share.setShareInfo({
title: this.title,
imgUrl: first.shareImage,
desc: first.intro
});
}
}
return Promise.resolve(result.data.detailList);
...
...
apps/pages/article/topic.vue
View file @
22c80e2
...
...
@@ -74,6 +74,7 @@
<script>
import {throttle, get} from 'lodash';
import Share from 'plugins/share';
import YAS from 'utils/yas-constants';
import ArticleItem from './components/article/article-item';
import ArticleItem2 from './components/article/article-item2';
...
...
@@ -114,6 +115,10 @@ export default {
mounted() {
if (this.$route.name === 'topic.share') {
this.share = true;
if (!this.$yoho.isApp) {
Share.init();
}
}
if (this.$cookie && this.$cookie.get) {
...
...
@@ -239,6 +244,14 @@ export default {
this.page = 1;
this.fetchTopicSimpleInfo({topicId: this.topicId}).then(res => {
if (this.share && !this.$yoho.isApp && res.code === 200) {
Share.setShareInfo({
title: res.data.topicName,
imgUrl: res.data.topicImageUrl,
desc: '我在有货的社区发现一个热门话题。' + res.data.topicDesc,
});
}
if (this.$refs.scroll) {
this.$refs.scroll.$el.scrollTop = 0;
...
...
apps/plugins/share.js
0 → 100644
View file @
22c80e2
let
shareData
=
{
title
:
''
,
link
:
''
,
desc
:
'逛'
,
imgUrl
:
'http://static.yohobuy.com/m/v1/img/touch/apple-touch-icon-144x144-precomposed-new.png'
};
let
jsApiList
=
[
'checkJsApi'
,
'onMenuShareTimeline'
,
'onMenuShareAppMessage'
,
'onMenuShareQQ'
,
'onMenuShareWeibo'
,
'onMenuShareQZone'
];
function
loadScript
(
url
,
success
)
{
const
head
=
document
.
getElementsByTagName
(
'head'
)[
0
];
let
script
=
document
.
createElement
(
'script'
);
script
.
type
=
'text/javascript'
;
script
.
onload
=
script
.
onreadystatechange
=
function
()
{
if
(
!
this
.
readyState
||
this
.
readyState
===
"loaded"
||
this
.
readyState
===
"complete"
)
{
success
&&
success
();
script
.
onload
=
script
.
onreadystatechange
=
null
;
}
};
script
.
src
=
url
;
head
.
appendChild
(
script
);
}
function
jsonp
(
url
,
data
=
{})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
JSONP
=
document
.
createElement
(
"script"
);
let
query
=
[];
data
.
callback
=
'jsonCallBack'
;
Object
.
keys
(
data
).
forEach
(
key
=>
{
query
.
push
(
key
+
'='
+
data
[
key
]);
});
window
.
jsonCallBack
=
(
result
)
=>
{
resolve
(
result
);
};
JSONP
.
type
=
"text/javascript"
;
JSONP
.
src
=
`
$
{
url
}?
$
{
query
.
join
(
'&'
)}
`
;
const
head
=
document
.
getElementsByTagName
(
"head"
)[
0
];
head
.
appendChild
(
JSONP
);
setTimeout
(()
=>
{
head
.
removeChild
(
JSONP
)
},
500
);
})
}
function
init
(
qs
)
{
if
(
/QQ/i
.
test
(
navigator
.
userAgent
))
{
loadScript
(
'//qzonestyle.gtimg.cn/qzone/qzact/common/share/share.js'
,
function
()
{
window
.
setShareInfo
&&
window
.
setShareInfo
({
title
:
shareData
.
title
,
summary
:
shareData
.
desc
,
pic
:
shareData
.
imgUrl
,
url
:
shareData
.
link
});
});
}
if
(
/MicroMessenger/i
.
test
(
navigator
.
userAgent
))
{
loadScript
(
'//res.wx.qq.com/open/js/jweixin-1.3.2.js'
,
()
=>
{
jsonp
(
location
.
protocol
+
'//m.yohobuy.com/activity/wechat/share'
,
{
url
:
location
.
href
}).
then
(
res
=>
{
if
(
window
.
wx
)
{
window
.
wx
.
config
({
debug
:
false
,
appId
:
res
.
appId
,
timestamp
:
res
.
timestamp
,
nonceStr
:
res
.
nonceStr
,
signature
:
res
.
signature
,
jsApiList
:
jsApiList
});
}
})
});
}
if
(
qs
&&
qs
.
share_id
)
{
jsonp
(
location
.
protocol
+
'//m.yohobuy.com/activity/share'
,
{
shareId
:
qs
.
share_id
}).
then
(
res
=>
{
if
(
res
&&
res
.
code
===
200
&&
res
.
data
)
{
shareData
.
desc
=
res
.
data
.
content
||
res
.
data
.
title
;
shareData
.
imgUrl
=
res
.
data
.
pic
;
shareData
.
title
=
res
.
data
.
title
;
};
});
}
}
export
default
{
init
,
setShareInfo
(
data
)
{
Object
.
assign
(
shareData
,
data
);
window
.
setShareInfo
&&
window
.
setShareInfo
({
title
:
shareData
.
title
,
summary
:
shareData
.
desc
,
pic
:
shareData
.
imgUrl
,
url
:
shareData
.
link
||
location
.
href
});
}
}
...
...
Please
register
or
login
to post a comment