重新授权

This commit is contained in:
406803045 2019-06-14 10:19:41 +08:00
parent d682a549a5
commit 232a194aeb

View File

@ -5,59 +5,59 @@ import wechatAuth from './plugins/wechatAuth' // 微信登录插件
const qs = require('qs') const qs = require('qs')
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
store.dispatch('user/fedLogOut').then(() => { // store.dispatch('user/fedLogOut').then(() => {
}) // })
// const loginStatus = Number(store.getters.loginStatus) const loginStatus = Number(store.getters.loginStatus)
// document.title = getPageTitle(to.meta.title) document.title = getPageTitle(to.meta.title)
// if (loginStatus === 0) { if (loginStatus === 0) {
// // 微信未授权登录跳转到授权登录页面 // 微信未授权登录跳转到授权登录页面
// const url = window.location.href const url = window.location.href
// // 解决重复登录url添加重复的code与state问题 // 解决重复登录url添加重复的code与state问题
// const parseUrl = qs.parse(url.split('?')[1]) const parseUrl = qs.parse(url.split('?')[1])
// let loginUrl let loginUrl
// if (parseUrl.code && parseUrl.state) { if (parseUrl.code && parseUrl.state) {
// delete parseUrl.code delete parseUrl.code
// delete parseUrl.state delete parseUrl.state
// loginUrl = `${url.split('?')[0]}?${qs.stringify(parseUrl)}` loginUrl = `${url.split('?')[0]}?${qs.stringify(parseUrl)}`
// } else { } else {
// loginUrl = url loginUrl = url
// } }
// // alert(loginUrl) // alert(loginUrl)
// wechatAuth.redirect_uri = loginUrl wechatAuth.redirect_uri = loginUrl
// // 无论拒绝还是授权都设置成1 // 无论拒绝还是授权都设置成1
// store.dispatch('user/setLoginStatus', 1) store.dispatch('user/setLoginStatus', 1)
// window.location.href = wechatAuth.authUrl window.location.href = wechatAuth.authUrl
// } else if (loginStatus === 1) { } else if (loginStatus === 1) {
// // 微信已经授权回调获取code // 微信已经授权回调获取code
// try { try {
// wechatAuth.returnFromWechat(to.fullPath) wechatAuth.returnFromWechat(to.fullPath)
// } catch (err) { } catch (err) {
// store.dispatch('user/setLoginStatus', 0) store.dispatch('user/setLoginStatus', 0)
// location.reload() location.reload()
// // next() // next()
// } }
// // 同意授权 to.fullPath 携带code参数拒绝授权没有code参数 // 同意授权 to.fullPath 携带code参数拒绝授权没有code参数
// // alert(to.fullPath) // alert(to.fullPath)
// // 重新赋值不然获取不到code // 重新赋值不然获取不到code
// const code = wechatAuth.code const code = wechatAuth.code
// // alert(code) // alert(code)
// if (code) { if (code) {
// store store
// .dispatch('user/loginWechatAuth', code) .dispatch('user/loginWechatAuth', code)
// .then(res => { .then(res => {
// store.dispatch('user/setLoginStatus', 2) store.dispatch('user/setLoginStatus', 2)
// next() next()
// }) })
// .catch(() => { .catch(() => {
// store.dispatch('user/setLoginStatus', 0) store.dispatch('user/setLoginStatus', 0)
// location.reload() location.reload()
// }) })
// } else { } else {
// store.dispatch('user/setLoginStatus', 0) store.dispatch('user/setLoginStatus', 0)
// location.reload() location.reload()
// } }
// } else { } else {
// // alert(to.fullPath) // alert(to.fullPath)
// next() next()
// } }
}) })