LoginScreen.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. import { StackScreenProps } from '@react-navigation/stack';
  2. import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
  3. import * as React from 'react';
  4. import { Div, Button, Image, Text, Avatar, Input } from 'react-native-magnus';
  5. import { ScrollView } from 'react-native-gesture-handler';
  6. import { TextInputMask } from 'react-native-masked-text';
  7. import { useMount } from 'ahooks';
  8. import { useNavigation } from '@react-navigation/native';
  9. import { useTranslation } from 'react-i18next';
  10. import useModel from 'flooks';
  11. import { MainStackParamList, LoginTabParamList } from '../types';
  12. import Navigation from '../navigation';
  13. import Login from './model';
  14. const LoginTab = createMaterialTopTabNavigator<LoginTabParamList>();
  15. export default function LoginScreen({
  16. navigation,
  17. }: StackScreenProps<MainStackParamList, 'Login'>) {
  18. const { t } = useTranslation();
  19. return (
  20. <Div flex={1} bg="yellow200">
  21. <ScrollView
  22. contentContainerStyle={{
  23. flexGrow: 1,
  24. backgroundColor: '#FFF2C7',
  25. justifyContent: 'center',
  26. }}
  27. keyboardDismissMode="on-drag"
  28. >
  29. <Div bg="white" mx={13} px={10} py={20} rounded="xs">
  30. <Image
  31. source={require('../assets/images/loginImg2.png')}
  32. alignSelf="center"
  33. w={217}
  34. h={100}
  35. />
  36. <Image
  37. source={require('../assets/images/loginImg.png')}
  38. w={275}
  39. h={60}
  40. position="absolute"
  41. top={-59}
  42. left="50%"
  43. ml={-137}
  44. zIndex={2}
  45. />
  46. <Div bg="white">
  47. <LoginTab.Navigator
  48. initialRouteName="Psd"
  49. tabBarOptions={{
  50. inactiveTintColor: '#000',
  51. activeTintColor: '#FFC21C',
  52. indicatorStyle: { height: 0 },
  53. labelStyle: { fontSize: 13 },
  54. }}
  55. >
  56. <LoginTab.Screen
  57. name="Psd"
  58. component={LoginByPsd}
  59. options={{
  60. title: t('mi-ma-deng-lu'),
  61. backgroundColor: '#fff',
  62. }}
  63. />
  64. <LoginTab.Screen
  65. name="Code"
  66. component={LoginByCode}
  67. options={{
  68. title: t('yan-zheng-ma-deng-lu'),
  69. }}
  70. />
  71. </LoginTab.Navigator>
  72. </Div>
  73. </Div>
  74. </ScrollView>
  75. </Div>
  76. );
  77. }
  78. function LoginByPsd() {
  79. const { t } = useTranslation();
  80. const [phone, setphone] = React.useState<string>('');
  81. const [password, setpassword] = React.useState<string>('');
  82. const navigation = useNavigation();
  83. const loginModel = useModel(Login, []);
  84. return (
  85. <Div bg="white">
  86. <Div row alignItems="center" py={10}>
  87. <Text w={96} textAlign="right">
  88. {t('shou-ji-hao')}:
  89. </Text>
  90. <Div
  91. flex={1}
  92. bg="gray100"
  93. rounded="sm"
  94. px={15}
  95. ml={5}
  96. h={30}
  97. alignItems="stretch"
  98. >
  99. <TextInputMask
  100. type={'custom'}
  101. value={phone}
  102. keyboardType="numeric"
  103. options={{
  104. mask: '999 9999 9999',
  105. }}
  106. onChangeText={(text) => {
  107. console.log(text);
  108. setphone(text);
  109. }}
  110. style={{ flex: 1, fontSize: 14 }}
  111. placeholderTextColor="#a6a6a6"
  112. placeholder={t('shu-ru-shang-jia-ming-cheng')}
  113. />
  114. </Div>
  115. </Div>
  116. <Div row alignItems="center" py={10}>
  117. <Text w={96} textAlign="right">
  118. {t('mi-ma')}:
  119. </Text>
  120. <Input
  121. flex={1}
  122. bg="gray100"
  123. rounded="sm"
  124. px={15}
  125. ml={5}
  126. h={30}
  127. type={'custom'}
  128. value={password}
  129. borderWidth={0}
  130. fontSize="md"
  131. opacity={1}
  132. loaderColor="gray400"
  133. color="gray900"
  134. secureTextEntry
  135. onChangeText={(text) => {
  136. console.log(text);
  137. setpassword(text);
  138. }}
  139. style={{ flex: 1 }}
  140. placeholder={t('shu-ru-mi-ma')}
  141. />
  142. </Div>
  143. <Div row justifyContent="space-between" pl={90}>
  144. <Button
  145. color="gray400"
  146. fontSize="sm"
  147. bg="white"
  148. onPress={() => navigation.navigate('ForgetPsd')}
  149. >
  150. {t('wang-ji-mi-ma')}
  151. </Button>
  152. <Button
  153. color="gray400"
  154. fontSize="sm"
  155. bg="white"
  156. onPress={() => navigation.navigate('Register')}
  157. >
  158. {t('qi-shou-zhu-ce')}
  159. </Button>
  160. </Div>
  161. <Button
  162. block
  163. bg="yellow500"
  164. w={112}
  165. fontSize="sm"
  166. ml={96}
  167. mt={10}
  168. onPress={() => {
  169. loginModel.loginByPsd();
  170. }}
  171. >
  172. {t('deng-lu')}
  173. </Button>
  174. </Div>
  175. );
  176. }
  177. function LoginByCode() {
  178. const { t } = useTranslation();
  179. const [phone, setphone] = React.useState<string>('');
  180. const [code, setCode] = React.useState<string>('');
  181. return (
  182. <Div bg="white">
  183. <Div row alignItems="center" py={10}>
  184. <Text w={96} textAlign="right">
  185. {t('shou-ji-hao')}:
  186. </Text>
  187. <Div
  188. flex={1}
  189. bg="gray100"
  190. rounded="sm"
  191. px={15}
  192. ml={5}
  193. h={30}
  194. alignItems="stretch"
  195. >
  196. <TextInputMask
  197. type={'custom'}
  198. value={phone}
  199. keyboardType="numeric"
  200. options={{
  201. mask: '999 9999 9999',
  202. }}
  203. onChangeText={(text) => {
  204. console.log(text);
  205. setphone(text);
  206. }}
  207. placeholderTextColor="#a6a6a6"
  208. style={{ flex: 1, fontSize: 14 }}
  209. placeholder={t('shu-ru-shou-ji-hao')}
  210. />
  211. </Div>
  212. </Div>
  213. <Div row alignItems="center" py={10}>
  214. <Text w={96} textAlign="right">
  215. {t('yan-zheng-ma')}:
  216. </Text>
  217. <Div
  218. flex={1}
  219. bg="gray100"
  220. rounded="sm"
  221. px={15}
  222. ml={5}
  223. h={30}
  224. alignItems="stretch"
  225. >
  226. <TextInputMask
  227. type={'custom'}
  228. value={code}
  229. keyboardType="numeric"
  230. options={{
  231. mask: '9999',
  232. }}
  233. onChangeText={(text) => {
  234. console.log(text);
  235. setCode(text);
  236. }}
  237. placeholderTextColor="#a6a6a6"
  238. style={{ flex: 1, fontSize: 14 }}
  239. placeholder={t('shu-ru-yan-zheng-ma')}
  240. />
  241. </Div>
  242. </Div>
  243. <Div row justifyContent="space-between" pl={90}>
  244. <Button color="gray400" fontSize="sm" bg="white">
  245. {t('wang-ji-mi-ma')}
  246. </Button>
  247. <Button color="gray400" fontSize="sm" bg="white">
  248. {t('qi-shou-zhu-ce')}
  249. </Button>
  250. </Div>
  251. <Button block bg="yellow500" w={112} fontSize="sm" ml={96} mt={10}>
  252. {t('deng-lu')}
  253. </Button>
  254. </Div>
  255. );
  256. }