133 lines
2.8 KiB
TypeScript
133 lines
2.8 KiB
TypeScript
export const LIGHT_MENU_NAMES = new Set([
|
|
'AccountSettings',
|
|
'Application',
|
|
'ControlCenter',
|
|
'AIAgent',
|
|
'AIKnowledgeDetail',
|
|
'AIModelConfig',
|
|
'AIPlatform',
|
|
'AIWorkflow',
|
|
'AIWorkflowRuns',
|
|
'AnnouncementList',
|
|
'AnnouncementManage',
|
|
'CodexAgentChat',
|
|
'FileManager',
|
|
'Message',
|
|
'MessageCenter',
|
|
'MessageList',
|
|
'KnowledgeBase',
|
|
'LoginLog',
|
|
'OrgNode',
|
|
'DatabaseMonitor',
|
|
'RedisMonitor',
|
|
'ServerMonitor',
|
|
'StartChat',
|
|
'SystemDept',
|
|
'SystemDict',
|
|
'SystemFileManager',
|
|
'SystemLoginLog',
|
|
'SystemManagement',
|
|
'SystemOrgChart',
|
|
'SystemTools',
|
|
'SystemConfig',
|
|
'SystemConfigManager',
|
|
'SystemMonitoring',
|
|
'SystemMenu',
|
|
'SystemPermission',
|
|
'SystemPost',
|
|
'SystemRole',
|
|
'UIConfig',
|
|
'UIConfigManager',
|
|
'UserManagement',
|
|
'userCenter',
|
|
'userSettings',
|
|
]);
|
|
|
|
const LIGHT_ROUTE_PATH_PREFIXES = [
|
|
'/control-center',
|
|
'/ai-platform/agent',
|
|
'/ai-platform/knowledge',
|
|
'/ai-platform/knowledge-base',
|
|
'/ai-platform/model',
|
|
'/ai-platform/workflow',
|
|
'/ai-platform/workflow-runs',
|
|
'/agent-chat',
|
|
'/application',
|
|
'/chat',
|
|
'/message/list',
|
|
'/message/announcement',
|
|
'/message/announcement-list',
|
|
'/page-render/main_home',
|
|
'/monitor',
|
|
'/core/ui-config',
|
|
'/system-config',
|
|
'/system/dept',
|
|
'/system/dict',
|
|
'/system/file-manager',
|
|
'/system/login-log',
|
|
'/system/org-chart',
|
|
'/system/post',
|
|
'/system/config',
|
|
'/system/menu',
|
|
'/system/new-permission',
|
|
'/system/role',
|
|
'/system/ui-config',
|
|
'/system/user',
|
|
'/tool/dict',
|
|
'/tool/file',
|
|
'/log/login-log',
|
|
'/user-center',
|
|
];
|
|
|
|
export function isLightMenuName(name?: string) {
|
|
return !name || LIGHT_MENU_NAMES.has(name);
|
|
}
|
|
|
|
function normalizePath(path?: string) {
|
|
if (!path) return '';
|
|
return path.split('?')[0]?.replace(/\/$/, '') || '';
|
|
}
|
|
|
|
export function isLightTabRoute(route: {
|
|
fullPath?: string;
|
|
matched?: Array<{ name?: unknown; path?: string }>;
|
|
name?: unknown;
|
|
path?: string;
|
|
}) {
|
|
if (typeof route.name === 'string' && LIGHT_MENU_NAMES.has(route.name)) {
|
|
return true;
|
|
}
|
|
|
|
if (
|
|
route.matched?.some(
|
|
(item) =>
|
|
typeof item.name === 'string' && LIGHT_MENU_NAMES.has(item.name),
|
|
)
|
|
) {
|
|
return true;
|
|
}
|
|
|
|
const path = normalizePath(route.fullPath || route.path);
|
|
return LIGHT_ROUTE_PATH_PREFIXES.some(
|
|
(prefix) => path === prefix || path.startsWith(`${prefix}/`),
|
|
);
|
|
}
|
|
|
|
export function filterLightMenuTree<
|
|
T extends { children?: T[]; name?: string },
|
|
>(routes: T[]): T[] {
|
|
return routes
|
|
.map((route) => {
|
|
const children = route.children
|
|
? filterLightMenuTree(route.children)
|
|
: undefined;
|
|
|
|
if (!isLightMenuName(route.name) && !children?.length) {
|
|
return undefined;
|
|
}
|
|
|
|
return children ? { ...route, children } : route;
|
|
})
|
|
.filter(Boolean) as T[];
|
|
}
|