'use client'; import { Book, Menu, Sunset, Trees, Zap } from "lucide-react"; import { Tractor, Map, Clipboard, Package, Brain, Droplets, Settings } from 'lucide-react'; import { MessageBell } from './components/MessageBell'; import { UserProfile } from './components/UserProfile'; import { ThemeToggle } from './ThemeToggle'; import { AuthProvider } from './components/auth/AuthContext'; import { useElementHeight } from '@/hooks/useElementHeight'; import { useViewHeight } from '@/hooks/useViewHeight'; import { usePathname } from 'next/navigation'; import { useRef, useEffect, useState } from 'react'; // 注释掉 Accordion 相关导入,因为不再需要二级菜单 // import { // Accordion, // AccordionContent, // AccordionItem, // AccordionTrigger, // } from "@/components/ui/accordion"; import { useLayoutStore } from '@/stores/useLayoutStore'; import { Button } from "@/components/ui/button"; import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu"; import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger, } from "@/components/ui/sheet"; interface MenuItem { title: string; url: string; description?: string; icon?: React.ReactNode; items?: MenuItem[]; } interface Navbar1Props { logo?: { url: string; src: string; alt: string; title: string; }; menu?: MenuItem[]; auth?: { login: { title: string; url: string; }; signup: { title: string; url: string; }; }; } const navbarData = { logo: { url: "/", src: "https://deifkwefumgah.cloudfront.net/shadcnblocks/block/logos/shadcnblockscom-icon.svg", alt: "Crop-X Logo", title: "智慧农业生产管理系统", }, menu: [ { title: "智能农机管理系统", url: "/agricultural-machinery", description: "农机档案、实时监控、精准作业管理", icon: , }, { title: "地块信息管理系统", url: "/land-information", description: "地块档案、地图管理、空间分析", icon: , }, { title: "农事操作管理系统", url: "/farming-operation", description: "农事计划、任务管理、操作执行", icon: , }, { title: "农业资产管理系统", url: "/agricultural-asset", description: "基础信息、采购管理、库存管理", icon: , }, { title: "AI作物模型精准决策系统", url: "/ai-crop-model", description: "数据感知、模型应用、智能决策", icon: , }, { title: "水肥一体化控制系统", url: "/water-fertilizer-control", description: "水肥机管理、智能灌溉、配方管理", icon: , }, { title: "中心配置管理系统", url: "/central-config", description: "租户管理、用户管理、系统监控", icon: , }, { title: "API 测试示例", url: "/api-example", description: "测试和展示 OpenAPI 客户端调用", icon: , }, ], auth: { login: { title: "登录", url: "/login" }, signup: { title: "注册", url: "/register" }, }, }; const Navbar1 = () => { const logo = navbarData.logo const menu = navbarData.menu const auth = navbarData.auth const pathname = usePathname() const containerStyle = { maxWidth:"100%",marginLeft:"0px",marginRight:"0px",paddingLeft:"1rem",paddingRight:"0rem" } // 检查当前路径是否匹配菜单项 const isMenuActive = (url: string) => { // 精确匹配 if (pathname === url) return true; // 检查是否是该菜单下的子路径 if (pathname.startsWith(url + '/')) return true; return false; } // 使用自定义 Hook 计算高度 const { elementRef, updateHeight } = useElementHeight({ immediate: true, // 立即计算高度 onUpdate: (height: number) => { // 更新 Zustand store 中的状态 const { setNavigatorHeight } = useLayoutStore.getState(); setNavigatorHeight(height); } }); // 监听页面高度变化 useViewHeight(); const handleMessageClick = () => { // 处理消息点击事件,可以跳转到消息中心页面 console.log('Navigate to message center'); }; const handleProfileClick = () => { // 处理个人中心点击事件 console.log('Navigate to profile page'); }; return (
{/* Desktop Menu */} {/* Mobile Menu */}
{/* Logo */} {logo.alt} {logo.alt}
{/* 简化移动端菜单,不再使用 Accordion */}
{menu.map((item) => renderMobileMenuItem(item, isMenuActive))}
); }; const renderMenuItem = (item: MenuItem, isMenuActive: (url: string) => boolean) => { // 注释掉二级菜单相关代码,项目不需要二级菜单 // if (item.items) { // return ( // // {item.title} // // {item.items.map((subItem) => ( // // // // // ))} // // // ); // } return ( {item.icon && ( {item.icon} )}
{item.title} {/* 激活菜单项下方的横条 */} {isMenuActive(item.url) && (
)}
); }; const renderMobileMenuItem = (item: MenuItem, isMenuActive: (url: string) => boolean) => { // 注释掉移动端二级菜单相关代码 // if (item.items) { // return ( // // // {item.icon && {item.icon}} // {item.title} // // // {item.items.map((subItem) => ( // // ))} // // // ); // } return ( {item.icon && ( {item.icon} )} {item.title} ); }; // 注释掉 SubMenuLink 组件,因为不再需要二级菜单 // const SubMenuLink = ({ item }: { item: MenuItem }) => { // return ( // //
{item.icon}
//
//
{item.title}
// {item.description && ( //

// {item.description} //

// )} //
//
// ); // }; export { Navbar1 };