|
|
@ -3,33 +3,35 @@ import type { Router, RouteRecordRaw } from 'vue-router' |
|
|
|
import { usePermissionStoreWithOut } from '@/store/modules/permission' |
|
|
|
import { usePermissionStoreWithOut } from '@/store/modules/permission' |
|
|
|
|
|
|
|
|
|
|
|
import { PageEnum } from '@/enums/pageEnum' |
|
|
|
import { PageEnum } from '@/enums/pageEnum' |
|
|
|
|
|
|
|
import { useDictStoreWithOut } from '@/store/modules/dict' |
|
|
|
import { useUserStoreWithOut } from '@/store/modules/user' |
|
|
|
import { useUserStoreWithOut } from '@/store/modules/user' |
|
|
|
|
|
|
|
|
|
|
|
import { PAGE_NOT_FOUND_ROUTE } from '@/router/routes/basic' |
|
|
|
import { PAGE_NOT_FOUND_ROUTE } from '@/router/routes/basic' |
|
|
|
|
|
|
|
|
|
|
|
import { RootRoute } from '@/router/routes' |
|
|
|
// import { RootRoute } from '@/router/routes'
|
|
|
|
|
|
|
|
|
|
|
|
const LOGIN_PATH = PageEnum.BASE_LOGIN |
|
|
|
const LOGIN_PATH = PageEnum.BASE_LOGIN |
|
|
|
|
|
|
|
|
|
|
|
const ROOT_PATH = RootRoute.path |
|
|
|
// const ROOT_PATH = RootRoute.path
|
|
|
|
|
|
|
|
|
|
|
|
const whitePathList: PageEnum[] = [LOGIN_PATH] |
|
|
|
const whitePathList: PageEnum[] = [LOGIN_PATH] |
|
|
|
|
|
|
|
|
|
|
|
export function createPermissionGuard(router: Router) { |
|
|
|
export function createPermissionGuard(router: Router) { |
|
|
|
|
|
|
|
const dictStore = useDictStoreWithOut() |
|
|
|
const userStore = useUserStoreWithOut() |
|
|
|
const userStore = useUserStoreWithOut() |
|
|
|
const permissionStore = usePermissionStoreWithOut() |
|
|
|
const permissionStore = usePermissionStoreWithOut() |
|
|
|
router.beforeEach(async (to, from, next) => { |
|
|
|
router.beforeEach(async (to, from, next) => { |
|
|
|
if ( |
|
|
|
// if (
|
|
|
|
from.path === ROOT_PATH && |
|
|
|
// from.path === ROOT_PATH &&
|
|
|
|
to.path === PageEnum.BASE_HOME && |
|
|
|
// to.path === PageEnum.BASE_HOME &&
|
|
|
|
userStore.getUserInfo.homePath && |
|
|
|
// userStore.getUserInfo.homePath &&
|
|
|
|
userStore.getUserInfo.homePath !== PageEnum.BASE_HOME |
|
|
|
// userStore.getUserInfo.homePath !== PageEnum.BASE_HOME
|
|
|
|
) { |
|
|
|
// ) {
|
|
|
|
next(userStore.getUserInfo.homePath) |
|
|
|
// next(userStore.getUserInfo.homePath)
|
|
|
|
return |
|
|
|
// return
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
const token = userStore.getToken |
|
|
|
const token = userStore.getAccessToken |
|
|
|
|
|
|
|
|
|
|
|
// Whitelist can be directly entered
|
|
|
|
// Whitelist can be directly entered
|
|
|
|
if (whitePathList.includes(to.path as PageEnum)) { |
|
|
|
if (whitePathList.includes(to.path as PageEnum)) { |
|
|
@ -46,7 +48,8 @@ export function createPermissionGuard(router: Router) { |
|
|
|
next() |
|
|
|
next() |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
// token or user does not exist
|
|
|
|
|
|
|
|
|
|
|
|
// token does not exist
|
|
|
|
if (!token) { |
|
|
|
if (!token) { |
|
|
|
// You can access without permission. You need to set the routing meta.ignoreAuth to true
|
|
|
|
// You can access without permission. You need to set the routing meta.ignoreAuth to true
|
|
|
|
if (to.meta.ignoreAuth) { |
|
|
|
if (to.meta.ignoreAuth) { |
|
|
@ -70,15 +73,14 @@ export function createPermissionGuard(router: Router) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Jump to the 404 page after processing the login
|
|
|
|
// Jump to the 404 page after processing the login
|
|
|
|
if ( |
|
|
|
if (from.path === LOGIN_PATH && to.name === PAGE_NOT_FOUND_ROUTE.name && to.fullPath !== PageEnum.BASE_HOME) { |
|
|
|
from.path === LOGIN_PATH && |
|
|
|
next(PageEnum.BASE_HOME) |
|
|
|
to.name === PAGE_NOT_FOUND_ROUTE.name && |
|
|
|
|
|
|
|
to.fullPath !== (userStore.getUserInfo.homePath || PageEnum.BASE_HOME) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME) |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!dictStore.getIsSetDict) { |
|
|
|
|
|
|
|
await dictStore.setDictMap() |
|
|
|
|
|
|
|
} |
|
|
|
// get userinfo while last fetch time is empty
|
|
|
|
// get userinfo while last fetch time is empty
|
|
|
|
if (userStore.getLastUpdateTime === 0) { |
|
|
|
if (userStore.getLastUpdateTime === 0) { |
|
|
|
try { |
|
|
|
try { |
|
|
|