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.

160 lines
5.5 KiB

<script>
const jwx = require('jweixin-module')
export default {
onLaunch: function() {
// this.$nextTick(() => {
// })
},
onShow: function() {
let link = window.location.href;
uni.showModal({title:'进入'})
if (/code=/.test(link) || link.indexOf("code") > -1) {
let temp = decodeURIComponent((new RegExp('[?|&]' + 'code' + '=' + '([^&;]+?)(&|#|;|$)')
.exec(link) || [, ''])[1].replace(/\+/g, '%20')) || null
uni.showModal({title:'code:'+temp})
let tadk2_lifeData = uni.getStorageSync('tadk2_lifeData')
if (!tadk2_lifeData.vuex_token) {
uni.showModal({title:'无Token'})
this.$u.api.login({
code: temp
}).then(res => {
uni.showModal({title:'获取到Token'})
this.$u.vuex('vuex_token', res.token)
this.$u.api.user().then(res => {
uni.showModal({title:'获取到user'})
this.$u.vuex('vuex_user', res)
let url = location.href.split('#')[0]
let link = "https://vr.langye.net/h5tadk/";
this.$u.api.share({
url
}).then(res => {
uni.showModal({title:'获取到share'})
this.$u.vuex('vuex_share', true)
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: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
desc: '点击查看',
imgUrl: 'https://vr.langye.net/storage/files/170899758665dd3bd2c88c7.png', // 分享图标
success: () => {
console.log(
'updateAppMessageShareData-success'
)
},
});
jwx.updateTimelineShareData({
title: '阵地有声 理响通安', // 分享标题
desc: '点击查看',
link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: 'https://vr.langye.net/storage/files/170899758665dd3bd2c88c7.png', // 分享图标
success: () => {
console.log(
'updateTimelineShareData-success'
)
}
});
})
uni.showModal({title:'请求结束'})
this.$isResolve()
// console.log("123---to")
// uni.reLaunch({
// url: '/pages/index/index',
// });
})
})
})
} else {
uni.showModal({title:'有Token'})
this.$u.api.user().then(res => {
uni.showModal({title:'获取user'})
this.$u.vuex('vuex_user', res)
let url = location.href.split('#')[0]
let link = "https://vr.langye.net/h5tadk/";
this.$u.api.share({
url
}).then(res => {
this.$u.vuex('vuex_share', true)
uni.showModal({title:'获取share'})
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: '阵地有声 理响通安', // 分享标题
desc: '点击查看',
link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: 'https://vr.langye.net/storage/files/170899758665dd3bd2c88c7.png', // 分享图标
success: () => {
console.log(
'updateAppMessageShareData-success'
)
},
});
jwx.updateTimelineShareData({
title: '阵地有声 理响通安', // 分享标题
desc: '点击查看',
link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: 'https://vr.langye.net/storage/files/170899758665dd3bd2c88c7.png', // 分享图标
success: () => {
console.log(
'updateTimelineShareData-success'
)
}
});
})
uni.showModal({title:'请求结束'})
this.$isResolve()
// console.log("123---to")
// uni.reLaunch({
// url: '/pages/index/index',
// });
})
})
}
} else {
// let that = this
// setInterval(function(){
// console.log("asd-------------")
// that.$u.vuex('vuex_token', "8801|764nhDiiWEGvu0TPh0wyhl3Pfq01Oozhgu8X8Cvl")
// that.$u.vuex('vuex_share', true)
// },10000)
this.$u.api.getAppId().then(res => {
let redirect = encodeURIComponent(link.replace(/#\//, ""))
uni.showModal({title:'跳转到公众号链接'})
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`
})
}
},
onHide: function() {
console.log('App Hide')
}
}
</script>
<style lang="scss">
/*每个页面公共css */
@import "uview-ui/index.scss";
</style>