Skip to content

Commit 7f3eb85

Browse files
author
z50902677
committed
新增登录action
1 parent fae79b9 commit 7f3eb85

File tree

4 files changed

+72
-31
lines changed

4 files changed

+72
-31
lines changed

src/actions/loginActions.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,32 @@
33
*/
44
import { createAction } from 'redux-actions';
55
import loginActionEnum from '../constants/loginActionEnum'
6-
6+
import {api} from '../apis/api'
77
const loginActions = {
8-
login: createAction(loginActionEnum.LOGIN_REQUEST)
8+
login: createAction(loginActionEnum.LOGIN_REQUEST),
9+
loginRequest: (data)=> {
10+
return dispatch=> {
11+
api.login(data)
12+
.then(response=> {
13+
if (response.ok) {
14+
return response;
15+
} else {
16+
console.warn("出错了");
17+
}
18+
})
19+
.then(response=>response.json())
20+
.then(jsonResult=> {
21+
if (jsonResult.errcode === 0) {
22+
console.warn(jsonResult.data);
23+
} else {
24+
console.warn(jsonResult.errmsg);
25+
}
26+
})
27+
.catch(error=> {
28+
console.warn(error);
29+
});
30+
}
31+
},
932
};
1033

1134
export default loginActions;

src/apis/api.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const api = {
66
`${appConfig.serviceRoot}service/man/userInfo/login`,
77
fetchMethod.Get,
88
{parameter: parameter}
9+
),
10+
login: (parameter)=> createFetch(
11+
`${appConfig.serviceRoot}app/login`,
12+
fetchMethod.Get,
13+
{parameter: parameter}
914
)
1015
};
1116

src/constants/appConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const appConfig = {
2-
serviceRoot: 'http://192.168.4.188:9000/'
2+
serviceRoot: 'http://192.168.56.1:3000/'
33
};
44

55
export default appConfig;

src/containers/android/Login.js

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
22
* Created by wangtun on 2016/7/21.
33
*/
4-
import React from 'react';
4+
import React,{Component} from 'react';
55
import {View, Text, StyleSheet,TextInput,Image} from "react-native";
66
import { connect } from 'react-redux'
7+
import {bindActionCreators} from 'redux'
78
import Button from "react-native-button";
89
import 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

94111
function mapStateToProps(state) {
@@ -100,11 +117,7 @@ function mapStateToProps(state) {
100117
}
101118

102119
function mapDispatchToProps(dispatch) {
103-
return {
104-
actions:{
105-
login:() => dispatch(loginActions.login())
106-
}
107-
}
120+
return bindActionCreators(loginActions, dispatch);
108121
}
109122

110123
export default connect(

0 commit comments

Comments
 (0)