/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useContext, useMemo } from 'react'; import { Routes, Route, Navigate, useLocation, useNavigate, } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Activity, BarChart2, CreditCard, FileText, Gift, Receipt, Settings, } from 'lucide-react'; import { StatusContext } from '../../context/Status'; import PageBackground from '../../components/common/PageBackground'; import UserCenterSidebar from './UserCenterSidebar'; import UserDashboard from './UserDashboard'; import UsageRecord from './UsageRecord'; import Invite from './Invite'; import Invoice from './Invoice'; import TopUp from '../TopUp'; import PersonalSetting from '../../components/settings/PersonalSetting'; import ServiceDashboard from '../ServiceDashboard'; import WeyAiDownload from '../WeyAiDownload'; import { normalizeSidebarModulesAdmin } from '../../constants/sidebarModules'; // 移动端底部导航组件 const MobileBottomNav = ({ sidebarConfig }) => { const { t } = useTranslation(); const location = useLocation(); const navigate = useNavigate(); const navItems = [ { key: 'dashboard', icon: BarChart2, label: t('概览'), path: '/user-center/dashboard', }, { key: 'usageRecord', icon: FileText, label: t('记录'), path: '/user-center/usage-record', }, { key: 'serviceDashboard', icon: Activity, label: t('监控'), path: '/user-center/service-dashboard', }, { key: 'invite', icon: Gift, label: t('邀请'), path: '/user-center/invite', }, { key: 'topup', icon: CreditCard, label: t('充值'), path: '/user-center/topup', }, { key: 'invoice', icon: Receipt, label: t('发票'), path: '/user-center/invoice', }, { key: 'settings', icon: Settings, label: t('设置'), path: '/user-center/settings', }, ]; const visibleNavItems = navItems.filter( (item) => sidebarConfig?.enabled !== false && sidebarConfig?.[item.key] !== false, ); if (visibleNavItems.length === 0) { return null; } return (
{visibleNavItems.map((item) => { const isActive = location.pathname === item.path || location.pathname.startsWith(`${item.path}/`); const IconComponent = item.icon; return ( ); })}
); }; const UserCenter = () => { const [statusState] = useContext(StatusContext); // 跑马灯公告是否存在(用于动态计算顶部间距) const hasMarquee = !!statusState?.status?.marquee_content?.trim(); const userCenterConfig = useMemo( () => normalizeSidebarModulesAdmin(statusState?.status?.SidebarModulesAdmin) .userCenter, [statusState?.status?.SidebarModulesAdmin], ); const userCenterRoutes = [ 'dashboard', 'usageRecord', 'serviceDashboard', 'topup', 'invoice', 'invite', 'settings', ]; const routePathMap = { dashboard: 'dashboard', usageRecord: 'usage-record', serviceDashboard: 'service-dashboard', topup: 'topup', invoice: 'invoice', invite: 'invite', settings: 'settings', }; const firstVisiblePath = userCenterConfig.enabled === false ? null : routePathMap[ userCenterRoutes.find((key) => userCenterConfig[key] !== false) ] || null; const firstVisibleRoute = firstVisiblePath ? `/user-center/${firstVisiblePath}` : '/'; const guardUserCenterRoute = (key, element) => { if (userCenterConfig.enabled === false || userCenterConfig[key] === false) { return ; } return element; }; if (!firstVisiblePath) { return ; } return (
{/* Sidebar - 仅桌面端 */}
{/* Main Content */}
{/* 统一页面背景层 —— 唯一背景来源,走 bg-glow-* 主题变量 */} {/* 内容区域 */}
} /> )} /> )} /> {/* ServiceDashboard 组件内部有 min-h-screen pt-[88px],嵌入 UserCenter 后用 -mt-[64px] 部分抵消 pt,保留 24px 顶部间距(与其他页面 p-6 一致),[&>div]:min-h-0 避免撑高 */}
, )} /> {/* TopUp 组件内部有 pt-[64px] 用于独立路由清除固定头部,UserCenter 已处理顶部偏移,需用 -mt 抵消。 * embedded:UserCenter shell 已提供 PageBackground,子页面不再渲染自身背景,避免双层叠加 */}
, )} /> {/* PersonalSetting 内部有 pt-16 sm:pt-20 用于独立路由清除固定头部,UserCenter 已处理顶部偏移,需用 -mt 抵消 */} {/* 邀请返利 / 发票抬头:侧栏项、routePathMap、权限守卫此前都已配好, 唯独漏了这两个 ,导致点进来是空白内容区。 手机端侧栏是 hidden md:block,底部导航是唯一入口,等于两个死路口。 两个组件根节点都是 p-4 sm:p-6、无自带顶部偏移,可直接嵌入。 */} )} /> )} />
, )} /> {/* WeyAi 桌面端下载:侧栏入口指到这里而不是独立的 /weyai/download, 否则点一下侧栏就整页跳走、导航栏消失。embedded:不加顶部让位、 不自绘背景(shell 已有 PageBackground)。未开放时页面自身显示空态, 侧栏项也随开关隐藏,无需再加守卫 */} } /> {/* 移动端底部导航栏 */} ); }; export default UserCenter;