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.
42 lines
1.3 KiB
42 lines
1.3 KiB
<script>
|
|
export default {
|
|
onLaunch: function() {
|
|
console.log('App Launch')
|
|
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 || !lifeData.vuex_userId) {
|
|
this.$u.api.login({
|
|
code: temp
|
|
}).then(res => {
|
|
uni.setStorageSync('lifeData', {
|
|
vuex_token: res.token,
|
|
vuex_userId: res.user_id
|
|
})
|
|
this.$u.vuex('vuex_token', res.token)
|
|
this.$u.vuex('vuex_userId', res.user_id)
|
|
})
|
|
}
|
|
} 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> |