LoginScreen.jsx 6.5 KB

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