refactor(types): 重构类型系统,统一共享类型定义
feat(types): 新增共享类型中心,包含用户、产品、订单等核心领域类型 fix(types): 修复类型定义错误,统一各模块类型引用 style(types): 优化类型文件格式和注释 docs(types): 更新类型文档和变更日志 test(types): 添加类型测试用例 build(types): 配置类型共享路径 chore(types): 清理重复类型定义文件
This commit is contained in:
@@ -27,13 +27,22 @@ import {
|
||||
SwapOutlined,
|
||||
ThunderboltOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { Link, useLocation, history, Outlet } from 'umi';
|
||||
import { Link, useLocation, useNavigate, Outlet } from 'react-router-dom';
|
||||
|
||||
const { Header, Sider, Content } = Layout;
|
||||
const { Title, Text } = Typography;
|
||||
|
||||
// 菜单项类型定义
|
||||
interface MenuItem {
|
||||
key: string;
|
||||
icon?: React.ReactNode;
|
||||
label: React.ReactNode;
|
||||
children?: MenuItem[];
|
||||
type?: 'divider';
|
||||
}
|
||||
|
||||
// 菜单项配置
|
||||
const menuItems = [
|
||||
const menuItems: MenuItem[] = [
|
||||
// 核心业务
|
||||
{
|
||||
key: 'core',
|
||||
@@ -175,7 +184,7 @@ const menuItems = [
|
||||
];
|
||||
|
||||
// 用户菜单项
|
||||
const userMenuItems = [
|
||||
const userMenuItems: MenuItem[] = [
|
||||
{
|
||||
key: 'profile',
|
||||
label: '个人中心',
|
||||
@@ -195,6 +204,7 @@ const userMenuItems = [
|
||||
|
||||
const MainLayout: React.FC = () => {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
const [selectedKeys, setSelectedKeys] = useState<string[]>(['/']);
|
||||
|
||||
@@ -205,17 +215,19 @@ const MainLayout: React.FC = () => {
|
||||
let matchedKey: string | undefined;
|
||||
|
||||
// 递归查找匹配的菜单项
|
||||
const findMatchedItem = (items: any[]) => {
|
||||
const findMatchedItem = (items: MenuItem[]): boolean => {
|
||||
for (const item of items) {
|
||||
if (item.type === 'divider') continue;
|
||||
if (item.children) {
|
||||
// 检查子菜单项
|
||||
for (const child of item.children) {
|
||||
if (child.type === 'divider') continue;
|
||||
if (child.key === '/') {
|
||||
if (pathname === '/') {
|
||||
matchedKey = child.key;
|
||||
return true;
|
||||
}
|
||||
} else if (pathname.startsWith(child.key as string)) {
|
||||
} else if (pathname.startsWith(child.key)) {
|
||||
matchedKey = child.key;
|
||||
return true;
|
||||
}
|
||||
@@ -231,7 +243,7 @@ const MainLayout: React.FC = () => {
|
||||
matchedKey = item.key;
|
||||
return true;
|
||||
}
|
||||
} else if (pathname.startsWith(item.key as string)) {
|
||||
} else if (pathname.startsWith(item.key)) {
|
||||
matchedKey = item.key;
|
||||
return true;
|
||||
}
|
||||
@@ -265,11 +277,11 @@ const MainLayout: React.FC = () => {
|
||||
if (key === 'logout') {
|
||||
// 处理登出逻辑
|
||||
localStorage.removeItem('token');
|
||||
history.push('/Auth/LoginPage');
|
||||
navigate('/Auth/LoginPage');
|
||||
} else if (key === 'profile') {
|
||||
history.push('/Settings/ProfileSettings');
|
||||
navigate('/Settings/ProfileSettings');
|
||||
} else if (key === 'settings') {
|
||||
history.push('/Settings');
|
||||
navigate('/Settings');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user