2026-03-30 14:53:42 +08:00
|
|
|
import React from 'react';
|
|
|
|
|
import { Layout, Dropdown } from 'antd';
|
|
|
|
|
import type { MenuProps } from 'antd';
|
2026-03-30 16:07:05 +08:00
|
|
|
import { useLocation } from '@umijs/max';
|
2026-03-30 14:53:42 +08:00
|
|
|
import AvatarProps from './AvatarProps';
|
|
|
|
|
import { useMyState } from '@/common';
|
|
|
|
|
|
|
|
|
|
const { Header } = Layout;
|
|
|
|
|
|
|
|
|
|
interface CustomHeaderProps {
|
|
|
|
|
collapsed?: boolean;
|
|
|
|
|
toggle?: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const CustomHeader: React.FC<CustomHeaderProps> = ({ collapsed, toggle }) => {
|
|
|
|
|
const { snap } = useMyState();
|
2026-03-30 16:07:05 +08:00
|
|
|
const { pathname } = useLocation();
|
2026-03-30 16:06:31 +08:00
|
|
|
|
|
|
|
|
// 在登录页面不显示header
|
|
|
|
|
if (pathname === '/login') {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2026-03-30 14:53:42 +08:00
|
|
|
|
|
|
|
|
const menuItems: MenuProps['items'] = [
|
|
|
|
|
{
|
|
|
|
|
key: 'profile',
|
|
|
|
|
label: '个人资料',
|
|
|
|
|
icon: <span>👤</span>,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'password',
|
|
|
|
|
label: '修改密码',
|
|
|
|
|
icon: <span>🔒</span>,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'divider',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'logout',
|
|
|
|
|
label: '退出登录',
|
|
|
|
|
icon: <span>🚪</span>,
|
|
|
|
|
danger: true,
|
|
|
|
|
onClick: () => {
|
|
|
|
|
// 添加退出登录逻辑
|
|
|
|
|
localStorage.removeItem('token');
|
|
|
|
|
window.location.href = '/login';
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Header className="custom-header">
|
|
|
|
|
{/* 左侧区域 */}
|
|
|
|
|
<div className="header-left">
|
|
|
|
|
{/* 可以添加面包屑导航或其他内容 */}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 右侧用户信息区域 */}
|
|
|
|
|
<div className="header-right">
|
|
|
|
|
<Dropdown menu={{ items: menuItems }} placement="bottomRight">
|
|
|
|
|
<div style={{ cursor: 'pointer', display: 'flex', alignItems: 'center' }}>
|
|
|
|
|
<AvatarProps user={snap.session.user} />
|
|
|
|
|
</div>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
</div>
|
|
|
|
|
</Header>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Styles will be defined in global.less:
|
|
|
|
|
// .custom-header { display: flex; justify-content: space-between; ... }
|
|
|
|
|
// .custom-header .header-left { flex: 1; }
|
|
|
|
|
// .custom-header .header-right { display: flex; gap: 16px; }
|