fix: hide unsupported menus in minimal scope
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { toastService } from '~/components/ui';
|
import { toastService } from '~/components/ui';
|
||||||
import { apiRequest } from '../axios-client';
|
import { apiRequest } from '../axios-client';
|
||||||
|
import { isMinimalMenuPath } from '~/config/minimal-scope';
|
||||||
|
|
||||||
// 后端返回的路由数据接口
|
// 后端返回的路由数据接口
|
||||||
export interface BackendRouteInfo {
|
export interface BackendRouteInfo {
|
||||||
@@ -963,6 +964,7 @@ function convertBackendRoutesToMenuItems(backendRoutes: BackendRouteInfo[], incl
|
|||||||
// console.log('🔄 [convertBackendRoutesToMenuItems] 构建树后的路由数据:', JSON.stringify(treeRoutes, null, 2));
|
// console.log('🔄 [convertBackendRoutesToMenuItems] 构建树后的路由数据:', JSON.stringify(treeRoutes, null, 2));
|
||||||
|
|
||||||
const result = treeRoutes
|
const result = treeRoutes
|
||||||
|
.filter(route => isMinimalMenuPath(route.route_path))
|
||||||
.filter(route => {
|
.filter(route => {
|
||||||
const shouldInclude = includeHidden || !route.is_hidden;
|
const shouldInclude = includeHidden || !route.is_hidden;
|
||||||
// console.log(`🔄 [convertBackendRoutesToMenuItems] 过滤路由 ${route.route_name}: is_hidden=${route.is_hidden}, includeHidden=${includeHidden}, 结果=${shouldInclude}`);
|
// console.log(`🔄 [convertBackendRoutesToMenuItems] 过滤路由 ${route.route_name}: is_hidden=${route.is_hidden}, includeHidden=${includeHidden}, 结果=${shouldInclude}`);
|
||||||
@@ -1036,7 +1038,7 @@ function buildFallbackRoutes(roleKey: string): {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: fallbackMenus,
|
data: fallbackMenus.filter(item => isMinimalMenuPath(item.path)),
|
||||||
permissionMap,
|
permissionMap,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-1
@@ -1,4 +1,5 @@
|
|||||||
import { apiRequest } from "../axios-client";
|
import { apiRequest } from "../axios-client";
|
||||||
|
import { normalizeHomeTargetPath } from '~/config/minimal-scope';
|
||||||
// import dayjs from 'dayjs';
|
// import dayjs from 'dayjs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -257,7 +258,25 @@ export async function getEntryModules(token?: string): Promise<EntryModule[]> {
|
|||||||
return [];
|
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) {
|
} catch (error) {
|
||||||
console.error('❌ [getEntryModules] 获取入口模块失败:', error instanceof Error ? error.message : String(error));
|
console.error('❌ [getEntryModules] 获取入口模块失败:', error instanceof Error ? error.message : String(error));
|
||||||
return [];
|
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