|
@@ -61,46 +61,50 @@ class LoginComponent extends React.Component {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
fetching: true
|
|
fetching: true
|
|
|
}, () => {
|
|
}, () => {
|
|
|
- service.fetch({
|
|
|
|
|
- url: URLS.LOGIN,
|
|
|
|
|
- body: body
|
|
|
|
|
- }).then(r => {
|
|
|
|
|
- if(!r.err && r.data.code > 0) {
|
|
|
|
|
- return r.data.data;
|
|
|
|
|
- }else {
|
|
|
|
|
- this.setState({
|
|
|
|
|
- notice: r.err || r.data.msg,
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ service.fetch({
|
|
|
|
|
+ url: URLS.LOGIN,
|
|
|
|
|
+ body: body
|
|
|
|
|
+ }).then(r => {
|
|
|
|
|
+ console.log('登录', body, r);
|
|
|
|
|
+ if(!r.err && r.data.code > 0) {
|
|
|
|
|
+ return r.data.data;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ notice: r.err || r.data.msg,
|
|
|
|
|
+ });
|
|
|
|
|
+ throw (r.err || r.data.msg);
|
|
|
|
|
+ }
|
|
|
|
|
+ }).then(resData => {
|
|
|
|
|
+ const token = resData.token;
|
|
|
|
|
+ const expireTime = resData.times;
|
|
|
|
|
+ const user = resData.user;
|
|
|
|
|
+ const currentUser = {
|
|
|
|
|
+ code: user.id+'',
|
|
|
|
|
+ account: user.userName,
|
|
|
|
|
+ password: user.passWord,
|
|
|
|
|
+ name: user.name,
|
|
|
|
|
+ role: user.role || 'default',
|
|
|
|
|
+ department: user.department,
|
|
|
|
|
+ job: user.post,
|
|
|
|
|
+ };
|
|
|
|
|
+ dispatch({ type: 'main/setCurrentUser', user: currentUser });
|
|
|
|
|
+ authenticate(token, expireTime, currentUser, autoLogin, () => {
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ redirectToReferrer: true,
|
|
|
|
|
+ fetching: false
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- throw (r.err || r.data.msg);
|
|
|
|
|
- }
|
|
|
|
|
- }).then(resData => {
|
|
|
|
|
- console.log('登录', body, resData);
|
|
|
|
|
- const token = resData.token;
|
|
|
|
|
- const expireTime = resData.times;
|
|
|
|
|
- const user = resData.user;
|
|
|
|
|
- const currentUser = {
|
|
|
|
|
- code: user.id+'',
|
|
|
|
|
- account: user.userName,
|
|
|
|
|
- password: user.passWord,
|
|
|
|
|
- name: user.name,
|
|
|
|
|
- role: user.role || 'default',
|
|
|
|
|
- department: user.department,
|
|
|
|
|
- job: user.post,
|
|
|
|
|
- };
|
|
|
|
|
- dispatch({ type: 'main/setCurrentUser', user: currentUser });
|
|
|
|
|
- authenticate(token, expireTime, currentUser, autoLogin, () => {
|
|
|
|
|
|
|
+ }).catch(ex => {
|
|
|
|
|
+ console.error('登录失败', ex);
|
|
|
this.setState({
|
|
this.setState({
|
|
|
- redirectToReferrer: true,
|
|
|
|
|
|
|
+ notice: (ex || ex.message ) || '登录失败',
|
|
|
fetching: false
|
|
fetching: false
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
- }).catch(ex => {
|
|
|
|
|
- console.error('登录失败', ex);
|
|
|
|
|
- this.setState({
|
|
|
|
|
- notice: (ex || ex.message ) || '登录失败',
|
|
|
|
|
- fetching: false
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ }catch(e) {
|
|
|
|
|
+ console.error(e);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|