修复页面bug

This commit is contained in:
2025-09-26 18:42:41 +08:00
parent 3c604be299
commit 4c154ec746
19 changed files with 584 additions and 405 deletions
@@ -8,14 +8,11 @@ import {
AppstoreOutlined,
FileTextOutlined,
TeamOutlined,
ToolOutlined,
BarChartOutlined,
CloudServerOutlined,
BugOutlined,
SearchOutlined,
MessageOutlined,
FolderOutlined,
SafetyOutlined,
} from '@ant-design/icons';
import { Link, useLocation, history } from 'umi';
import ProLayout, { MenuDataItem } from '@ant-design/pro-layout';
@@ -23,7 +20,6 @@ import { fetchMenuData, outLogin } from '@/services/login';
import { useTheme } from '@/theme';
import { ThemeSwitch } from '@/components/ui';
// 后端菜单节点(兼容 children 与 subMenus)
type MenuNode = {
id?: number | string;
name?: string;
@@ -56,16 +52,21 @@ const BasicLayout: React.FC = (props: any) => {
return () => { mounted = false; };
}, []);
// 将后端菜单转换为 ProLayout 菜单(对齐 react-web 映射规则)
const menuDataRender = useMemo(() => {
const mapPath = (m: MenuNode): string | undefined => {
const mapPath = (m: MenuNode, childrenLen: number): string | undefined => {
const cand = (m.path || m.url || '').trim();
if (!cand) return undefined;
const lower = cand.toLowerCase();
if (lower.startsWith('http')) return cand; // 外链
if (lower.endsWith('.html')) return cand.startsWith('/') ? cand : `/${cand}`; // 仅 .html 可点击
if (lower.endsWith('.html')) return cand.startsWith('/') ? cand : `/${cand}`; // 静态路由
if (lower === '/welcome' || lower === 'welcome') return '/welcome';
return undefined; // 其余作为分组,仅展开不跳转
// 兼容后端菜单未带 .html 的叶子路由,例如 /system/tenant => /system/tenant.html
const ensureSlash = cand.startsWith('/') ? cand : `/${cand}`;
const parts = ensureSlash.split('/').filter(Boolean);
if (childrenLen === 0 && parts.length >= 2) {
return `${ensureSlash}.html`;
}
return undefined; // 作为分组
};
const getIcon = (p?: string) => {
@@ -90,12 +91,12 @@ const BasicLayout: React.FC = (props: any) => {
`${parentKey}-${menu.name}-${index}`;
const keyStr = String(stableKey);
const path = mapPath(menu);
const childrenList: MenuNode[] = (menu.children && menu.children.length ? menu.children : (menu.subMenus || [])) || [];
const path = mapPath(menu, childrenList.length);
const item: MenuDataItem = {
key: keyStr,
name: menu.name || `菜单项${index + 1}`,
name: menu.name || `菜单${index + 1}`,
path,
icon: getIcon(path),
children: childrenList.map((child: MenuNode, i: number) => normalize(child, i, keyStr)),
@@ -103,13 +104,11 @@ const BasicLayout: React.FC = (props: any) => {
return item;
};
// 首次未加载完毕前不渲染默认菜单,避免覆盖接口菜单
if (!loaded) return [];
const list = menus && menus.length ? menus : [{ name: '欢迎页', url: '/welcome', id: 'welcome-default' }];
return list.map((m, i) => normalize(m, i));
}, [menus, mode, loaded]);
// 右上角操作区
const rightContentRender = () => (
<Space size="middle">
<ThemeSwitch mode={mode} onToggle={toggle} />
@@ -196,7 +195,6 @@ const BasicLayout: React.FC = (props: any) => {
)}
token={{
sider: {
// 左侧侧边栏背景使用更柔和的浅色,避免纯白突兀
colorMenuBackground: 'var(--sider-bg)',
colorBgMenuItemSelected: 'var(--primary-color)',
colorTextMenuSelected: '#ffffff',
@@ -204,7 +202,6 @@ const BasicLayout: React.FC = (props: any) => {
colorBgMenuItemHover: 'var(--bg-glass)',
},
header: {
// 顶部导航背景采用柔和渐变
colorBgHeader: 'var(--header-bg)',
colorHeaderTitle: 'var(--text-primary)',
colorTextRightActionsItem: 'var(--text-secondary)',