首页统计

This commit is contained in:
2025-10-01 03:51:53 +08:00
parent dbd4d4d198
commit 66d09ef19c
32 changed files with 1293 additions and 499 deletions
@@ -17,6 +17,7 @@ import {
import { Link, useLocation, history } from 'umi';
import ProLayout, { MenuDataItem } from '@ant-design/pro-layout';
import { fetchMenuData, outLogin } from '@/services/login';
import { clearTenantCache } from '@/utils/tenantCache';
import { useTheme } from '@/theme';
import { ThemeSwitch } from '@/components/ui';
@@ -57,16 +58,15 @@ const BasicLayout: React.FC = (props: any) => {
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}`; // 静态路由
if (lower === '/welcome' || lower === 'welcome') return '/welcome';
// 兼容后端菜单未带 .html 的叶子路由,例如 /system/tenant => /system/tenant.html
if (lower.startsWith('http')) return cand; // 澶栭摼
if (lower.endsWith('.html')) return cand.startsWith('/') ? cand : `/${cand}`; // 闈欐€佽矾鐢? if (lower === '/welcome' || lower === 'welcome') return '/welcome';
// 鍏煎鍚庣鑿滃崟鏈甫 .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; // 作为分组
return undefined; // 浣滀负鍒嗙粍
};
const getIcon = (p?: string) => {
@@ -96,7 +96,7 @@ const BasicLayout: React.FC = (props: any) => {
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)),
@@ -105,18 +105,24 @@ const BasicLayout: React.FC = (props: any) => {
};
if (!loaded) return [];
const list = menus && menus.length ? menus : [{ name: '欢迎页', url: '/welcome', id: 'welcome-default' }];
return list.map((m, i) => normalize(m, i));
const list = menus && menus.length ? menus : [{ name: '首页', url: '/welcome', id: 'welcome-default' }];
const rendered = list.map((m, i) => normalize(m, i));
const hasHome = rendered.some((r) => r.path === '/welcome');
if (!hasHome) {
rendered.unshift({ key: 'welcome-fixed', name: '首页', path: '/welcome', icon: <DashboardOutlined /> });
}
return rendered;
}, [menus, mode, loaded]);
const rightContentRender = () => (
<Space size="middle">
<Link to="/welcome" style={{ color: 'var(--text-primary)' }}>首页</Link>
<ThemeSwitch mode={mode} onToggle={toggle} />
<Dropdown
menu={{
items: [
{ key: 'profile', icon: <UserOutlined />, label: '个人中心' },
{ key: 'settings', icon: <SettingOutlined />, label: '系统设置' },
{ key: 'settings', icon: <SettingOutlined />, label: '设置' },
{ type: 'divider' as any },
{
key: 'logout',
@@ -127,6 +133,7 @@ const BasicLayout: React.FC = (props: any) => {
try {
sessionStorage.removeItem('access_token');
sessionStorage.removeItem('current_user');
clearTenantCache();
} catch {}
message.success('已退出登录');
history.push('/user/login');
@@ -175,6 +182,7 @@ const BasicLayout: React.FC = (props: any) => {
);
}}
headerTitleRender={(logo, title) => (
<Link to="/welcome" style={{ textDecoration: 'none' }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 12, fontWeight: 600 }}>
<div
style={{
@@ -192,6 +200,7 @@ const BasicLayout: React.FC = (props: any) => {
</div>
<span style={{ fontSize: 18, color: 'var(--text-primary)', fontWeight: 700 }}>{title}</span>
</div>
</Link>
)}
token={{
sider: {
@@ -217,3 +226,6 @@ const BasicLayout: React.FC = (props: any) => {
};
export default BasicLayout;