mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-27 14:31:41 +08:00
refactor: refactoring menu generation
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { PermissionModeEnum } from '../enums/appEnum';
|
||||
import type { GlobEnvConfig } from '/@/types/config';
|
||||
|
||||
export const getGlobEnvConfig = (): GlobEnvConfig => {
|
||||
@@ -46,3 +47,14 @@ export const isProdMode = (): boolean => import.meta.env.PROD;
|
||||
* @example:
|
||||
*/
|
||||
export const isUseMock = (): boolean => import.meta.env.VITE_USE_MOCK === 'true';
|
||||
|
||||
/**
|
||||
* @description: 获取菜单生成方式
|
||||
* @param {type}
|
||||
* @returns:
|
||||
* @example:
|
||||
*/
|
||||
export const getRoleMode = (): PermissionModeEnum =>
|
||||
import.meta.env.VITE_GEN_MENU_MODE === PermissionModeEnum.ROLE
|
||||
? PermissionModeEnum.ROLE
|
||||
: PermissionModeEnum.BACK;
|
||||
|
4
src/utils/helper/dynamicImport.ts
Normal file
4
src/utils/helper/dynamicImport.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export default function (id: string) {
|
||||
const dynamicImportModule: any = id;
|
||||
return dynamicImportModule;
|
||||
}
|
@@ -6,6 +6,8 @@ import { tabStore } from '/@/store/modules/tab';
|
||||
import { createRouter, createWebHashHistory } from 'vue-router';
|
||||
import { toRaw } from 'vue';
|
||||
import { PAGE_LAYOUT_COMPONENT } from '/@/router/constant';
|
||||
// import { isDevMode } from '/@/utils/env';
|
||||
import dynamicImport from './dynamicImport';
|
||||
|
||||
let currentTo: RouteLocationNormalized | null = null;
|
||||
|
||||
@@ -45,12 +47,12 @@ export function genRouteModule(moduleList: AppRouteModule[]) {
|
||||
// TODO 错误写法
|
||||
function asyncImportRoute(routes: AppRouteRecordRaw[]) {
|
||||
routes.forEach((item) => {
|
||||
let { component } = item;
|
||||
const { component } = item;
|
||||
const { children } = item;
|
||||
if (component) {
|
||||
component = component.replace(/^\//, '');
|
||||
item.component = () => import(`/@/views/${component}`);
|
||||
item.component = dynamicImport(component);
|
||||
}
|
||||
|
||||
children && asyncImportRoute(children);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user