LoginScreen.jsx 6.3 KB

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