Files
ckb-SuperAdmin/nkebao/src/components/MeauMobile/MeauMoible.tsx
笔记本里的永平 94f61085ca feat: 本次提交更新内容如下
菜单图标矫正
2025-07-21 14:16:50 +08:00

78 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useState, useEffect } from "react";
import { TabBar } from "antd-mobile";
import { PieOutline, UserOutline } from "antd-mobile-icons";
import { HomeOutlined, TeamOutlined } from "@ant-design/icons";
import { useLocation, useNavigate } from "react-router-dom";
const tabs = [
{
key: "home",
title: "首页",
icon: <HomeOutlined />,
path: "/",
},
{
key: "scene",
title: "场景获客",
icon: <TeamOutlined />,
path: "/scenarios",
},
{
key: "work",
title: "工作台",
icon: <PieOutline />,
path: "/workspace",
},
{
key: "mine",
title: "我的",
icon: <UserOutline />,
path: "/mine",
},
];
// 需要展示菜单的路由白名单(可根据实际业务调整)
const menuPaths = ["/", "/scenarios", "/workspace", "/mine"];
const MeauMobile: React.FC = () => {
const location = useLocation();
const navigate = useNavigate();
const [activeKey, setActiveKey] = useState("home");
// 根据当前路由自动设置 activeKey支持嵌套路由
useEffect(() => {
const found = tabs.find((tab) =>
tab.path === "/"
? location.pathname === "/"
: location.pathname.startsWith(tab.path)
);
if (found) setActiveKey(found.key);
}, [location.pathname]);
// 判断当前路由是否需要展示菜单
const showMenu = menuPaths.some((path) =>
path === "/"
? location.pathname === "/"
: location.pathname.startsWith(path)
);
if (!showMenu) return null;
return (
<TabBar
style={{ background: "#fff" }}
activeKey={activeKey}
onChange={(key) => {
setActiveKey(key);
const tab = tabs.find((t) => t.key === key);
if (tab && tab.path) navigate(tab.path);
}}
>
{tabs.map((item) => (
<TabBar.Item key={item.key} icon={item.icon} title={item.title} />
))}
</TabBar>
);
};
export default MeauMobile;