【修改】增加登陆持久

This commit is contained in:
zhoulingpo
2023-05-18 16:17:02 +08:00
parent 5bf4bae1bf
commit 1011adf46c
2 changed files with 36 additions and 1 deletions
+35
View File
@@ -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(() => {})