welfare.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. <ImageBackground
  58. source={{ uri: Images.welfare.wealTitle }}
  59. style={styles.headSection}
  60. resizeMode="cover"
  61. >
  62. <Text style={styles.headTitle}>限时福利活动</Text>
  63. <Text style={styles.headText}>限时活动,不定时开放</Text>
  64. </ImageBackground>
  65. {/* 房间列表 */}
  66. {showSection && (
  67. <ScrollView
  68. style={styles.scrollView}
  69. showsVerticalScrollIndicator={false}
  70. contentContainerStyle={styles.scrollContent}
  71. >
  72. <TouchableOpacity
  73. style={styles.roomItem}
  74. onPress={() => handleRoomPress(0)}
  75. activeOpacity={0.8}
  76. >
  77. <Image
  78. source={{ uri: Images.welfare.indexItem1 }}
  79. style={styles.roomImage}
  80. contentFit="contain"
  81. />
  82. </TouchableOpacity>
  83. <TouchableOpacity
  84. style={styles.roomItem}
  85. onPress={() => handleRoomPress(1)}
  86. activeOpacity={0.8}
  87. >
  88. <Image
  89. source={{ uri: Images.welfare.indexItem2 }}
  90. style={styles.roomImage}
  91. contentFit="contain"
  92. />
  93. </TouchableOpacity>
  94. <TouchableOpacity
  95. style={styles.roomItem}
  96. onPress={() => handleRoomPress(2)}
  97. activeOpacity={0.8}
  98. >
  99. <Image
  100. source={{ uri: Images.welfare.indexItem3 }}
  101. style={styles.roomImage}
  102. contentFit="contain"
  103. />
  104. </TouchableOpacity>
  105. </ScrollView>
  106. )}
  107. {/* 底部占位 */}
  108. <View style={{ height: 120 }} />
  109. </ImageBackground>
  110. </View>
  111. );
  112. }
  113. const styles = StyleSheet.create({
  114. container: {
  115. flex: 1,
  116. backgroundColor: '#52504e',
  117. },
  118. background: {
  119. flex: 1,
  120. },
  121. header: {
  122. alignItems: 'center',
  123. position: 'absolute',
  124. top: 0,
  125. left: 0,
  126. right: 0,
  127. zIndex: 100,
  128. },
  129. title: {
  130. color: '#fff',
  131. fontSize: 16,
  132. fontWeight: 'bold',
  133. height: 40,
  134. lineHeight: 40,
  135. },
  136. headSection: {
  137. width: '100%',
  138. height: 192,
  139. alignItems: 'center',
  140. paddingTop: 90,
  141. },
  142. headTitle: {
  143. fontWeight: 'bold',
  144. fontSize: 40,
  145. color: '#FDF685',
  146. textShadowColor: '#E85801',
  147. textShadowOffset: { width: 1, height: 2 },
  148. textShadowRadius: 0,
  149. },
  150. headText: {
  151. fontSize: 15,
  152. color: '#E85801',
  153. marginTop: 5,
  154. textShadowColor: '#fff',
  155. textShadowOffset: { width: 1, height: 2 },
  156. textShadowRadius: 1,
  157. },
  158. scrollView: {
  159. flex: 1,
  160. marginTop: 15,
  161. },
  162. scrollContent: {
  163. paddingHorizontal: 0,
  164. alignItems: 'center',
  165. },
  166. roomItem: {
  167. marginBottom: 15,
  168. },
  169. roomImage: {
  170. width: 375,
  171. height: 130,
  172. },
  173. });