RegisterScreen.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import { StackScreenProps } from '@react-navigation/stack';
  2. import * as React from 'react';
  3. import {
  4. Div,
  5. Button,
  6. Image,
  7. Text,
  8. Avatar,
  9. Input,
  10. Icon,
  11. Radio,
  12. } from 'react-native-magnus';
  13. import { TextInputMask } from 'react-native-masked-text';
  14. import { ScrollView } from 'react-native-gesture-handler';
  15. import { useTranslation } from 'react-i18next';
  16. import { useCreation } from 'ahooks';
  17. import useModel from 'flooks';
  18. import Login from './model';
  19. import { MainStackParamList } from '../types';
  20. import { connect } from '../utils/SystemUtils';
  21. import Navigation from '../navigation/LoginStackNavigator';
  22. import SmsInput from '../components/SmsInput';
  23. export default function RegisterScreen({
  24. navigation,
  25. }: StackScreenProps<MainStackParamList, 'Login'>) {
  26. navigation.setOptions({
  27. headerLeft: (props) => (
  28. <Button
  29. bg="none"
  30. px={15}
  31. py={0}
  32. onPress={() => {
  33. navigation.goBack();
  34. }}
  35. >
  36. <Image w={50} h={50} source={require('../assets/images/logo.png')} />
  37. </Button>
  38. ),
  39. });
  40. const { loginByRegister } = useModel(Login, []);
  41. const { t } = useTranslation();
  42. const [phone, setPhone] = React.useState<string>('');
  43. const [code, setCode] = React.useState<string>('');
  44. const [password, setpassword] = React.useState<string>('');
  45. const [password2, setpassword2] = React.useState<string>('');
  46. const [sure, setSure] = React.useState<boolean>(false);
  47. const canSubmit = useCreation(() => {
  48. if (phone && code && password && password === password2 && sure) {
  49. return true;
  50. } else {
  51. return false;
  52. }
  53. }, [phone, code, password, password2, sure]);
  54. return (
  55. <Div bg="gray100" flex={1}>
  56. <ScrollView
  57. contentContainerStyle={{
  58. flexGrow: 1,
  59. backgroundColor: '#f2f2f2',
  60. }}
  61. >
  62. <Div
  63. bg="white"
  64. py={20}
  65. px={10}
  66. borderTopWidth={5}
  67. borderColor="gray100"
  68. >
  69. <Text textAlign="center">{t('guide1')}!</Text>
  70. <Text textAlign="center">{t('guide2')}</Text>
  71. </Div>
  72. <Div
  73. bg="white"
  74. py={20}
  75. px={25}
  76. borderTopWidth={5}
  77. borderColor="gray100"
  78. flex={1}
  79. >
  80. <Div row alignItems="center" py={10}>
  81. <Text w={96} textAlign="right">
  82. {t('shou-ji-hao')}:
  83. </Text>
  84. <Div
  85. flex={1}
  86. bg="gray100"
  87. rounded="sm"
  88. px={15}
  89. ml={5}
  90. h={30}
  91. alignItems="stretch"
  92. >
  93. <TextInputMask
  94. type={'custom'}
  95. placeholderTextColor="#a6a6a6"
  96. px={12}
  97. value={phone}
  98. keyboardType="numeric"
  99. options={{
  100. mask: '999 9999 9999',
  101. }}
  102. onChangeText={(text) => {
  103. setPhone(text);
  104. }}
  105. style={{ flex: 1, fontSize: 14 }}
  106. placeholder={t('shu-ru-shou-ji-hao')}
  107. />
  108. {__DEV__ && (
  109. <Input
  110. onChangeText={(text) => {
  111. setPhone(text);
  112. }}
  113. />
  114. )}
  115. </Div>
  116. </Div>
  117. {/* <Div row alignItems="center" py={10}>
  118. <Text w={96} textAlign="right">
  119. {t('yan-zheng-ma')}:
  120. </Text>
  121. <Div
  122. flex={1}
  123. bg="gray100"
  124. rounded="sm"
  125. px={15}
  126. ml={5}
  127. h={30}
  128. alignItems="stretch"
  129. >
  130. <TextInputMask
  131. type={'custom'}
  132. value={code}
  133. keyboardType="numeric"
  134. placeholderTextColor="#a6a6a6"
  135. options={{
  136. mask: '999999',
  137. }}
  138. onChangeText={(text) => {
  139. setCode(text);
  140. }}
  141. style={{ flex: 1, fontSize: 14 }}
  142. placeholder={t('shu-ru-yan-zheng-ma')}
  143. />
  144. </Div>
  145. </Div> */}
  146. <SmsInput phone={phone} onCodeChange={setCode} />
  147. <Div row alignItems="center" py={10}>
  148. <Text w={96} textAlign="right">
  149. {t('mi-ma')}:
  150. </Text>
  151. <Input
  152. flex={1}
  153. bg="gray100"
  154. rounded="sm"
  155. loaderColor="gray400"
  156. px={12}
  157. ml={5}
  158. h={30}
  159. type={'custom'}
  160. value={password}
  161. borderWidth={0}
  162. fontSize="md"
  163. secureTextEntry
  164. opacity={1}
  165. loaderColor="gray400"
  166. color="gray900"
  167. onChangeText={(text) => {
  168. setpassword(text);
  169. }}
  170. style={{ flex: 1 }}
  171. placeholder={t('shu-ru-mi-ma')}
  172. />
  173. </Div>
  174. <Div row alignItems="center" py={10}>
  175. <Text w={96} textAlign="right">
  176. {t('que-ren-mi-ma')}:
  177. </Text>
  178. <Input
  179. flex={1}
  180. bg="gray100"
  181. rounded="sm"
  182. px={12}
  183. ml={5}
  184. h={30}
  185. type={'custom'}
  186. value={password2}
  187. borderWidth={0}
  188. fontSize="md"
  189. secureTextEntry
  190. opacity={1}
  191. loaderColor="gray400"
  192. color="gray900"
  193. onChangeText={(text) => {
  194. setpassword2(text);
  195. }}
  196. style={{ flex: 1 }}
  197. placeholder={t('zai-ci-shu-ru-que-ren-mi-ma')}
  198. />
  199. </Div>
  200. <Button bg="white" block mt={20} onPress={() => setSure(!sure)}>
  201. <Div row alignItems="center" flex={1} justifyContent="center">
  202. <Icon
  203. fontFamily="Ionicons"
  204. ml={30}
  205. color={sure ? 'yellow500' : 'gray400'}
  206. name={sure ? 'ios-radio-button-on' : 'ios-radio-button-off'}
  207. />
  208. <Div row flexWrap="wrap" ml={15} flex={1}>
  209. <Text color="gray400" fontSize="xs">
  210. {t('yi-jing-yue-du-bing-tong-yi')}
  211. </Text>
  212. <Button bg="none" color="yellow300" fontSize="sm" p={0}>
  213. {t('ding-dong-wai-mai-qi-shou-zhu-ce-xie-yi')}
  214. </Button>
  215. <Text color="gray400" fontSize="xs">
  216. {t('he')}
  217. </Text>
  218. <Button bg="none" color="yellow300" p={0} fontSize="sm">
  219. {t('ding-dong-wai-mai-qi-shou-yin-si-zheng-ce')}
  220. </Button>
  221. </Div>
  222. </Div>
  223. </Button>
  224. <Button
  225. w={112}
  226. bg="yellow500"
  227. alignSelf="center"
  228. fontSize="sm"
  229. my={20}
  230. disabled={!canSubmit}
  231. onPress={() => loginByRegister(phone, password, code)}
  232. >
  233. {t('xia-yi-bu')}
  234. </Button>
  235. <Button
  236. w={112}
  237. color="yellow500"
  238. bg="none"
  239. borderColor="gray100"
  240. borderWidth={1}
  241. alignSelf="center"
  242. fontSize="sm"
  243. my={20}
  244. onPress={() => connect(navigation)}
  245. >
  246. {t('lian-xi-ke-fu')}
  247. </Button>
  248. </Div>
  249. </ScrollView>
  250. </Div>
  251. );
  252. }