You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
2 years ago
|
import type { Router } from 'vue-router'
|
||
|
import { configureDynamicParamsMenu } from '../helper/menuHelper'
|
||
|
import { Menu } from '../types'
|
||
|
import { PermissionModeEnum } from '@/enums/appEnum'
|
||
|
import { useAppStoreWithOut } from '@/store/modules/app'
|
||
|
|
||
|
import { usePermissionStoreWithOut } from '@/store/modules/permission'
|
||
|
|
||
|
export function createParamMenuGuard(router: Router) {
|
||
|
const permissionStore = usePermissionStoreWithOut()
|
||
|
router.beforeEach(async (to, _, next) => {
|
||
|
// filter no name route
|
||
|
if (!to.name) {
|
||
|
next()
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// menu has been built.
|
||
|
if (!permissionStore.getIsDynamicAddedRoute) {
|
||
|
next()
|
||
|
return
|
||
|
}
|
||
|
|
||
|
let menus: Menu[] = []
|
||
|
if (isBackMode()) {
|
||
|
menus = permissionStore.getBackMenuList
|
||
|
} else if (isRouteMappingMode()) {
|
||
|
menus = permissionStore.getFrontMenuList
|
||
|
}
|
||
|
menus.forEach((item) => configureDynamicParamsMenu(item, to.params))
|
||
|
|
||
|
next()
|
||
|
})
|
||
|
}
|
||
|
|
||
|
const getPermissionMode = () => {
|
||
|
const appStore = useAppStoreWithOut()
|
||
|
return appStore.getProjectConfig.permissionMode
|
||
|
}
|
||
|
|
||
|
const isBackMode = () => {
|
||
|
return getPermissionMode() === PermissionModeEnum.BACK
|
||
|
}
|
||
|
|
||
|
const isRouteMappingMode = () => {
|
||
|
return getPermissionMode() === PermissionModeEnum.ROUTE_MAPPING
|
||
|
}
|