welfare.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import { Image } from 'expo-image';
  2. import { useRouter } from 'expo-router';
  3. import React, { useCallback, useEffect, useState } from 'react';
  4. import {
  5. ImageBackground,
  6. ScrollView,
  7. StatusBar,
  8. StyleSheet,
  9. Text,
  10. TouchableOpacity,
  11. View,
  12. } from 'react-native';
  13. import { useSafeAreaInsets } from 'react-native-safe-area-context';
  14. import { Images } from '@/constants/images';
  15. import { getUserInfo, UserInfo } from '@/services/user';
  16. export default function WelfareScreen() {
  17. const router = useRouter();
  18. const insets = useSafeAreaInsets();
  19. const [showSection, setShowSection] = useState(true);
  20. const [user, setUser] = useState<UserInfo | null>(null);
  21. const loadUserInfo = useCallback(async () => {
  22. try {
  23. const info = await getUserInfo();
  24. setUser(info);
  25. } catch (error) {
  26. console.error('获取用户信息失败:', error);
  27. }
  28. }, []);
  29. useEffect(() => {
  30. loadUserInfo();
  31. }, [loadUserInfo]);
  32. const handleRoomPress = (type: number) => {
  33. if (type === 0) {
  34. // 福利房间
  35. router.push('/weal/room' as any);
  36. } else if (type === 1) {
  37. // 扭蛋机
  38. router.push('/weal/catchDoll' as any);
  39. } else {
  40. // 祈愿
  41. router.push('/weal/wish' as any);
  42. }
  43. };
  44. return (
  45. <View style={styles.container}>
  46. <StatusBar barStyle="light-content" />
  47. <ImageBackground
  48. source={{ uri: Images.mine.kaixinMineBg }}
  49. style={styles.background}
  50. resizeMode="cover"
  51. >
  52. {/* 顶部导航 */}
  53. <View style={[styles.header, { paddingTop: insets.top + 50 }]}>
  54. <Text style={styles.title}>福利</Text>
  55. </View>
  56. {/* 标题区域 */}
  57. <View style={styles.headSection}>
  58. <Text style={styles.headTitle}>限时福利活动</Text>
  59. <Text style={styles.headText}>限时活动,不定时开放</Text>
  60. </View>
  61. {/* 房间列表 */}
  62. {showSection && (
  63. <ScrollView
  64. style={styles.scrollView}
  65. showsVerticalScrollIndicator={false}
  66. contentContainerStyle={styles.scrollContent}
  67. >
  68. <TouchableOpacity
  69. style={styles.roomItem}
  70. onPress={() => handleRoomPress(0)}
  71. activeOpacity={0.8}
  72. >
  73. <Image
  74. source={{ uri: Images.welfare.kaixinRoom1 }}
  75. style={styles.roomImage}
  76. contentFit="contain"
  77. />
  78. </TouchableOpacity>
  79. <TouchableOpacity
  80. style={styles.roomItem}
  81. onPress={() => handleRoomPress(1)}
  82. activeOpacity={0.8}
  83. >
  84. <Image
  85. source={{ uri: Images.welfare.kaixinRoom2 }}
  86. style={styles.roomImage}
  87. contentFit="contain"
  88. />
  89. </TouchableOpacity>
  90. <TouchableOpacity
  91. style={styles.roomItem}
  92. onPress={() => handleRoomPress(2)}
  93. activeOpacity={0.8}
  94. >
  95. <Image
  96. source={{ uri: Images.welfare.kaixinRoom3 }}
  97. style={styles.roomImage}
  98. contentFit="contain"
  99. />
  100. </TouchableOpacity>
  101. </ScrollView>
  102. )}
  103. {/* 底部占位 */}
  104. <View style={{ height: 120 }} />
  105. </ImageBackground>
  106. </View>
  107. );
  108. }
  109. const styles = StyleSheet.create({
  110. container: {
  111. flex: 1,
  112. backgroundColor: '#52504e',
  113. },
  114. background: {
  115. flex: 1,
  116. },
  117. header: {
  118. alignItems: 'center',
  119. position: 'absolute',
  120. top: 0,
  121. left: 0,
  122. right: 0,
  123. zIndex: 100,
  124. },
  125. title: {
  126. color: '#fff',
  127. fontSize: 16,
  128. fontWeight: 'bold',
  129. height: 40,
  130. lineHeight: 40,
  131. },
  132. headSection: {
  133. width: '100%',
  134. height: 192,
  135. alignItems: 'center',
  136. paddingTop: 90,
  137. },
  138. headTitle: {
  139. fontWeight: 'bold',
  140. fontSize: 40,
  141. color: '#FDF685',
  142. textShadowColor: '#E85801',
  143. textShadowOffset: { width: 1, height: 2 },
  144. textShadowRadius: 0,
  145. },
  146. headText: {
  147. fontSize: 15,
  148. color: '#E85801',
  149. marginTop: 5,
  150. },
  151. scrollView: {
  152. flex: 1,
  153. marginTop: 15,
  154. },
  155. scrollContent: {
  156. paddingHorizontal: 0,
  157. alignItems: 'center',
  158. },
  159. roomItem: {
  160. marginBottom: 15,
  161. },
  162. roomImage: {
  163. width: 375,
  164. height: 130,
  165. },
  166. });