Commit f784074f by hank

小程序传token判断

parent 2228cfc7
......@@ -55,6 +55,10 @@ export default new Vuex.Store({
console.log(num);
state.ruweigonggao = num;
},
setToken (state, token) {
state.token = token
localStorage.setItem('token', JSON.stringify(res.token))
},
getAuth (state, auth) {
},
......@@ -82,7 +86,7 @@ export default new Vuex.Store({
return new Promise((resolve, reject) => {
axios.get('/weixin/info').then(res => {
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({
window.localStorage.setItem('token', res.data.data.accessToken)
state.token = res.data.data.accessToken
// location.href = res.data.data.url + '/video/2.html'
resolve(res.data.data.accessToken)
commit('getUserInfo')
})
})
......
......@@ -47,13 +47,14 @@ export default {
// store.commit('getRuweiInfo');
},
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')
} else {
store.dispatch('getAuth').then()
}
if(this.getQuery('code')) {
store.dispatch('getToken', this.getQuery('code')).then()
store.dispatch('getAuth')
}
var tar_userinfo = localStorage.getItem('tar_userinfo');
console.log(tar)
......
......@@ -98,7 +98,10 @@ router.beforeEach((to, from, next) => {
store.dispatch('getToken', getQuery('code')).then(res => {
next()
})
} else {
} else if (getQuery('token')) {
store.commit('setToken', getQuery('token'))
}
else {
next()
}
// return next()
......
......@@ -51,12 +51,12 @@ export default {
},
mounted() {
if(localStorage.getItem('token')) {
if (this.getQuery('token')) {
store.commit('setToken', this.getQuery('token'))
}
store.commit('getUserInfo')
} else {
store.dispatch('getAuth').then()
}
if(this.getQuery('code')) {
store.dispatch('getToken', this.getQuery('code')).then()
store.dispatch('getAuth')
}
var tar_userinfo = localStorage.getItem('tar_userinfo');
if (tar_userinfo) {
......
......@@ -72,11 +72,14 @@ router.beforeEach((to, from, next) => {
_hmt.push(['_trackPageview', '/#' + to.fullPath]);
}
}
if (getQuery('code') && !store.state.token) {
if(getQuery('code') && !store.state.token) {
store.dispatch('getToken', getQuery('code')).then(res => {
next()
})
} else {
next()
})
} else if (getQuery('token')) {
store.commit('setToken', getQuery('token'))
}
else {
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