import { useEffect, useState } from "react"; import { NavLink, Outlet, useNavigate } from "react-router-dom"; import { ScanLine, ClipboardList, Bell, User, ArrowLeft } from "lucide-react"; import { useAuth } from "../../contexts/AuthContext"; import { getNotifications } from "../../services/notificationApi"; /** 底部导航 Tab 配置 — 与 uni-app pages.json tabBar.list 完全一致 */ const TABS = [ { path: "/scan", label: "扫码干活", icon: ScanLine }, { path: "/tasks", label: "我的任务", icon: ClipboardList }, { path: "/notifications", label: "消息", icon: Bell }, { path: "/profile", label: "我的", icon: User }, ] as const; /** 导航栏高度(供页面计算偏移量) */ export const TAB_BAR_HEIGHT = 64; const TOP_BAR_HEIGHT = 48; export default function AppLayout() { const { user } = useAuth(); const navigate = useNavigate(); const [unreadCount, setUnreadCount] = useState(0); // 🔔 未读消息数轮询 useEffect(() => { const userId = user?.username || user?.id || ""; if (!userId) return; function poll() { getNotifications(userId, 0, 1) .then((res) => setUnreadCount(res.unread_count || 0)) .catch(() => {}); // 静默 } poll(); // 立即请求一次 const id = setInterval(poll, 30_000); // 每 30 秒轮询 return () => clearInterval(id); }, [user]); return (