fix: 修复路由整合的问题
This commit is contained in:
parent
fab65e2dd5
commit
58d216a95b
|
@ -14,10 +14,9 @@ export default [
|
|||
{
|
||||
path: '/',
|
||||
redirect: '/workspace',
|
||||
breadcrumb: '工作空间',
|
||||
},
|
||||
{
|
||||
name: 'workspace',
|
||||
name: '工作空间',
|
||||
path: '/workspace',
|
||||
routes: [
|
||||
{
|
||||
|
@ -41,6 +40,7 @@ export default [
|
|||
},
|
||||
{
|
||||
path: '/account',
|
||||
name: '用户中心',
|
||||
routes: [
|
||||
{
|
||||
name: '用户中心',
|
||||
|
@ -70,21 +70,21 @@ export default [
|
|||
],
|
||||
},
|
||||
{
|
||||
name: 'developmentEnvironment',
|
||||
name: '开发环境',
|
||||
path: '/developmentEnvironment',
|
||||
routes: [
|
||||
{
|
||||
name: '开发环境',
|
||||
path: '',
|
||||
component: './DevelopmentEnvironment/Editor',
|
||||
component: './DevelopmentEnvironment/List',
|
||||
},
|
||||
{
|
||||
name: '创建编辑器',
|
||||
name: '创建开发环境',
|
||||
path: 'create',
|
||||
component: './DevelopmentEnvironment/Create',
|
||||
},
|
||||
{
|
||||
name: '编辑器',
|
||||
name: '开发环境详情',
|
||||
path: 'editor',
|
||||
component: './DevelopmentEnvironment/Editor',
|
||||
},
|
||||
|
@ -306,47 +306,47 @@ export default [
|
|||
},
|
||||
{
|
||||
name: '用户管理',
|
||||
path: '/system/user',
|
||||
path: 'user',
|
||||
component: './System/User',
|
||||
},
|
||||
{
|
||||
name: '角色管理',
|
||||
path: '/system/role',
|
||||
path: 'role',
|
||||
component: './System/Role',
|
||||
},
|
||||
{
|
||||
name: '定时任务',
|
||||
path: '/system/job',
|
||||
path: 'job',
|
||||
component: './Monitor/Job',
|
||||
},
|
||||
{
|
||||
name: '菜单管理',
|
||||
path: '/system/menu',
|
||||
path: 'menu',
|
||||
component: './System/Menu',
|
||||
},
|
||||
{
|
||||
name: '部门管理',
|
||||
path: '/system/dept',
|
||||
path: 'dept',
|
||||
component: './System/Dept',
|
||||
},
|
||||
{
|
||||
name: '岗位管理',
|
||||
path: '/system/post',
|
||||
path: 'post',
|
||||
component: './System/Post',
|
||||
},
|
||||
{
|
||||
name: '字典管理',
|
||||
path: '/system/dict',
|
||||
path: 'dict',
|
||||
component: './System/Dict',
|
||||
},
|
||||
{
|
||||
name: '字典数据',
|
||||
path: '/system/dict-data/index/:id',
|
||||
path: 'dict-data/index/:id',
|
||||
component: './System/DictData',
|
||||
},
|
||||
{
|
||||
name: '分配用户',
|
||||
path: '/system/role-auth/user/:id',
|
||||
path: 'role-auth/user/:id',
|
||||
component: './System/Role/authUser',
|
||||
},
|
||||
],
|
||||
|
|
|
@ -12,30 +12,35 @@ export function setRemoteMenu(data: any) {
|
|||
remoteMenu = data;
|
||||
}
|
||||
|
||||
// 根据后台配置的菜单路径获取本地路由
|
||||
const getLocalRoute = (route: any, menuItem: any) => {
|
||||
for (const routeChild of route.routes) {
|
||||
if (routeChild.path === menuItem.path) {
|
||||
return routeChild;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
function patchRouteItems(route: any, menu: any, parentPath: string) {
|
||||
for (const menuItem of menu) {
|
||||
if (menuItem.component === 'Layout' || menuItem.component === 'ParentView') {
|
||||
if (menuItem.routes) {
|
||||
let hasItem = false;
|
||||
let newItem = null;
|
||||
for (const routeChild of route.routes) {
|
||||
if (routeChild.path === menuItem.path) {
|
||||
hasItem = true;
|
||||
newItem = routeChild;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasItem) {
|
||||
let newItem = getLocalRoute(route, menuItem);
|
||||
if (!newItem) {
|
||||
newItem = {
|
||||
path: menuItem.path,
|
||||
routes: [],
|
||||
children: [],
|
||||
};
|
||||
route.children = route.routes;
|
||||
route.routes.push(newItem);
|
||||
}
|
||||
patchRouteItems(newItem, menuItem.routes, parentPath + menuItem.path + '/');
|
||||
}
|
||||
} else {
|
||||
if (getLocalRoute(route, menuItem)) {
|
||||
return;
|
||||
}
|
||||
const names: string[] = menuItem.component.split('/');
|
||||
let path = '';
|
||||
names.forEach((name) => {
|
||||
|
@ -53,17 +58,13 @@ function patchRouteItems(route: any, menu: any, parentPath: string) {
|
|||
}
|
||||
if (route.routes === undefined) {
|
||||
route.routes = [];
|
||||
route.children = route.routes;
|
||||
}
|
||||
if (route.children === undefined) {
|
||||
route.children = [];
|
||||
}
|
||||
|
||||
const newRoute = {
|
||||
element: React.createElement(lazy(() => import('@/pages/' + path))),
|
||||
path: parentPath + menuItem.path,
|
||||
};
|
||||
// console.log(newRoute);
|
||||
|
||||
route.children.push(newRoute);
|
||||
route.routes.push(newRoute);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue