feat: 本次提交更新内容如下

同步导航栏
This commit is contained in:
笔记本里的永平
2025-07-22 11:15:41 +08:00
parent a1e707b12e
commit b8e309d26f
8 changed files with 43 additions and 70 deletions

View File

@@ -1,8 +1,8 @@
import React, { useState, useEffect } from "react";
import React 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";
import { useNavigate } from "react-router-dom";
const tabs = [
{
@@ -12,13 +12,13 @@ const tabs = [
path: "/",
},
{
key: "scene",
key: "scenarios",
title: "场景获客",
icon: <TeamOutlined />,
path: "/scenarios",
},
{
key: "work",
key: "workspace",
title: "工作台",
icon: <PieOutline />,
path: "/workspace",
@@ -31,38 +31,18 @@ const tabs = [
},
];
// 需要展示菜单的路由白名单(可根据实际业务调整)
const menuPaths = ["/", "/scenarios", "/workspace", "/mine"];
interface MeauMobileProps {
activeKey: string;
}
const MeauMobile: React.FC = () => {
const location = useLocation();
const MeauMobile: React.FC<MeauMobileProps> = ({ activeKey }) => {
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);
}}