| | |
| | | import { wxAuthorize, refreshToken } from '@/api' |
| | | export default { |
| | | onLaunch: function () { |
| | | var that = this |
| | | if (!that.$store.state.openid) { |
| | | let url = window.location.href |
| | | let code = '' |
| | | let source = '' |
| | | if (url.indexOf('code=') !== -1) { |
| | | const query = url.split('?') |
| | | console.log('app-app', url) |
| | | for (const q of query) { |
| | | if (q.indexOf('code=') !== -1) { |
| | | code = q.substring(q.indexOf('code=') + 5, q.length) |
| | | } |
| | | if (q.indexOf('source=') !== -1) { |
| | | source = q.substring(q.indexOf('source=') + 7,q.indexOf('source=') + 8 ) |
| | | } |
| | | } |
| | | wxAuthorize({ |
| | | code: code, |
| | | source |
| | | }).then(res => { |
| | | console.log('app_ress', res) |
| | | if (res.code === 200) { |
| | | that.$store.commit('setOpenId', res.data.openid) |
| | | if (res.data.member) { |
| | | that.$store.commit('setMember', res.data.member) |
| | | } |
| | | } |
| | | }) |
| | | } else { |
| | | // const appID = 'wx4d7c10bdec51942b' |
| | | // let uri = encodeURIComponent(url) |
| | | // let authURL = |
| | | // `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appID}&redirect_uri=${uri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect` |
| | | // window.location.href = authURL |
| | | } |
| | | } |
| | | // 刷新token |
| | | const token = uni.getStorageSync('token') |
| | | // if (token) { |
| | | // refreshToken().then(res => { |
| | | // if(res.code && res.code === 200){ |
| | | // this.$store.commit('setToken', res.data) |
| | | // } |
| | | // }) |
| | | // } |
| | | |
| | | }, |
| | | onShow: function () { |
| | | console.log('App Show') |