login.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import React, {Component} from 'react';
  2. import {StyleSheet, View, Image, StatusBar} from 'react-native';
  3. import {connect} from 'react-redux';
  4. import {Button, InputItem, List, Toast, Provider} 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. static navigationOptions = {
  17. headerShown: false, //隐藏顶部导航栏
  18. };
  19. componentDidMount() {
  20. }
  21. onLogin = () => {
  22. console.log('===>', this.state.username, this.state.password);
  23. if (!this.state.username || !this.state.password) {
  24. Toast.info('请输入用户名密码', 1);
  25. return;
  26. }
  27. this.props.dispatch({
  28. type: 'auth/login',
  29. payload: this.state,
  30. callback: () => {
  31. this.props.navigation.navigate('SalesHome');
  32. },
  33. unLogin: (msg) => {
  34. if (msg) {
  35. Toast.info(msg);
  36. }
  37. },
  38. });
  39. };
  40. render() {
  41. const {loading} = this.props.auth;
  42. return (
  43. <View style={styles.container}>
  44. <StatusBar backgroundColor={'#fff'} barStyle='dark-content'/>
  45. <Provider>
  46. <View style={styles.logoContainer}>
  47. <Image source={require('../../../assets/images/logo.png')} style={styles.logo}/>
  48. </View>
  49. <List style={styles.list}>
  50. <InputItem
  51. clear
  52. placeholder={'请输入用户名'}
  53. value={this.state.username}
  54. onChange={value => {
  55. this.setState({
  56. username: value,
  57. });
  58. }}
  59. >用户名:</InputItem>
  60. <InputItem
  61. clear
  62. placeholder={'请输入密码'}
  63. type="password"
  64. value={this.state.password}
  65. onChange={value => {
  66. this.setState({
  67. password: value,
  68. });
  69. }}
  70. >密码:</InputItem>
  71. </List>
  72. <Button loading={loading} disabled={loading} onPress={this.onLogin}
  73. style={styles.button}
  74. type="primary">登录</Button>
  75. </Provider>
  76. </View>
  77. );
  78. }
  79. }
  80. const styles = StyleSheet.create({
  81. tabText: {
  82. textAlign: 'center',
  83. paddingTop: 10,
  84. color: '#03C762',
  85. },
  86. button: {
  87. borderRadius: 10,
  88. margin: 10,
  89. borderWidth: 0,
  90. backgroundColor: '#2b90ea',
  91. },
  92. container: {
  93. flex: 1,
  94. backgroundColor: '#fff',
  95. },
  96. logoContainer: {
  97. alignItems: 'center',
  98. marginVertical: 60,
  99. },
  100. logo: {
  101. width: ScreenUtil.scaleSize(80),
  102. height: ScreenUtil.scaleSize(80),
  103. },
  104. list: {
  105. marginTop: 10,
  106. },
  107. });
  108. export default Login;