parent
ad9235ba24
commit
61067a7b25
14 changed files with 67 additions and 40 deletions
@ -1,27 +1,35 @@ |
||||
import router from "./index"; |
||||
import Setting from "@/setting"; |
||||
import util from "@/libs/util"; |
||||
import Setting from '@/setting' |
||||
import Util from '@/libs/util' |
||||
|
||||
const whiteList = Setting.whiteList // 白名单
|
||||
router.beforeEach((to, from, next) => { |
||||
const officalTag = from.query.q && !to.query.q ? ((to.fullPath.includes('?') ? '&' : '?') + `q=${Date.now()}`) : '' // 安财赛事专用标识
|
||||
document.title = to.path === '/screenShow' || to.path === '/screenShowPro' ? '安徽省绿色食品全产业链数据可视化看板' : Setting.titleSuffix + '-' + to.meta.title |
||||
const role = util.session.get(Setting.tokenKey); |
||||
if (!role && !whiteList.includes(to.path)) { |
||||
const localToken = Util.local.get(Setting.tokenKey) |
||||
const sessionToken = Util.session.get(Setting.tokenKey) |
||||
|
||||
if (!localToken && sessionToken && !whiteList.includes(to.path)) { |
||||
// sessionStorage里有token,localStorage里没有,则直接退出登录
|
||||
Util.session.remove(Setting.tokenKey) |
||||
next('/login' + officalTag) |
||||
} else if (role && to.path === '/login') { |
||||
next('/station' + officalTag) |
||||
} else { |
||||
if (to.query.q || !from.query.q) { |
||||
next() |
||||
} else if (from.query.q) { |
||||
next({ |
||||
path: to.path, |
||||
query: { |
||||
...to.query, |
||||
q: Date.now() |
||||
} |
||||
}) |
||||
if (!sessionToken && !whiteList.includes(to.path)) { |
||||
next('/login' + officalTag) |
||||
} else if (sessionToken && to.path === '/login') { |
||||
next('/station' + officalTag) |
||||
} else { |
||||
if (to.query.q || !from.query.q) { |
||||
next() |
||||
} else if (from.query.q) { |
||||
next({ |
||||
path: to.path, |
||||
query: { |
||||
...to.query, |
||||
q: Date.now() |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
}) |
Loading…
Reference in new issue