You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
4.7 KiB
117 lines
4.7 KiB
<script>
|
|
const jwx = require('jweixin-module')
|
|
export default {
|
|
onLaunch: function() {
|
|
this.$nextTick(() => {
|
|
let link = window.location.href;
|
|
if (/code=/.test(link) || link.indexOf("code") > -1) {
|
|
let temp = decodeURIComponent((new RegExp('[?|&]' + 'code' + '=' + '([^&;]+?)(&|#|;|$)')
|
|
.exec(link) || [, ''])[1].replace(/\+/g, '%20')) || null
|
|
let lifeData = uni.getStorageSync('lifeData')
|
|
if (!lifeData.vuex_token) {
|
|
this.$u.api.login({
|
|
code: temp
|
|
}).then(res => {
|
|
this.$u.vuex('vuex_token', res.token)
|
|
|
|
this.$u.api.user().then(res => {
|
|
this.$u.vuex('vuex_user', res)
|
|
|
|
|
|
let url = location.href.split('#')[0]
|
|
this.$u.api.share({
|
|
url
|
|
}).then(res => {
|
|
jwx.config({
|
|
debug: false, // 开启调试模式,调用的所有 api 的返回值会在客户端 alert 出来,若要查看传入的参数,可以在 pc 端打开,参数信息会通过 log 打出,仅在 pc 端时才会打印。
|
|
appId: res.appId,
|
|
jsApiList: res.jsApiList,
|
|
nonceStr: res.nonceStr,
|
|
signature: res.signature,
|
|
timestamp: res.timestamp,
|
|
})
|
|
jwx.ready(() => {
|
|
jwx.updateAppMessageShareData({
|
|
title: '我是党史记录人——红色少年行 未成年人研学', // 分享标题
|
|
link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
|
imgUrl: 'https://vr.langye.net/res/share-dangshi-img.jpg', // 分享图标
|
|
success: () => {
|
|
console.log('updateAppMessageShareData-success')
|
|
},
|
|
|
|
});
|
|
jwx.updateTimelineShareData({
|
|
title: '我是党史记录人——红色少年行 未成年人研学', // 分享标题
|
|
link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
|
imgUrl: 'https://vr.langye.net/res/share-dangshi-img.jpg', // 分享图标
|
|
success: () => {
|
|
console.log('updateTimelineShareData-success')
|
|
}
|
|
});
|
|
})
|
|
})
|
|
})
|
|
})
|
|
} else {
|
|
this.$u.api.user().then(res => {
|
|
this.$u.vuex('vuex_user', res)
|
|
|
|
|
|
let url ="https://vr.langye.net/h5hssnx/"; //location.href.split('#')[0]
|
|
this.$u.api.share({
|
|
url
|
|
}).then(res => {
|
|
jwx.config({
|
|
debug: false, // 开启调试模式,调用的所有 api 的返回值会在客户端 alert 出来,若要查看传入的参数,可以在 pc 端打开,参数信息会通过 log 打出,仅在 pc 端时才会打印。
|
|
appId: res.appId,
|
|
jsApiList: res.jsApiList,
|
|
nonceStr: res.nonceStr,
|
|
signature: res.signature,
|
|
timestamp: res.timestamp,
|
|
})
|
|
jwx.ready(() => {
|
|
jwx.updateAppMessageShareData({
|
|
title: '我是党史记录人——红色少年行 未成年人研学', // 分享标题
|
|
link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
|
imgUrl: 'https://vr.langye.net/res/share-dangshi-img.jpg', // 分享图标
|
|
success: () => {
|
|
console.log('updateAppMessageShareData-success')
|
|
},
|
|
|
|
});
|
|
jwx.updateTimelineShareData({
|
|
title: '我是党史记录人——红色少年行 未成年人研学', // 分享标题
|
|
link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
|
imgUrl: 'https://vr.langye.net/res/share-dangshi-img.jpg', // 分享图标
|
|
success: () => {
|
|
console.log('updateTimelineShareData-success')
|
|
}
|
|
});
|
|
})
|
|
})
|
|
})
|
|
}
|
|
} else {
|
|
this.$u.api.getAppId().then(res => {
|
|
let redirect = encodeURIComponent(link.replace(/#\//, ""))
|
|
window.location.href =
|
|
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${res.appid}&redirect_uri=${redirect}&response_type=code&scope=snsapi_base#wechat_redirect`
|
|
})
|
|
}
|
|
})
|
|
|
|
},
|
|
onShow: function() {
|
|
console.log('App Show')
|
|
},
|
|
onHide: function() {
|
|
console.log('App Hide')
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
/*每个页面公共css */
|
|
@import "uview-ui/index.scss";
|
|
</style>
|