mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-07 23:31:08 +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 { preferences } from '@vben/preferences';
|
||||
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
|
||||
import { getAllMenusApi } from '#/api';
|
||||
import { BasicLayout, IFrameView } from '#/layouts';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { localMenuList } from './routes/local';
|
||||
|
||||
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
|
||||
const NotFoundComponent = () => import('#/views/_core/fallback/not-found.vue');
|
||||
|
||||
@@ -249,10 +245,7 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) {
|
||||
const backMenuList = await getAllMenusApi();
|
||||
// 转换为vben能用的路由
|
||||
const vbenMenuList = backMenuToVbenMenu(backMenuList);
|
||||
// 特别注意 这里要深拷贝
|
||||
const menuList = [...cloneDeep(localMenuList), ...vbenMenuList];
|
||||
// console.log('menuList', menuList);
|
||||
return menuList;
|
||||
return vbenMenuList;
|
||||
},
|
||||
// 可以指定没有权限跳转403页面
|
||||
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 {
|
||||
version,
|
||||
// vite inject-metadata 插件注入的全局变量
|
||||
} = __VBEN_ADMIN_METADATA__ || {};
|
||||
|
||||
/**
|
||||
* 该文件放非后台返回的路由 比如个人中心 等需要跳转显示的页面
|
||||
* 也可以直接在菜单管理配置
|
||||
*/
|
||||
const localRoutes: RouteRecordStringComponent[] = [
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
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: {
|
||||
order: -1,
|
||||
title: 'page.dashboard.title',
|
||||
// 不使用基础布局(仅在顶级生效)
|
||||
noBasicLayout: true,
|
||||
title: $t('page.dashboard.title'),
|
||||
},
|
||||
name: 'Dashboard',
|
||||
path: '/',
|
||||
@@ -44,24 +22,24 @@ export const localMenuList: RouteRecordStringComponent[] = [
|
||||
{
|
||||
name: 'Analytics',
|
||||
path: '/analytics',
|
||||
component: '/dashboard/analytics/index',
|
||||
component: () => import('#/views/dashboard/analytics/index.vue'),
|
||||
meta: {
|
||||
affixTab: true,
|
||||
title: 'page.dashboard.analytics',
|
||||
title: $t('page.dashboard.analytics'),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Workspace',
|
||||
path: '/workspace',
|
||||
component: '/dashboard/workspace/index',
|
||||
component: () => import('#/views/dashboard/workspace/index.vue'),
|
||||
meta: {
|
||||
title: 'page.dashboard.workspace',
|
||||
title: $t('page.dashboard.workspace'),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'VbenDocument',
|
||||
path: '/vben-admin/document',
|
||||
component: 'IFrameView',
|
||||
component: IFrameView,
|
||||
meta: {
|
||||
icon: 'lucide:book-open-text',
|
||||
iframeSrc: 'https://dapdap.top',
|
||||
@@ -72,7 +50,7 @@ export const localMenuList: RouteRecordStringComponent[] = [
|
||||
{
|
||||
name: 'V5UpdateLog',
|
||||
path: '/changelog',
|
||||
component: '/演示使用自行删除/changelog/index',
|
||||
component: () => import('#/views/演示使用自行删除/changelog/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:book-open-text',
|
||||
keepAlive: true,
|
||||
@@ -84,7 +62,7 @@ export const localMenuList: RouteRecordStringComponent[] = [
|
||||
],
|
||||
},
|
||||
{
|
||||
component: '/_core/about/index',
|
||||
component: () => import('#/views/_core/about/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:copyright',
|
||||
order: 9999,
|
||||
@@ -93,5 +71,6 @@ export const localMenuList: RouteRecordStringComponent[] = [
|
||||
name: '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