mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-24 10:33:50 +08:00
fix: ensure permissionMode exists close #409
This commit is contained in:
parent
fedd9caefb
commit
8fb03961f5
@ -20,7 +20,7 @@ const setting: ProjectConfig = {
|
||||
settingButtonPosition: SettingButtonPositionEnum.AUTO,
|
||||
|
||||
// Permission mode
|
||||
permissionMode: PermissionModeEnum.ROLE,
|
||||
permissionMode: PermissionModeEnum.BACK,
|
||||
|
||||
// Permission-related cache is stored in sessionStorage or localStorage
|
||||
permissionCacheType: CacheTypeEnum.LOCAL,
|
||||
|
@ -1,28 +1,30 @@
|
||||
import type { AppRouteRecordRaw, Menu } from '/@/router/types';
|
||||
import store from '/@/store/index';
|
||||
import { hotModuleUnregisterModule } from '/@/utils/helper/vuexHelper';
|
||||
|
||||
import store from '/@/store';
|
||||
import { toRaw } from 'vue';
|
||||
import { VuexModule, Mutation, Module, getModule, Action } from 'vuex-module-decorators';
|
||||
|
||||
import { hotModuleUnregisterModule } from '/@/utils/helper/vuexHelper';
|
||||
|
||||
import { PermissionModeEnum } from '/@/enums/appEnum';
|
||||
|
||||
import { appStore } from '/@/store/modules/app';
|
||||
import { userStore } from '/@/store/modules/user';
|
||||
import projectSetting from '/@/settings/projectSetting';
|
||||
|
||||
import { asyncRoutes } from '/@/router/routes';
|
||||
import { filter } from '/@/utils/helper/treeHelper';
|
||||
import { toRaw } from 'vue';
|
||||
import { getMenuListById } from '/@/api/sys/menu';
|
||||
import { getPermCodeByUserId } from '/@/api/sys/user';
|
||||
|
||||
import { ERROR_LOG_ROUTE, PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
|
||||
import { transformObjToRoute, flatMultiLevelRoutes } from '/@/router/helper/routeHelper';
|
||||
import { transformRouteToMenu } from '/@/router/helper/menuHelper';
|
||||
|
||||
import { filter } from '/@/utils/helper/treeHelper';
|
||||
|
||||
import { getMenuListById } from '/@/api/sys/menu';
|
||||
import { getPermCodeByUserId } from '/@/api/sys/user';
|
||||
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
import { useI18n } from '/@/hooks/web/useI18n';
|
||||
import { ERROR_LOG_ROUTE, PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
|
||||
|
||||
const { createMessage } = useMessage();
|
||||
const NAME = 'app-permission';
|
||||
hotModuleUnregisterModule(NAME);
|
||||
@Module({ dynamic: true, namespaced: true, store, name: NAME })
|
||||
@ -94,13 +96,11 @@ class Permission extends VuexModule {
|
||||
const { t } = useI18n();
|
||||
let routes: AppRouteRecordRaw[] = [];
|
||||
const roleList = toRaw(userStore.getRoleListState);
|
||||
|
||||
const { permissionMode = PermissionModeEnum.ROLE } = appStore.getProjectConfig;
|
||||
|
||||
const { permissionMode = projectSetting.permissionMode } = appStore.getProjectConfig;
|
||||
// role permissions
|
||||
if (permissionMode === PermissionModeEnum.ROLE) {
|
||||
const routeFilter = (route) => {
|
||||
const { meta } = route as AppRouteRecordRaw;
|
||||
const routeFilter = (route: AppRouteRecordRaw) => {
|
||||
const { meta } = route;
|
||||
const { roles } = meta || {};
|
||||
if (!roles) return true;
|
||||
return roleList.some((role) => roles.includes(role));
|
||||
@ -111,6 +111,8 @@ class Permission extends VuexModule {
|
||||
routes = flatMultiLevelRoutes(routes);
|
||||
// If you are sure that you do not need to do background dynamic permissions, please comment the entire judgment below
|
||||
} else if (permissionMode === PermissionModeEnum.BACK) {
|
||||
const { createMessage } = useMessage();
|
||||
|
||||
createMessage.loading({
|
||||
content: t('sys.app.menuLoading'),
|
||||
duration: 1,
|
||||
|
@ -1,8 +1,8 @@
|
||||
import store from '/@/store';
|
||||
|
||||
export function hotModuleUnregisterModule(name: string) {
|
||||
if (!name) return;
|
||||
if ((store.state as any)[name]) {
|
||||
if (!name || !import.meta.hot) return;
|
||||
if ((store.state as Recordable)[name]) {
|
||||
store.unregisterModule(name);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user