fix(components): 菜单管理调整
This commit is contained in:
@@ -2,12 +2,11 @@ import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { setupElegantRouter } from '../build/plugins/router.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 generatedFiles = [
|
||||
path.resolve(rootDir, 'src/router/elegant/imports.ts'),
|
||||
@@ -36,17 +35,25 @@ function isGenerated(before, after) {
|
||||
async function waitForGeneration(beforeMtimes, timeoutMs = 10000) {
|
||||
const startTime = Date.now();
|
||||
|
||||
while (Date.now() - startTime < timeoutMs) {
|
||||
async function poll() {
|
||||
const afterMtimes = await getGeneratedFileMtimes();
|
||||
|
||||
if (isGenerated(beforeMtimes, afterMtimes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
if (Date.now() - startTime >= timeoutMs) {
|
||||
throw new Error('Timed out while waiting for elegant-router generated files.');
|
||||
}
|
||||
|
||||
await new Promise(resolve => {
|
||||
setTimeout(resolve, 100);
|
||||
});
|
||||
|
||||
await poll();
|
||||
}
|
||||
|
||||
throw new Error('Timed out while waiting for elegant-router generated files.');
|
||||
await poll();
|
||||
}
|
||||
|
||||
process.chdir(rootDir);
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user