Login.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React, { Component } from 'react'
  2. import { StyleSheet, View, Text, Alert, TouchableOpacity, Image } from 'react-native'
  3. import { connect } from 'react-redux'
  4. import { Button, InputItem, List, WhiteSpace, WingBlank } from '@ant-design/react-native';
  5. import { createAction, ScreenUtil } from '../../utils'
  6. import {NavigationActions} from "react-navigation";
  7. @connect(auth => ({...auth}))
  8. class Login extends Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. username: '',
  13. password: ''
  14. };
  15. }
  16. onLogin = () => {
  17. if(this.state.username == ''){
  18. Alert.alert('提示', '请输入用户名!');
  19. return
  20. }
  21. if(this.state.password == ''){
  22. Alert.alert('提示', '请输入密码!');
  23. return
  24. }
  25. this.props.dispatch(createAction('auth/login')(this.state))
  26. }
  27. renderMessage = content => (
  28. <Text style={{ marginBottom: 24 }}>{content}</Text>
  29. );
  30. render() {
  31. const {
  32. loading,
  33. } = this.props.auth
  34. return (
  35. <View style={styles.container}>
  36. <View style={styles.logoContainer}>
  37. <Image source={require('../../../assets/images/logo.png')} style={styles.logo}/>
  38. </View>
  39. <WhiteSpace size="xl" />
  40. <List style={styles.list}>
  41. <InputItem
  42. clear
  43. value={this.state.username}
  44. onChange={value => {
  45. this.setState({
  46. username:value,
  47. });
  48. }}
  49. >用户名:</InputItem>
  50. <InputItem
  51. clear
  52. type="password"
  53. value={this.state.password}
  54. onChange={value => {
  55. this.setState({
  56. password:value,
  57. });
  58. }}
  59. >密码:</InputItem>
  60. </List>
  61. <WhiteSpace />
  62. <WingBlank>
  63. <Button loading={loading} onPress={this.onLogin} type="primary">登录</Button>
  64. </WingBlank>
  65. </View>
  66. )
  67. }
  68. }
  69. const styles = StyleSheet.create({
  70. container:{
  71. flex:1,
  72. },
  73. logoContainer:{
  74. alignItems:'center',
  75. marginTop: 60
  76. },
  77. logo: {
  78. width:ScreenUtil.scaleSize(80),
  79. height:ScreenUtil.scaleSize(80),
  80. },
  81. list: {
  82. marginTop: 10
  83. }
  84. })
  85. export default Login