重构
This commit is contained in:
@ -10,11 +10,16 @@ import { isRelogin } from '@/utils/request'
|
||||
NProgress.configure({ showSpinner: false })
|
||||
|
||||
const whiteList = ['/login', '/register']
|
||||
const GLOBAL_SITE_STORAGE_KEY = 'global_site_id'
|
||||
|
||||
const isWhiteList = (path) => {
|
||||
return whiteList.some(pattern => isPathMatch(pattern, path))
|
||||
}
|
||||
|
||||
const shouldAppendSiteId = (path) => {
|
||||
return !['/login', '/register', '/404', '/401'].includes(path) && !path.startsWith('/redirect')
|
||||
}
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
NProgress.start()
|
||||
if (getToken()) {
|
||||
@ -26,6 +31,24 @@ router.beforeEach((to, from, next) => {
|
||||
} else if (isWhiteList(to.path)) {
|
||||
next()
|
||||
} else {
|
||||
const routeSiteId = to.query?.siteId
|
||||
if (routeSiteId) {
|
||||
localStorage.setItem(GLOBAL_SITE_STORAGE_KEY, routeSiteId)
|
||||
} else {
|
||||
const globalSiteId = localStorage.getItem(GLOBAL_SITE_STORAGE_KEY)
|
||||
if (globalSiteId && shouldAppendSiteId(to.path)) {
|
||||
next({
|
||||
path: to.path,
|
||||
query: {
|
||||
...to.query,
|
||||
siteId: globalSiteId
|
||||
},
|
||||
hash: to.hash,
|
||||
replace: true
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
if (store.getters.roles.length === 0) {
|
||||
isRelogin.show = true
|
||||
// 判断当前用户是否已拉取完user_info信息
|
||||
|
||||
Reference in New Issue
Block a user