LoginScreen.tsx 7.5 KB

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