/** * Header 组件 - 增强版 * 基于 xinyong-web 的 header 组件重建 * 功能包括: * - 顶部导航栏(logo、搜索、用户按钮) * - 左侧菜单(侧边栏) * - 登录/注册弹窗 * - 钱包信息显示 * - 主题适配 */ import React, { useState, useCallback, useMemo } from 'react'; import { View, Text, StyleSheet, TouchableOpacity, TextInput, Image, Dimensions, Modal, ScrollView, SafeAreaView, } from 'react-native'; import { useColorScheme, useThemeColors } from '@/theme'; import { useIsLoggedIn, useUser } from '@/stores/userStore'; import { useLogo } from '@/stores/tenantStore'; import { Ionicons, AntDesign } from '@expo/vector-icons'; import LeftMenu from './LeftMenu'; import LoginRegisterModal from './LoginRegisterModal'; import WalletAmount from '../WalletAmount'; import { styles } from './styles'; const { width } = Dimensions.get('window'); interface HeaderProps { onSearch?: (keyword: string) => void; onMessagePress?: () => void; onMenuPress?: () => void; unreadCount?: number; } /** * Header 组件 - 增强版 */ export default function Header({ onSearch, onMessagePress, onMenuPress, unreadCount = 0, }: HeaderProps) { const colorScheme = useColorScheme(); const s = styles[colorScheme]; const themeColors = useThemeColors(); const isLoggedIn = useIsLoggedIn(); const user = useUser(); const logoUrl = useLogo(); const [searchText, setSearchText] = useState(''); const [showLeftMenu, setShowLeftMenu] = useState(false); const [showLoginModal, setShowLoginModal] = useState(false); const handleSearch = useCallback(() => { if (searchText.trim()) { onSearch?.(searchText); setSearchText(''); } }, [searchText, onSearch]); const handleMenuPress = useCallback(() => { setShowLeftMenu(true); onMenuPress?.(); }, [onMenuPress]); const handleLoginPress = useCallback(() => { setShowLoginModal(true); }, []); return ( <> {/* 左侧部分 */} {/* 菜单按钮 */} {/* Logo */} {logoUrl ? : null} {/* 搜索框 */} {/**/} {/* */} {/* */} {/* {searchText ? (*/} {/* setSearchText('')}>*/} {/* */} {/* */} {/* ) : null}*/} {/**/} {/* 右侧部分 */} {isLoggedIn && user ? ( <> {/* 消息按钮 */} {unreadCount > 0 && ( {unreadCount > 99 ? '99+' : unreadCount} )} {/* 用户头像 */} {user.avatar ? ( ) : ( )} ) : ( /* 登录/注册按钮 */ setShowLoginModal(true)} activeOpacity={0.7} > 注册 setShowLoginModal(true)} activeOpacity={0.7} > 登录 )} {/* 左侧菜单 */} setShowLeftMenu(false)} /> {/* 登录/注册弹窗 */} setShowLoginModal(false)} /> ); }