fix: hide unsupported menus in minimal scope
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { toastService } from '~/components/ui';
|
||||
import { apiRequest } from '../axios-client';
|
||||
import { isMinimalMenuPath } from '~/config/minimal-scope';
|
||||
|
||||
// 后端返回的路由数据接口
|
||||
export interface BackendRouteInfo {
|
||||
@@ -963,6 +964,7 @@ function convertBackendRoutesToMenuItems(backendRoutes: BackendRouteInfo[], incl
|
||||
// console.log('🔄 [convertBackendRoutesToMenuItems] 构建树后的路由数据:', JSON.stringify(treeRoutes, null, 2));
|
||||
|
||||
const result = treeRoutes
|
||||
.filter(route => isMinimalMenuPath(route.route_path))
|
||||
.filter(route => {
|
||||
const shouldInclude = includeHidden || !route.is_hidden;
|
||||
// console.log(`🔄 [convertBackendRoutesToMenuItems] 过滤路由 ${route.route_name}: is_hidden=${route.is_hidden}, includeHidden=${includeHidden}, 结果=${shouldInclude}`);
|
||||
@@ -1036,7 +1038,7 @@ function buildFallbackRoutes(roleKey: string): {
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: fallbackMenus,
|
||||
data: fallbackMenus.filter(item => isMinimalMenuPath(item.path)),
|
||||
permissionMap,
|
||||
};
|
||||
}
|
||||
|
||||
+20
-1
@@ -1,4 +1,5 @@
|
||||
import { apiRequest } from "../axios-client";
|
||||
import { normalizeHomeTargetPath } from '~/config/minimal-scope';
|
||||
// import dayjs from 'dayjs';
|
||||
|
||||
/**
|
||||
@@ -257,7 +258,25 @@ export async function getEntryModules(token?: string): Promise<EntryModule[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
return modules;
|
||||
const normalizedModules: EntryModule[] = [];
|
||||
for (const module of modules) {
|
||||
const normalizedTargetPath = normalizeHomeTargetPath(
|
||||
module.targetPath,
|
||||
Array.isArray(module.documentTypes) && module.documentTypes.length > 0
|
||||
);
|
||||
|
||||
if (!normalizedTargetPath) {
|
||||
continue;
|
||||
}
|
||||
|
||||
normalizedModules.push({
|
||||
...module,
|
||||
targetPath: normalizedTargetPath,
|
||||
routePath: normalizedTargetPath
|
||||
});
|
||||
}
|
||||
|
||||
return normalizedModules;
|
||||
} catch (error) {
|
||||
console.error('❌ [getEntryModules] 获取入口模块失败:', error instanceof Error ? error.message : String(error));
|
||||
return [];
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
export const MINIMAL_MENU_PREFIXES = [
|
||||
'/home',
|
||||
'/chat-with-llm',
|
||||
'/files',
|
||||
'/documents'
|
||||
] as const;
|
||||
|
||||
export const MINIMAL_HOME_TARGETS = [
|
||||
'/home',
|
||||
'/files/upload',
|
||||
'/documents',
|
||||
'/chat-with-llm/chat'
|
||||
] as const;
|
||||
|
||||
export function isMinimalMenuPath(path?: string | null): boolean {
|
||||
if (!path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return MINIMAL_MENU_PREFIXES.some(prefix => path === prefix || path.startsWith(`${prefix}/`));
|
||||
}
|
||||
|
||||
export function normalizeHomeTargetPath(path?: string | null, hasDocumentTypes: boolean = false): string | null {
|
||||
if (!path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (path === '/contract-template/search' && hasDocumentTypes) {
|
||||
return '/files/upload';
|
||||
}
|
||||
|
||||
if (path === '/cross-checking') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (MINIMAL_HOME_TARGETS.some(prefix => path === prefix || path.startsWith(`${prefix}/`))) {
|
||||
return path;
|
||||
}
|
||||
|
||||
return hasDocumentTypes ? '/files/upload' : null;
|
||||
}
|
||||
Reference in New Issue
Block a user