LoginScreen.jsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StyleSheet, View, StatusBar, Platform, Image } from 'react-native';
  4. import { Flex, WingBlank, InputItem } from '@ant-design/react-native';
  5. import { Card, Paragraph, Caption } from 'react-native-paper';
  6. import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
  7. import useModel from 'flooks';
  8. import Toast from '../../flooks/Toast';
  9. import user from '../../flooks/User';
  10. import Button from '../../components/Button';
  11. const Tab = createMaterialTopTabNavigator();
  12. // const img = require('../../assets/images/loginImg.png')
  13. const img2 = require('../../assets/images/loginLogo.png');
  14. export default function LoginScreen({ navigation }) {
  15. const btnList = () => (
  16. <View style={styles.btn}>
  17. <Button
  18. text
  19. size="small"
  20. type="info"
  21. onPress={() => {
  22. navigation.navigate('BackPassword');
  23. }}
  24. >
  25. 忘记密码
  26. </Button>
  27. <Button
  28. text
  29. size="small"
  30. type="info"
  31. onPress={() => {
  32. navigation.navigate('Register');
  33. }}
  34. >
  35. 用户注册
  36. </Button>
  37. </View>
  38. );
  39. return (
  40. <>
  41. {Platform.OS !== 'ios' && <StatusBar backgroundColor="#FFF2C7" />}
  42. <View style={styles.container}>
  43. <WingBlank style={styles.container}>
  44. <Flex
  45. direction="column"
  46. justify="center"
  47. align="stretch"
  48. style={styles.container}
  49. >
  50. <Card style={styles.center}>
  51. <Image source={img2} style={styles.img2} resizeMode="contain" />
  52. <View style={styles.tab}>
  53. <Tab.Navigator
  54. tabBarOptions={{
  55. activeTintColor: '#FFC750',
  56. inactiveTintColor: '#000',
  57. indicatorStyle: {
  58. backgroundColor: '#FFC750',
  59. height: 0,
  60. },
  61. labelStyle: {
  62. fontSize: 16,
  63. },
  64. style: {
  65. backgroundColor: '#fff',
  66. height: 50,
  67. elevation: 0,
  68. shadowOffset: {
  69. width: 0,
  70. height: 0,
  71. },
  72. shadowOpacity: 0,
  73. shadowRadius: 0,
  74. borderBottomWidth: 1,
  75. borderColor: '#eee',
  76. },
  77. }}
  78. >
  79. <Tab.Screen
  80. name="密码登陆"
  81. component={LoginPassword}
  82. initialParams={{ btnList }}
  83. />
  84. <Tab.Screen
  85. name="验证码登陆"
  86. component={LoginCode}
  87. initialParams={{ btnList }}
  88. />
  89. </Tab.Navigator>
  90. </View>
  91. </Card>
  92. </Flex>
  93. </WingBlank>
  94. </View>
  95. </>
  96. );
  97. }
  98. const LoginPassword = ({ route }) => {
  99. const [phone, setphone] = React.useState();
  100. const [password, setPassword] = React.useState();
  101. const { warnning } = useModel(Toast, []);
  102. const { loginByPsd } = useModel(user, []);
  103. const { params } = route;
  104. const { btnList } = params || {};
  105. const submit = () => {
  106. if (!phone) {
  107. warnning('手机号不能为空');
  108. } else if (!password) {
  109. warnning('密码不能为空');
  110. } else {
  111. loginByPsd(phone, password);
  112. }
  113. };
  114. return (
  115. <View style={styles.list}>
  116. <InputItem
  117. clear
  118. type="phone"
  119. value={phone}
  120. onChange={setphone}
  121. placeholder="输入手机号"
  122. style={{ fontSize: 14 }}
  123. >
  124. <Paragraph>手机号</Paragraph>
  125. </InputItem>
  126. <InputItem
  127. clear
  128. type="password"
  129. value={password}
  130. onChange={setPassword}
  131. placeholder="输入密码"
  132. style={{ fontSize: 14 }}
  133. >
  134. <Paragraph>密码</Paragraph>
  135. </InputItem>
  136. {btnList()}
  137. <View style={[styles.btn, styles.sub]}>
  138. <Button onPress={submit}>登录</Button>
  139. </View>
  140. </View>
  141. );
  142. };
  143. const LoginCode = ({ route }) => {
  144. const [phone, setphone] = React.useState();
  145. const [code, setCode] = React.useState();
  146. const { warnning } = useModel(Toast, []);
  147. const { loginByPsd } = useModel(user, []);
  148. const { params } = route;
  149. const { btnList } = params || {};
  150. const submit = () => {
  151. if (!phone) {
  152. warnning('手机号不能为空');
  153. } else if (!code) {
  154. warnning('验证码');
  155. } else {
  156. loginByPsd(phone, code);
  157. }
  158. };
  159. return (
  160. <View style={styles.list}>
  161. <InputItem
  162. clear
  163. type="phone"
  164. value={phone}
  165. onChange={setphone}
  166. style={{ fontSize: 14 }}
  167. placeholder="输入手机号"
  168. >
  169. <Paragraph>手机号</Paragraph>
  170. </InputItem>
  171. <InputItem
  172. clear
  173. type="number"
  174. value={code}
  175. onChange={setCode}
  176. extra={<Caption style={{ color: '#FFC21C' }}>发送验证码</Caption>}
  177. placeholder="输入验证码"
  178. maxLength={6}
  179. style={{ fontSize: 14 }}
  180. onExtraClick={() => {
  181. console.log('发送验证码');
  182. }}
  183. >
  184. <Paragraph>验证码</Paragraph>
  185. </InputItem>
  186. {btnList()}
  187. <View style={[styles.btn, styles.sub]}>
  188. <Button onPress={submit}>登录</Button>
  189. </View>
  190. </View>
  191. );
  192. };
  193. const styles = StyleSheet.create({
  194. container: { flex: 1, backgroundColor: '#FFF2C7' },
  195. center: {
  196. paddingHorizontal: 10,
  197. // paddingVertical: 20,
  198. paddingTop: 20,
  199. backgroundColor: '#fff',
  200. borderRadius: 7,
  201. flexDirection: 'column',
  202. height: 380,
  203. },
  204. img2: {
  205. height: 90,
  206. backgroundColor: '#fff',
  207. width: '100%',
  208. // marginBottom: 20,
  209. },
  210. list: {
  211. backgroundColor: '#fff',
  212. borderWidth: 0,
  213. paddingTop: 10,
  214. height: 200,
  215. },
  216. tab: {
  217. flex: 1,
  218. backgroundColor: '#fff',
  219. paddingBottom: 20,
  220. },
  221. btn: {
  222. paddingLeft: 70,
  223. flexDirection: 'row',
  224. justifyContent: 'space-between',
  225. marginTop: 5,
  226. },
  227. sub: {
  228. marginTop: 10,
  229. marginLeft: 10,
  230. },
  231. });