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