NoticeScreen.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import { StackScreenProps } from '@react-navigation/stack';
  2. import * as React from 'react';
  3. import { useFocusEffect } from '@react-navigation/native';
  4. import { Div, Button, Image, Text, Avatar } from 'react-native-magnus';
  5. import { ScrollView, FlatList } from 'react-native-gesture-handler';
  6. import { useNavigation } from '@react-navigation/native';
  7. import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
  8. import Constants from 'expo-constants';
  9. import {useModel} from 'flooks';
  10. import { useMount } from 'ahooks';
  11. import IM from './model';
  12. import User from '../stores/User';
  13. import NoticeCom from './NoticeCom';
  14. import { SoundPlay } from '../utils/SoundUtils';
  15. const NoticeTab = createMaterialTopTabNavigator();
  16. export default function NoticeScreen({
  17. navigation,
  18. }: StackScreenProps) {
  19. const webRef = React.useRef();
  20. const { initChat } = useModel("IMModel");
  21. useFocusEffect(
  22. React.useCallback(() => {
  23. initChat();
  24. }, [])
  25. );
  26. return (
  27. <Div bg="gray100" flex={1}>
  28. <Div bg="yellow500" pt={Constants.statusBarHeight + 11} pb={11}>
  29. <Text color="white" textAlign="center" fontSize="xl" fontWeight="bold">
  30. 系统通知
  31. </Text>
  32. </Div>
  33. <NoticeTab.Navigator
  34. initialRouteName="Sys"
  35. style={{ flexGrow: 1 }}
  36. tabBarOptions={{
  37. inactiveTintColor: '#000',
  38. activeTintColor: '#FFC21C',
  39. indicatorStyle: { height: 0 },
  40. labelStyle: { fontSize: 15 },
  41. style: {
  42. backgroundColor: '#f2f2f2',
  43. elevation: 0,
  44. shadowOffset: {
  45. width: 0,
  46. height: 0,
  47. },
  48. shadowOpacity: 0,
  49. shadowRadius: 0,
  50. },
  51. }}
  52. >
  53. <NoticeTab.Screen
  54. name="Sys"
  55. component={SysNoticeScreen}
  56. options={{
  57. title: t('xi-tong-xiao-xi'),
  58. }}
  59. />
  60. <NoticeTab.Screen
  61. name="Chat"
  62. component={UserChatScreen}
  63. options={{
  64. title: t('yong-hu-xiao-xi'),
  65. }}
  66. />
  67. </NoticeTab.Navigator>
  68. </Div>
  69. );
  70. }
  71. function SysNoticeScreen({ navigation }) {
  72. const { sysNoticeList, sendPushNotification } = useModel(IM, [
  73. 'sysNoticeList',
  74. ]);
  75. const { t } = useTranslation();
  76. return (
  77. <>
  78. {/* <Button
  79. onPress={() => {
  80. sendPushNotification();
  81. SoundPlay('voice_664');
  82. }}
  83. >
  84. 发送系统消息
  85. </Button> */}
  86. <FlatList
  87. renderItem={({ item }) => {
  88. return (
  89. <NoticeCom
  90. info={item}
  91. type="email"
  92. onPress={() => {
  93. navigation.navigate('NoticeStack', {
  94. screen: 'EmailDetail',
  95. params: {
  96. emailId: item.id,
  97. },
  98. });
  99. }}
  100. />
  101. );
  102. }}
  103. data={sysNoticeList}
  104. keyExtractor={(item, index) => `email${index}`}
  105. ListEmptyComponent={() => {
  106. return (
  107. <Text color="gary200" fontSize="sm" textAlign="center" py={20}>
  108. 暂无数据
  109. </Text>
  110. );
  111. }}
  112. contentContainerStyle={{ flexGrow: 1, backgroundColor: '#fff' }}
  113. />
  114. </>
  115. );
  116. }
  117. function UserChatScreen({ navigation }) {
  118. const { chatList } = useModel(IM, ['chatList']);
  119. const { id } = useModel(User, ['id']);
  120. return (
  121. <FlatList
  122. renderItem={({ item }) => {
  123. const isReceive = item.receiveUserId === id;
  124. const toUserId = isReceive ? item.sendUserId : item.receiveUserId;
  125. const toUserName = isReceive ? item.sendNickname : item.receiveNickname;
  126. return (
  127. <NoticeCom
  128. info={item}
  129. userId={id}
  130. type="user"
  131. toUserName={toUserName}
  132. onPress={() => {
  133. navigation.navigate('NoticeStack', {
  134. screen: 'Chat',
  135. params: {
  136. toUserId,
  137. toUserName,
  138. },
  139. });
  140. }}
  141. />
  142. );
  143. }}
  144. data={chatList}
  145. keyExtractor={(item, index) => `chat${index}`}
  146. contentContainerStyle={{ flexGrow: 1, backgroundColor: '#fff' }}
  147. ListEmptyComponent={() => {
  148. return (
  149. <Text color="gary200" fontSize="sm" textAlign="center" py={20}>
  150. 暂无数据
  151. </Text>
  152. );
  153. }}
  154. />
  155. );
  156. }