修复知识库的标签管理和分类管理
This commit is contained in:
@@ -42,16 +42,30 @@ export function convertMenusToRoutes(menus) {
|
||||
// 子菜单添加到父菜单的 children 中
|
||||
const parentRoute = menuMap[menu.parentId];
|
||||
if (parentRoute) {
|
||||
// 修正子路由路径:相对于父路由的路径
|
||||
const parentPath = parentRoute.path; // 例如 "system"
|
||||
const childFullPath = currentRoute.path; // 例如 "system/users"
|
||||
// 修正子路由路径:使用原始菜单路径来准确匹配
|
||||
// 使用原始路径(menuPath)来准确计算相对路径
|
||||
const parentOriginalPath = parentRoute.meta?.menuPath || parentRoute.path;
|
||||
const childOriginalPath = currentRoute.meta?.menuPath || currentRoute.path;
|
||||
|
||||
// 确保路径格式一致(去掉前导斜杠)
|
||||
const parentPath = parentOriginalPath.startsWith('/') ? parentOriginalPath.substring(1) : parentOriginalPath;
|
||||
const childFullPath = childOriginalPath.startsWith('/') ? childOriginalPath.substring(1) : childOriginalPath;
|
||||
|
||||
// 如果子路径以父路径开头,则只保留剩余部分
|
||||
if (childFullPath.startsWith(parentPath + '/')) {
|
||||
currentRoute.path = childFullPath.substring(parentPath.length + 1); // "users"
|
||||
} else if (childFullPath.startsWith('/')) {
|
||||
// 如果仍然有前导斜杠,去掉它
|
||||
currentRoute.path = childFullPath.substring(1);
|
||||
currentRoute.path = childFullPath.substring(parentPath.length + 1); // "users" 或 "knowledge/category"
|
||||
} else {
|
||||
// 如果子路径不以父路径开头,尝试直接使用子路径的最后一部分
|
||||
// 这处理了路径不连续的情况
|
||||
const pathParts = childFullPath.split('/');
|
||||
const parentPathParts = parentPath.split('/');
|
||||
// 找到子路径相对于父路径的部分
|
||||
if (pathParts.length > parentPathParts.length) {
|
||||
currentRoute.path = pathParts.slice(parentPathParts.length).join('/');
|
||||
} else {
|
||||
// 如果无法确定相对路径,使用最后一个路径段
|
||||
currentRoute.path = pathParts[pathParts.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
if (!parentRoute.children) {
|
||||
@@ -64,6 +78,29 @@ export function convertMenusToRoutes(menus) {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 2.5. 为有子路由但没有 component 的父路由自动添加默认组件
|
||||
const addDefaultComponent = (routeList) => {
|
||||
routeList.forEach(route => {
|
||||
// 如果路由有子路由但没有组件,尝试添加默认组件
|
||||
if (route.children && route.children.length > 0 && !route.component) {
|
||||
// 使用原始菜单路径(menuPath)来推断组件路径,而不是修正后的路径
|
||||
const originalPath = route.meta?.menuPath || route.path;
|
||||
// 确保路径以 / 开头
|
||||
const normalizedPath = originalPath.startsWith('/') ? originalPath : `/${originalPath}`;
|
||||
const defaultComponentPath = `${normalizedPath}/index.vue`;
|
||||
const defaultComponent = createComponentLoader(defaultComponentPath);
|
||||
if (defaultComponent) {
|
||||
route.component = defaultComponent;
|
||||
}
|
||||
}
|
||||
// 递归处理子路由
|
||||
if (route.children && route.children.length > 0) {
|
||||
addDefaultComponent(route.children);
|
||||
}
|
||||
});
|
||||
};
|
||||
addDefaultComponent(routes);
|
||||
|
||||
// 3. 按 order 排序
|
||||
const sortRoutes = (routesList) => {
|
||||
|
||||
+18
-18
@@ -142,24 +142,24 @@ function addDynamicRoutes(menus) {
|
||||
|
||||
// 添加知识库的子路由(详情页和编辑页)
|
||||
// 直接在 Main 路由下添加完整路径的子路由
|
||||
router.addRoute('Main', {
|
||||
path: 'apps/knowledge/detail/:id',
|
||||
name: 'apps-knowledge-detail',
|
||||
component: () => import('@/views/apps/knowledge/components/detail.vue'),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
title: '知识详情'
|
||||
}
|
||||
});
|
||||
router.addRoute('Main', {
|
||||
path: 'apps/knowledge/edit/:id',
|
||||
name: 'apps-knowledge-edit',
|
||||
component: () => import('@/views/apps/knowledge/components/edit.vue'),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
title: '编辑知识'
|
||||
}
|
||||
});
|
||||
// router.addRoute('Main', {
|
||||
// path: 'apps/knowledge/detail/:id',
|
||||
// name: 'apps-knowledge-detail',
|
||||
// component: () => import('@/views/apps/knowledge/components/detail.vue'),
|
||||
// meta: {
|
||||
// requiresAuth: true,
|
||||
// title: '知识详情'
|
||||
// }
|
||||
// });
|
||||
// router.addRoute('Main', {
|
||||
// path: 'apps/knowledge/edit/:id',
|
||||
// name: 'apps-knowledge-edit',
|
||||
// component: () => import('@/views/apps/knowledge/components/edit.vue'),
|
||||
// meta: {
|
||||
// requiresAuth: true,
|
||||
// title: '编辑知识'
|
||||
// }
|
||||
// });
|
||||
|
||||
dynamicRoutesAdded = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user