Commit f784074f by hank

小程序传token判断

parent 2228cfc7
...@@ -55,6 +55,10 @@ export default new Vuex.Store({ ...@@ -55,6 +55,10 @@ export default new Vuex.Store({
console.log(num); console.log(num);
state.ruweigonggao = num; state.ruweigonggao = num;
}, },
setToken (state, token) {
state.token = token
localStorage.setItem('token', JSON.stringify(res.token))
},
getAuth (state, auth) { getAuth (state, auth) {
}, },
...@@ -82,7 +86,7 @@ export default new Vuex.Store({ ...@@ -82,7 +86,7 @@ export default new Vuex.Store({
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get('/weixin/info').then(res => { axios.get('/weixin/info').then(res => {
window.localStorage.setItem('callbackurl', location.href) window.localStorage.setItem('callbackurl', location.href)
location.href = res.data.data.url + '/video/2.html' location.href = res.data.data.url
}) })
}) })
}, },
...@@ -97,6 +101,7 @@ export default new Vuex.Store({ ...@@ -97,6 +101,7 @@ export default new Vuex.Store({
window.localStorage.setItem('token', res.data.data.accessToken) window.localStorage.setItem('token', res.data.data.accessToken)
state.token = res.data.data.accessToken state.token = res.data.data.accessToken
// location.href = res.data.data.url + '/video/2.html' // location.href = res.data.data.url + '/video/2.html'
resolve(res.data.data.accessToken)
commit('getUserInfo') commit('getUserInfo')
}) })
}) })
......
...@@ -47,13 +47,14 @@ export default { ...@@ -47,13 +47,14 @@ export default {
// store.commit('getRuweiInfo'); // store.commit('getRuweiInfo');
}, },
mounted() { mounted() {
if(localStorage.getItem('token')) { if(localStorage.getItem('token') || this.getQuery('token')) {
if (this.getQuery('token')) {
store.commit('setToken', this.getQuery('token'))
}
store.commit('getUserInfo') store.commit('getUserInfo')
} else { } else {
store.dispatch('getAuth').then() store.dispatch('getAuth')
}
if(this.getQuery('code')) {
store.dispatch('getToken', this.getQuery('code')).then()
} }
var tar_userinfo = localStorage.getItem('tar_userinfo'); var tar_userinfo = localStorage.getItem('tar_userinfo');
console.log(tar) console.log(tar)
......
...@@ -98,7 +98,10 @@ router.beforeEach((to, from, next) => { ...@@ -98,7 +98,10 @@ router.beforeEach((to, from, next) => {
store.dispatch('getToken', getQuery('code')).then(res => { store.dispatch('getToken', getQuery('code')).then(res => {
next() next()
}) })
} else { } else if (getQuery('token')) {
store.commit('setToken', getQuery('token'))
}
else {
next() next()
} }
// return next() // return next()
......
...@@ -51,12 +51,12 @@ export default { ...@@ -51,12 +51,12 @@ export default {
}, },
mounted() { mounted() {
if(localStorage.getItem('token')) { if(localStorage.getItem('token')) {
if (this.getQuery('token')) {
store.commit('setToken', this.getQuery('token'))
}
store.commit('getUserInfo') store.commit('getUserInfo')
} else { } else {
store.dispatch('getAuth').then() store.dispatch('getAuth')
}
if(this.getQuery('code')) {
store.dispatch('getToken', this.getQuery('code')).then()
} }
var tar_userinfo = localStorage.getItem('tar_userinfo'); var tar_userinfo = localStorage.getItem('tar_userinfo');
if (tar_userinfo) { if (tar_userinfo) {
......
...@@ -72,11 +72,14 @@ router.beforeEach((to, from, next) => { ...@@ -72,11 +72,14 @@ router.beforeEach((to, from, next) => {
_hmt.push(['_trackPageview', '/#' + to.fullPath]); _hmt.push(['_trackPageview', '/#' + to.fullPath]);
} }
} }
if (getQuery('code') && !store.state.token) { if(getQuery('code') && !store.state.token) {
store.dispatch('getToken', getQuery('code')).then(res => { store.dispatch('getToken', getQuery('code')).then(res => {
next() next()
}) })
} else { } else if (getQuery('token')) {
store.commit('setToken', getQuery('token'))
}
else {
next() next()
} }
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment