11/**
22 * Created by wangtun on 2016/7/21.
33 */
4- import React from 'react' ;
4+ import React , { Component } from 'react' ;
55import { View , Text , StyleSheet , TextInput , Image } from "react-native" ;
66import { connect } from 'react-redux'
7+ import { bindActionCreators } from 'redux'
78import Button from "react-native-button" ;
89import loginActions from '../../actions/loginActions'
910
@@ -65,30 +66,46 @@ const styles = StyleSheet.create({
6566 } ,
6667} ) ;
6768
69+ class Login extends Component {
70+ constructor ( props ) {
71+ super ( props ) ;
72+ this . state = {
73+ } ;
74+ this . login = this . login . bind ( this ) ;
75+ }
76+ login ( ) {
77+ const username = this . refs . username . _lastNativeText ;
78+ const password = this . refs . password . _lastNativeText ;
79+ const data = {
80+ username : username ,
81+ password : password
82+ } ;
83+ this . props . loginRequest ( data ) ;
6884
69- const Login = ( props ) => {
70- const { login} = props . actions ;
71- return (
72- < View style = { styles . container } >
73- < View style = { styles . avatarview } >
74- < Image source = { require ( '../../image/logo.png' ) } style = { styles . avatarimage } />
75- < Text style = { styles . loginName } > 电 桩</ Text >
76- </ View >
77- < View style = { styles . driver } >
78- < TextInput placeholder = "请输入用户名" placeholderTextColor = '#E0E0E0' style = { styles . textinput } underlineColorAndroid = 'transparent'
79- keyboardType = 'default' >
80- </ TextInput >
81- </ View >
82- < View style = { styles . driver1 } >
83- < TextInput placeholder = "请输入密码" placeholderTextColor = '#E0E0E0' style = { styles . textinput } underlineColorAndroid = 'transparent'
84- secureTextEntry = { true } keyboardType = 'default' >
85- </ TextInput >
86- </ View >
87- < View style = { styles . buttonview } >
88- < Text style = { styles . logintext } > 登 录</ Text >
85+ }
86+ render ( ) {
87+ return (
88+ < View style = { styles . container } >
89+ < View style = { styles . avatarview } >
90+ < Image source = { require ( '../../image/logo.png' ) } style = { styles . avatarimage } />
91+ < Text style = { styles . loginName } > 电 桩</ Text >
92+ </ View >
93+ < View style = { styles . driver } >
94+ < TextInput placeholder = "请输入用户名" placeholderTextColor = '#E0E0E0' style = { styles . textinput } underlineColorAndroid = 'transparent'
95+ keyboardType = 'default' ref = "username" >
96+ </ TextInput >
97+ </ View >
98+ < View style = { styles . driver1 } >
99+ < TextInput placeholder = "请输入密码" placeholderTextColor = '#E0E0E0' style = { styles . textinput } underlineColorAndroid = 'transparent'
100+ secureTextEntry = { true } keyboardType = 'default' ref = "password" >
101+ </ TextInput >
102+ </ View >
103+ < View style = { styles . buttonview } >
104+ < Text style = { styles . logintext } onPress = { this . login } > 登 录</ Text >
105+ </ View >
89106 </ View >
90- </ View >
91- ) ;
107+ ) ;
108+ }
92109} ;
93110
94111function mapStateToProps ( state ) {
@@ -100,11 +117,7 @@ function mapStateToProps(state) {
100117}
101118
102119function mapDispatchToProps ( dispatch ) {
103- return {
104- actions :{
105- login :( ) => dispatch ( loginActions . login ( ) )
106- }
107- }
120+ return bindActionCreators ( loginActions , dispatch ) ;
108121}
109122
110123export default connect (
0 commit comments