From 98653f042b4b6ec514bff67afbd5827bab0939e9 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Tue, 21 Oct 2025 15:43:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AF=BC=E8=88=AAUI=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Navbars/HomeNavbar.js | 323 ++++++++++++++++---- src/components/Subscription/CrownTooltip.js | 137 +++++++++ 2 files changed, 405 insertions(+), 55 deletions(-) create mode 100644 src/components/Subscription/CrownTooltip.js diff --git a/src/components/Navbars/HomeNavbar.js b/src/components/Navbars/HomeNavbar.js index 671bc2d8..8b017bf7 100644 --- a/src/components/Navbars/HomeNavbar.js +++ b/src/components/Navbars/HomeNavbar.js @@ -43,7 +43,7 @@ import { logger } from '../../utils/logger'; import { getApiBase } from '../../utils/apiConfig'; import SubscriptionButton from '../Subscription/SubscriptionButton'; import SubscriptionModal from '../Subscription/SubscriptionModal'; -import CrownTooltip, { TooltipContent } from '../Subscription/CrownTooltip'; +import { CrownIcon, TooltipContent } from '../Subscription/CrownTooltip'; /** 二级导航栏组件 - 显示当前一级菜单下的所有二级菜单项 */ const SecondaryNav = ({ showCompletenessAlert }) => { @@ -186,6 +186,112 @@ const SecondaryNav = ({ showCompletenessAlert }) => { ); }; +/** 中屏"更多"菜单 - 用于平板和小笔记本 */ +const MoreNavMenu = ({ isAuthenticated, user }) => { + const navigate = useNavigate(); + const location = useLocation(); + + // 辅助函数:判断导航项是否激活 + const isActive = useCallback((paths) => { + return paths.some(path => location.pathname.includes(path)); + }, [location.pathname]); + + if (!isAuthenticated || !user) return null; + + return ( + + } + fontWeight="medium" + > + 更多 + + + {/* 高频跟踪组 */} + 高频跟踪 + navigate('/community')} + borderRadius="md" + bg={location.pathname.includes('/community') ? 'blue.50' : 'transparent'} + > + + 新闻催化分析 + + HOT + NEW + + + + navigate('/concepts')} + borderRadius="md" + bg={location.pathname.includes('/concepts') ? 'blue.50' : 'transparent'} + > + + 概念中心 + NEW + + + + + + {/* 行情复盘组 */} + 行情复盘 + navigate('/limit-analyse')} + borderRadius="md" + bg={location.pathname.includes('/limit-analyse') ? 'blue.50' : 'transparent'} + > + + 涨停分析 + FREE + + + navigate('/stocks')} + borderRadius="md" + bg={location.pathname.includes('/stocks') ? 'blue.50' : 'transparent'} + > + + 个股中心 + HOT + + + navigate('/trading-simulation')} + borderRadius="md" + bg={location.pathname.includes('/trading-simulation') ? 'blue.50' : 'transparent'} + > + + 模拟盘 + NEW + + + + + + {/* AGENT社群组 */} + AGENT社群 + + 今日热议 + + + 个股社区 + + + + + {/* 联系我们 */} + + 联系我们 + + + + ); +}; + /** 桌面端导航 - 完全按照原网站 * @TODO 添加逻辑 不展示导航case * 1.未登陆状态 && 是首页 @@ -360,6 +466,8 @@ export default function HomeNavbar() { const { isOpen, onOpen, onClose } = useDisclosure(); const navigate = useNavigate(); const isMobile = useBreakpointValue({ base: true, md: false }); + const isTablet = useBreakpointValue({ base: false, md: true, lg: false }); + const isDesktop = useBreakpointValue({ base: false, md: false, lg: true }); const { user, isAuthenticated, logout, isLoading } = useAuth(); const { openAuthModal } = useAuthModal(); const { colorMode, toggleColorMode } = useColorMode(); @@ -746,15 +854,22 @@ export default function HomeNavbar() { - {/* 移动端菜单按钮 */} + {/* 中间导航区域 - 响应式 */} {isMobile ? ( + // 移动端:汉堡菜单 } variant="ghost" onClick={onOpen} aria-label="Open menu" /> - ) : } + ) : isTablet ? ( + // 中屏(平板):"更多"下拉菜单 + + ) : ( + // 大屏(桌面):完整导航菜单 + + )} {/* 右侧:日夜模式切换 + 登录/用户区 */} @@ -774,8 +889,8 @@ export default function HomeNavbar() { ) : isAuthenticated && user ? ( // 已登录状态 - 用户菜单 + 功能菜单排列 - {/* 自选股 - 移动端隐藏 */} - {!isMobile && ( + {/* 自选股 - 仅大屏显示 */} + {isDesktop && ( )} - {/* 关注的事件 - 头像右侧 - 移动端隐藏 */} - {!isMobile && ( + {/* 关注的事件 - 仅大屏显示 */} + {isDesktop && ( )} - {/* 带会员标识的头像 - 点击打开订阅弹窗 */} - setIsSubscriptionModalOpen(true)} - > - {/* 会员图标徽章 - 使用独立的 CrownTooltip 组件 */} - + {/* 头像区域 - 响应式 */} + {isDesktop ? ( + // 大屏:头像点击打开订阅弹窗 + <> + } + placement="bottom" + hasArrow + bg={useColorModeValue('white', 'gray.800')} + borderRadius="lg" + border="1px solid" + borderColor={useColorModeValue('gray.200', 'gray.600')} + boxShadow="lg" + p={3} + > + setIsSubscriptionModalOpen(true)} + > + + + + + {isSubscriptionModalOpen && ( + setIsSubscriptionModalOpen(false)} + subscriptionInfo={subscriptionInfo} + /> + )} + + ) : ( + // 中屏:头像作为下拉菜单,包含所有功能 + + + + + + + + + {/* 用户信息区 */} + + {getDisplayName()} + {user.email} + {user.phone && ( + {user.phone} + )} + {user.has_wechat && ( + 微信已绑定 + )} + - {/* 头像 - 带会员等级边框和详细信息 Tooltip */} - } - placement="bottom" - hasArrow - bg={useColorModeValue('white', 'gray.800')} - borderRadius="lg" - border="1px solid" - borderColor={useColorModeValue('gray.200', 'gray.600')} - boxShadow="lg" - p={3} - > - - - + {/* 订阅管理 */} + } onClick={() => setIsSubscriptionModalOpen(true)}> + + 订阅管理 + + {subscriptionInfo.type === 'max' ? 'MAX' : + subscriptionInfo.type === 'pro' ? 'PRO' : '免费版'} + + + - {/* 订阅管理弹窗 - 只在打开时渲染 */} - {isSubscriptionModalOpen && ( - setIsSubscriptionModalOpen(false)} - subscriptionInfo={subscriptionInfo} - /> + {isSubscriptionModalOpen && ( + setIsSubscriptionModalOpen(false)} + subscriptionInfo={subscriptionInfo} + /> + )} + + + + {/* 自选股 */} + } onClick={() => navigate('/home/center')}> + + 我的自选股 + {watchlistQuotes && watchlistQuotes.length > 0 && ( + {watchlistQuotes.length} + )} + + + + {/* 自选事件 */} + } onClick={() => navigate('/home/center')}> + + 我的自选事件 + {followingEvents && followingEvents.length > 0 && ( + {followingEvents.length} + )} + + + + + + {/* 个人中心 */} + } onClick={() => navigate('/home/center')}> + 个人中心 + + } onClick={() => navigate('/home/profile')}> + 个人资料 + + } onClick={() => navigate('/home/settings')}> + 账户设置 + + + + + {/* 退出登录 */} + } onClick={handleLogout} color="red.500"> + 退出登录 + + + )} - {/* 个人中心下拉菜单 */} + {/* 个人中心下拉菜单 - 仅大屏显示 */} + {isDesktop && ( + )} ) : ( // 未登录状态 - 单一按钮 diff --git a/src/components/Subscription/CrownTooltip.js b/src/components/Subscription/CrownTooltip.js new file mode 100644 index 00000000..0eb40950 --- /dev/null +++ b/src/components/Subscription/CrownTooltip.js @@ -0,0 +1,137 @@ +// src/components/Subscription/CrownTooltip.js +import React from 'react'; +import { + Box, + VStack, + HStack, + Text, + Divider, + useColorModeValue +} from '@chakra-ui/react'; +import PropTypes from 'prop-types'; + +/** + * Tooltip 内容组件 - 显示详细的会员信息 + * 导出此组件供头像也使用相同的 Tooltip 内容 + */ +export const TooltipContent = ({ subscriptionInfo }) => { + const tooltipText = useColorModeValue('gray.700', 'gray.100'); + const dividerColor = useColorModeValue('gray.200', 'gray.600'); + const { type, days_left, is_active } = subscriptionInfo; + + // 基础版用户 + if (type === 'free') { + return ( + + + ✨ 基础版用户 + + + + 解锁更多高级功能 + + + 点击头像升级会员 + + + ); + } + + // 付费用户 + const isExpired = !is_active; + const isUrgent = days_left < 7; + const isWarning = days_left < 30; + + return ( + + + + {type === 'pro' ? '💎 Pro 会员' : '👑 Max 会员'} + + {isExpired && 已过期} + + + + + {/* 状态信息 */} + {isExpired ? ( + + + + 会员已过期,续费恢复权益 + + + ) : ( + + + + {isUrgent ? '⚠️' : isWarning ? '⏰' : '📅'} + + + {isUrgent && 紧急! } + 还有 {days_left} 天到期 + + + + 享受全部高级功能 + + + )} + + {/* 操作提示 */} + + {isExpired || isUrgent ? '点击头像立即续费' : '点击头像管理订阅'} + + + ); +}; + +/** + * 皇冠图标组件 - 显示在头像左上角的会员标识(纯图标,无 Tooltip) + * Tooltip 由外层统一包裹 + * + * @param {Object} subscriptionInfo - 订阅信息 + * @param {string} subscriptionInfo.type - 订阅类型: 'free' | 'pro' | 'max' + */ +export function CrownIcon({ subscriptionInfo }) { + // 基础版用户不显示皇冠 + if (subscriptionInfo.type === 'free') { + return null; + } + + return ( + + + {subscriptionInfo.type === 'max' ? '👑' : '💎'} + + + ); +} + +CrownIcon.propTypes = { + subscriptionInfo: PropTypes.shape({ + type: PropTypes.oneOf(['free', 'pro', 'max']).isRequired, + }).isRequired, +}; + +TooltipContent.propTypes = { + subscriptionInfo: PropTypes.shape({ + type: PropTypes.oneOf(['free', 'pro', 'max']).isRequired, + days_left: PropTypes.number, + is_active: PropTypes.bool, + }).isRequired, +};