Files
rn-app/pages/HomeScreen/index.tsx

158 lines
3.8 KiB
TypeScript
Raw Normal View History

2025-11-11 18:48:54 +08:00
/**
2025-11-12 00:13:26 +08:00
*
* HeaderBottomTabs
*
2025-11-11 18:48:54 +08:00
*/
2025-11-12 00:13:26 +08:00
import React, { useState, useEffect, useCallback } from 'react';
import { View, ScrollView, RefreshControl, Alert } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { createThemeStyles, useColorScheme, useThemeInfo } from '@/theme';
import {
Header,
BannerSwiper,
NoticeBar,
GameMainMenus,
Lobby,
HighPrizeGame,
FastFootNav,
} from './components';
import { requestHomePageData } from '@/stores/gameStore';
import { useTenantLoad } from '@/stores/tenantStore';
import type {
Banner,
Notice,
GameCategory,
Game,
HighPrizeGame as HighPrizeGameType,
} from '@/types/home';
2025-11-11 18:48:54 +08:00
/**
*
*/
const styles = createThemeStyles((colors) => ({
container: {
flex: 1,
backgroundColor: colors.background,
},
2025-11-12 00:13:26 +08:00
contentContainer: {
2025-11-11 18:48:54 +08:00
flex: 1,
},
2025-11-12 00:13:26 +08:00
scrollContent: {
paddingBottom: 20,
},
2025-11-11 18:48:54 +08:00
}));
2025-11-12 00:13:26 +08:00
2025-11-11 18:48:54 +08:00
/**
2025-11-12 00:13:26 +08:00
*
2025-11-11 18:48:54 +08:00
*/
2025-11-12 00:13:26 +08:00
export default function HomePage() {
const colorScheme = useColorScheme();
const s = styles[colorScheme];
const { isDark: isDarkTheme, colors } = useThemeInfo();
const [refreshing, setRefreshing] = useState(false);
const tenantLoad = useTenantLoad();
2025-11-11 18:48:54 +08:00
2025-11-12 00:13:26 +08:00
// 加载首页数据
const loadHomePageData = useCallback(async () => {
try {
await requestHomePageData();
} catch (error) {
console.error('加载首页数据失败:', error);
}
}, []);
// 初始化加载
useEffect(() => {
console.log('租户数据加载完成:', tenantLoad);
if (tenantLoad) {
loadHomePageData();
}
}, [loadHomePageData, tenantLoad]);
// 下拉刷新
const handleRefresh = useCallback(async () => {
2025-11-11 18:48:54 +08:00
setRefreshing(true);
2025-11-12 00:13:26 +08:00
try {
await loadHomePageData();
} finally {
2025-11-11 18:48:54 +08:00
setRefreshing(false);
2025-11-12 00:13:26 +08:00
}
}, [loadHomePageData]);
// 处理游戏点击
const handleGamePress = useCallback((game: Game) => {
Alert.alert('游戏', `点击了: ${game.play_up_name}`);
// 这里可以添加打开游戏的逻辑
2025-11-11 18:48:54 +08:00
}, []);
2025-11-12 00:13:26 +08:00
// 处理底部 Tab 点击
const handleTabPress = useCallback((tabId: string, action: string) => {
Alert.alert('导航', `点击了: ${tabId}`);
// 这里可以添加导航逻辑
}, []);
// 处理搜索
const handleSearch = useCallback((keyword: string) => {
Alert.alert('搜索', `搜索关键词: ${keyword}`);
// 这里可以添加搜索逻辑
}, []);
// 根据主题选择要显示的组件
const renderContent = () => {
if (isDarkTheme) {
// 深色主题布局
return (
<>
<GameMainMenus />
<BannerSwiper />
<NoticeBar />
<HighPrizeGame onGamePress={handleGamePress} />
<Lobby onGamePress={handleGamePress} />
<FastFootNav onTabPress={handleTabPress} />
</>
);
} else {
// 浅色主题布局
return (
<>
<BannerSwiper />
<NoticeBar />
<GameMainMenus />
<Lobby onGamePress={handleGamePress} />
</>
);
}
};
2025-11-11 18:48:54 +08:00
return (
2025-11-12 00:13:26 +08:00
<SafeAreaView style={s.container}>
{/* Header */}
<Header
onSearch={handleSearch}
onMessagePress={() => Alert.alert('消息', '消息功能')}
onUserPress={() => Alert.alert('用户', '用户中心')}
unreadCount={3}
/>
{/* 内容区域 */}
<View style={s.contentContainer}>
<ScrollView
style={s.contentContainer}
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.primary}
/>
}
showsVerticalScrollIndicator={false}
>
<View style={s.scrollContent}>{renderContent()}</View>
</ScrollView>
</View>
</SafeAreaView>
2025-11-11 18:48:54 +08:00
);
}