mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-04-12 05:13:14 +08:00
refactor(router): 重构路由菜单生成逻辑并新增模块化路由
移除本地菜单列表的依赖,改为完全从后端API获取菜单数据 新增 profile 和 dashboard 模块化路由文件 简化菜单生成逻辑,避免不必要的深拷贝操作
This commit is contained in:
@@ -10,14 +10,10 @@ import type { Menu } from '#/api';
|
|||||||
import { generateAccessible } from '@vben/access';
|
import { generateAccessible } from '@vben/access';
|
||||||
import { preferences } from '@vben/preferences';
|
import { preferences } from '@vben/preferences';
|
||||||
|
|
||||||
import { cloneDeep } from 'lodash-es';
|
|
||||||
|
|
||||||
import { getAllMenusApi } from '#/api';
|
import { getAllMenusApi } from '#/api';
|
||||||
import { BasicLayout, IFrameView } from '#/layouts';
|
import { BasicLayout, IFrameView } from '#/layouts';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
import { localMenuList } from './routes/local';
|
|
||||||
|
|
||||||
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
|
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
|
||||||
const NotFoundComponent = () => import('#/views/_core/fallback/not-found.vue');
|
const NotFoundComponent = () => import('#/views/_core/fallback/not-found.vue');
|
||||||
|
|
||||||
@@ -249,10 +245,7 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) {
|
|||||||
const backMenuList = await getAllMenusApi();
|
const backMenuList = await getAllMenusApi();
|
||||||
// 转换为vben能用的路由
|
// 转换为vben能用的路由
|
||||||
const vbenMenuList = backMenuToVbenMenu(backMenuList);
|
const vbenMenuList = backMenuToVbenMenu(backMenuList);
|
||||||
// 特别注意 这里要深拷贝
|
return vbenMenuList;
|
||||||
const menuList = [...cloneDeep(localMenuList), ...vbenMenuList];
|
|
||||||
// console.log('menuList', menuList);
|
|
||||||
return menuList;
|
|
||||||
},
|
},
|
||||||
// 可以指定没有权限跳转403页面
|
// 可以指定没有权限跳转403页面
|
||||||
forbiddenComponent,
|
forbiddenComponent,
|
||||||
|
|||||||
@@ -1,41 +1,19 @@
|
|||||||
import type { RouteRecordStringComponent } from '@vben/types';
|
import type { RouteRecordRaw } from 'vue-router';
|
||||||
|
|
||||||
import { $t } from '@vben/locales';
|
import { IFrameView } from '@vben/layouts';
|
||||||
|
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
version,
|
version,
|
||||||
// vite inject-metadata 插件注入的全局变量
|
// vite inject-metadata 插件注入的全局变量
|
||||||
} = __VBEN_ADMIN_METADATA__ || {};
|
} = __VBEN_ADMIN_METADATA__ || {};
|
||||||
|
|
||||||
/**
|
const routes: RouteRecordRaw[] = [
|
||||||
* 该文件放非后台返回的路由 比如个人中心 等需要跳转显示的页面
|
|
||||||
* 也可以直接在菜单管理配置
|
|
||||||
*/
|
|
||||||
const localRoutes: RouteRecordStringComponent[] = [
|
|
||||||
{
|
{
|
||||||
component: '/_core/profile/index',
|
|
||||||
meta: {
|
|
||||||
icon: 'mingcute:profile-line',
|
|
||||||
title: $t('ui.widgets.profile'),
|
|
||||||
hideInMenu: true,
|
|
||||||
requireHomeRedirect: true,
|
|
||||||
},
|
|
||||||
name: 'Profile',
|
|
||||||
path: '/profile',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 这里放本地路由
|
|
||||||
*/
|
|
||||||
export const localMenuList: RouteRecordStringComponent[] = [
|
|
||||||
{
|
|
||||||
component: 'BasicLayout',
|
|
||||||
meta: {
|
meta: {
|
||||||
order: -1,
|
order: -1,
|
||||||
title: 'page.dashboard.title',
|
title: $t('page.dashboard.title'),
|
||||||
// 不使用基础布局(仅在顶级生效)
|
|
||||||
noBasicLayout: true,
|
|
||||||
},
|
},
|
||||||
name: 'Dashboard',
|
name: 'Dashboard',
|
||||||
path: '/',
|
path: '/',
|
||||||
@@ -44,24 +22,24 @@ export const localMenuList: RouteRecordStringComponent[] = [
|
|||||||
{
|
{
|
||||||
name: 'Analytics',
|
name: 'Analytics',
|
||||||
path: '/analytics',
|
path: '/analytics',
|
||||||
component: '/dashboard/analytics/index',
|
component: () => import('#/views/dashboard/analytics/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
affixTab: true,
|
affixTab: true,
|
||||||
title: 'page.dashboard.analytics',
|
title: $t('page.dashboard.analytics'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Workspace',
|
name: 'Workspace',
|
||||||
path: '/workspace',
|
path: '/workspace',
|
||||||
component: '/dashboard/workspace/index',
|
component: () => import('#/views/dashboard/workspace/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: 'page.dashboard.workspace',
|
title: $t('page.dashboard.workspace'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'VbenDocument',
|
name: 'VbenDocument',
|
||||||
path: '/vben-admin/document',
|
path: '/vben-admin/document',
|
||||||
component: 'IFrameView',
|
component: IFrameView,
|
||||||
meta: {
|
meta: {
|
||||||
icon: 'lucide:book-open-text',
|
icon: 'lucide:book-open-text',
|
||||||
iframeSrc: 'https://dapdap.top',
|
iframeSrc: 'https://dapdap.top',
|
||||||
@@ -72,7 +50,7 @@ export const localMenuList: RouteRecordStringComponent[] = [
|
|||||||
{
|
{
|
||||||
name: 'V5UpdateLog',
|
name: 'V5UpdateLog',
|
||||||
path: '/changelog',
|
path: '/changelog',
|
||||||
component: '/演示使用自行删除/changelog/index',
|
component: () => import('#/views/演示使用自行删除/changelog/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
icon: 'lucide:book-open-text',
|
icon: 'lucide:book-open-text',
|
||||||
keepAlive: true,
|
keepAlive: true,
|
||||||
@@ -84,7 +62,7 @@ export const localMenuList: RouteRecordStringComponent[] = [
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: '/_core/about/index',
|
component: () => import('#/views/_core/about/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
icon: 'lucide:copyright',
|
icon: 'lucide:copyright',
|
||||||
order: 9999,
|
order: 9999,
|
||||||
@@ -93,5 +71,6 @@ export const localMenuList: RouteRecordStringComponent[] = [
|
|||||||
name: 'About',
|
name: 'About',
|
||||||
path: '/vben-admin/about',
|
path: '/vben-admin/about',
|
||||||
},
|
},
|
||||||
...localRoutes,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export default routes;
|
||||||
19
apps/web-antd/src/router/routes/modules/profile.ts
Normal file
19
apps/web-antd/src/router/routes/modules/profile.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import type { RouteRecordRaw } from 'vue-router';
|
||||||
|
|
||||||
|
import { $t } from '@vben/locales';
|
||||||
|
|
||||||
|
const routes: RouteRecordRaw[] = [
|
||||||
|
{
|
||||||
|
meta: {
|
||||||
|
order: -1,
|
||||||
|
title: $t('ui.widgets.profile'),
|
||||||
|
hideInMenu: true,
|
||||||
|
requireHomeRedirect: true,
|
||||||
|
},
|
||||||
|
name: 'Profile',
|
||||||
|
path: '/profile',
|
||||||
|
component: () => import('#/views/_core/profile/index.vue'),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export default routes;
|
||||||
Reference in New Issue
Block a user