【修改】增加登陆持久
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import router from './router/index'
|
||||
// import { getToken } from '@utils/auth'
|
||||
import store from './store'
|
||||
import vue from 'vue'
|
||||
const whiteList = ['/loginout','/login','/checkPage']
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
// 判断用户是否登录
|
||||
const hasToken =store.getters.userInfo
|
||||
// 如果已经登录了
|
||||
if (localStorage.getItem('cookie')) {
|
||||
// console.log( this.$cookies.get('JSESSIONID'),"getCookiegetCookiegetCookiegetCookiegetCookiegetCookie")
|
||||
vue.prototype.$cookies.set("JSESSIONID", localStorage.getItem('cookie'), {expires: "7D"});
|
||||
// 不能再去登录页面
|
||||
if (to.path === '/login' ||to.path === '/loginout' ||to.path === '/checkPage') {
|
||||
|
||||
next({ path: store.getters.pathUrl })
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}
|
||||
// 否则如果没登录
|
||||
else {
|
||||
// 去白名单路由页面
|
||||
if (whiteList.indexOf(to.path) !== -1) {
|
||||
next()
|
||||
}
|
||||
// 否则必须登录
|
||||
else {
|
||||
next('/login')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
router.afterEach(() => {})
|
||||
Reference in New Issue
Block a user