fix(components): 菜单管理调整

This commit is contained in:
2026-03-27 14:03:42 +08:00
parent 120a5b4dfd
commit ca3d697941
9 changed files with 11075 additions and 103 deletions

View File

@@ -1,14 +1,13 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { customRoutes } from '../src/router/routes/custom-routes.ts';
import { generatedRoutes } from '../src/router/elegant/routes.ts';
import zhCn from '../src/locales/langs/zh-cn.ts';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = path.resolve(__dirname, '..');
const currentFilePath = fileURLToPath(import.meta.url);
const currentDirPath = path.dirname(currentFilePath);
const rootDir = path.resolve(currentDirPath, '..');
const outputPath = path.resolve(rootDir, 'docs/frontend-page-resource-manifest.json');
const excludedPageResourceRouteNames = new Set(['exception_403', 'exception_404', 'exception_500']);
const excludedPageResourcePathPrefixes = ['/function/', '/plugin/'];
@@ -120,54 +119,76 @@ function getRouteLabel(route) {
return route.meta?.title || route.name;
}
function getPageResourceMeta(route) {
const hideInMenu = Boolean(route.meta?.hideInMenu);
const order = getNumberMetaValue(route.meta?.order);
const fixedIndexInTab = getNumberMetaValue(route.meta?.fixedIndexInTab);
return {
title: getRouteLabel(route),
i18nKey: route.meta?.i18nKey || null,
icon: route.meta?.icon || null,
localIcon: route.meta?.localIcon || null,
order,
keepAlive: Boolean(route.meta?.keepAlive),
hideInMenu,
activeMenu: route.meta?.activeMenu || null,
multiTab: Boolean(route.meta?.multiTab),
fixedIndexInTab
};
}
function shouldCollectPageResource(route, pageComponent) {
if (!pageComponent) {
return false;
}
if (route.meta?.hideInMenu) {
return false;
}
return !shouldExcludePageResource(route);
}
function createPageResourceItem(route, options) {
const { pageComponent, parentName, source } = options;
const props = normalizeRouteProps(route.props);
const meta = getPageResourceMeta(route);
return {
name: route.name,
path: route.path,
component: pageComponent,
title: meta.title,
routeTitle: route.meta?.title || route.name,
i18nKey: meta.i18nKey,
icon: meta.icon,
localIcon: meta.localIcon,
order: meta.order,
hideInMenu: meta.hideInMenu,
keepAlive: meta.keepAlive,
activeMenu: meta.activeMenu,
multiTab: meta.multiTab,
fixedIndexInTab: meta.fixedIndexInTab,
redirect: route.redirect || null,
props,
meta,
parentName,
pageType: getPageType(pageComponent),
source
};
}
function collectPageResources(routes, options, items) {
const { parentName = null, source } = options;
const orderedRoutes = sortRoutes(routes);
for (const route of orderedRoutes) {
const pageComponent = getPageComponent(route.component);
const hideInMenu = Boolean(route.meta?.hideInMenu);
// The backend page-node whitelist only contains menu-visible pages.
if (pageComponent && !hideInMenu && !shouldExcludePageResource(route)) {
const order = getNumberMetaValue(route.meta?.order);
const fixedIndexInTab = getNumberMetaValue(route.meta?.fixedIndexInTab);
const props = normalizeRouteProps(route.props);
const meta = {
title: getRouteLabel(route),
i18nKey: route.meta?.i18nKey || null,
icon: route.meta?.icon || null,
localIcon: route.meta?.localIcon || null,
order,
keepAlive: Boolean(route.meta?.keepAlive),
hideInMenu,
activeMenu: route.meta?.activeMenu || null,
multiTab: Boolean(route.meta?.multiTab),
fixedIndexInTab
};
items.push({
name: route.name,
path: route.path,
component: pageComponent,
title: meta.title,
routeTitle: route.meta?.title || route.name,
i18nKey: meta.i18nKey,
icon: meta.icon,
localIcon: meta.localIcon,
order,
hideInMenu,
keepAlive: meta.keepAlive,
activeMenu: meta.activeMenu,
multiTab: meta.multiTab,
fixedIndexInTab,
redirect: route.redirect || null,
props,
meta,
parentName,
pageType: getPageType(pageComponent),
source
});
if (shouldCollectPageResource(route, pageComponent)) {
items.push(createPageResourceItem(route, { pageComponent, parentName, source }));
}
if (route.children?.length) {
@@ -179,8 +200,16 @@ function collectPageResources(routes, options, items) {
function getPageResources() {
const items = [];
collectPageResources(customRoutes.filter(route => !isConstantRoute(route)), { source: 'custom' }, items);
collectPageResources(generatedRoutes.filter(route => !isConstantRoute(route)), { source: 'generated' }, items);
collectPageResources(
customRoutes.filter(route => !isConstantRoute(route)),
{ source: 'custom' },
items
);
collectPageResources(
generatedRoutes.filter(route => !isConstantRoute(route)),
{ source: 'generated' },
items
);
const uniqueItems = Array.from(new Map(items.map(item => [item.name, item])).values());