ForgetPsdScreen.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. import { verify } from '../utils/SmsUtil';
  24. export default function ForgetPsdScreen({ navigation }: StackScreenProps) {
  25. const { changePsd } = useModel(Login, []);
  26. const { t } = useTranslation();
  27. const [phone, setPhone] = React.useState<string>('');
  28. const [code, setCode] = React.useState<string>('');
  29. const [password, setpassword] = React.useState<string>('');
  30. const [password2, setpassword2] = React.useState<string>('');
  31. const canSubmit = useCreation(() => {
  32. if (phone && code && password && password === password2) {
  33. return true;
  34. } else {
  35. return false;
  36. }
  37. }, [phone, code, password, password2]);
  38. function submit() {
  39. verify(phone, code).then((res) => {
  40. console.log(res);
  41. });
  42. }
  43. return (
  44. <Div bg="gray100" flex={1}>
  45. <ScrollView
  46. contentContainerStyle={{
  47. flexGrow: 1,
  48. backgroundColor: '#f2f2f2',
  49. }}
  50. >
  51. <Div
  52. bg="white"
  53. py={20}
  54. px={25}
  55. borderTopWidth={5}
  56. borderColor="gray100"
  57. flex={1}
  58. >
  59. <Div row alignItems="center" py={10}>
  60. <Text w={96} textAlign="right">
  61. {t('shou-ji-hao')}:
  62. </Text>
  63. <Div
  64. flex={1}
  65. bg="gray100"
  66. rounded="sm"
  67. px={15}
  68. ml={5}
  69. h={30}
  70. alignItems="stretch"
  71. >
  72. <TextInputMask
  73. type={'custom'}
  74. placeholderTextColor="#a6a6a6"
  75. px={12}
  76. value={phone}
  77. keyboardType="numeric"
  78. options={{
  79. mask: '999 9999 9999',
  80. }}
  81. onChangeText={(text) => {
  82. setPhone(text);
  83. }}
  84. style={{ flex: 1, fontSize: 14 }}
  85. placeholder={t('shu-ru-shou-ji-hao')}
  86. />
  87. {__DEV__ && (
  88. <Input
  89. onChangeText={(text) => {
  90. setPhone(text);
  91. }}
  92. />
  93. )}
  94. </Div>
  95. </Div>
  96. <SmsInput phone={phone} onCodeChange={setCode} />
  97. <Div row alignItems="center" py={10}>
  98. <Text w={96} textAlign="right">
  99. {t('mi-ma')}:
  100. </Text>
  101. <Input
  102. flex={1}
  103. bg="gray100"
  104. rounded="sm"
  105. loaderColor="gray400"
  106. px={12}
  107. ml={5}
  108. h={30}
  109. type={'custom'}
  110. value={password}
  111. borderWidth={0}
  112. fontSize="md"
  113. secureTextEntry
  114. opacity={1}
  115. loaderColor="gray400"
  116. color="gray900"
  117. onChangeText={(text) => {
  118. setpassword(text);
  119. }}
  120. style={{ flex: 1 }}
  121. placeholder={t('shu-ru-mi-ma')}
  122. />
  123. </Div>
  124. <Div row alignItems="center" py={10}>
  125. <Text w={96} textAlign="right">
  126. {t('que-ren-mi-ma')}:
  127. </Text>
  128. <Input
  129. flex={1}
  130. bg="gray100"
  131. rounded="sm"
  132. px={12}
  133. ml={5}
  134. h={30}
  135. type={'custom'}
  136. value={password2}
  137. borderWidth={0}
  138. fontSize="md"
  139. secureTextEntry
  140. opacity={1}
  141. loaderColor="gray400"
  142. color="gray900"
  143. onChangeText={(text) => {
  144. setpassword2(text);
  145. }}
  146. style={{ flex: 1 }}
  147. placeholder={t('zai-ci-shu-ru-que-ren-mi-ma')}
  148. />
  149. </Div>
  150. <Button
  151. w={112}
  152. bg="yellow500"
  153. alignSelf="center"
  154. fontSize="sm"
  155. my={20}
  156. disabled={!canSubmit}
  157. onPress={() =>
  158. changePsd(phone, code, password, () => {
  159. navigation.goBack();
  160. })
  161. }
  162. >
  163. {t('que-ding')}
  164. </Button>
  165. <Button
  166. w={112}
  167. color="yellow500"
  168. bg="none"
  169. borderColor="gray100"
  170. borderWidth={1}
  171. alignSelf="center"
  172. fontSize="sm"
  173. my={20}
  174. onPress={() => connect(navigation)}
  175. >
  176. {t('lian-xi-ke-fu')}
  177. </Button>
  178. </Div>
  179. </ScrollView>
  180. </Div>
  181. );
  182. }