mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-01-01 09:55:28 +08:00
前端和后端源码,合并到一个git仓库中,方便用户下载,避免前后端不匹配的问题
This commit is contained in:
47
jeecgboot-vue3/src/router/guard/paramMenuGuard.ts
Normal file
47
jeecgboot-vue3/src/router/guard/paramMenuGuard.ts
Normal file
@ -0,0 +1,47 @@
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user