-
Notifications
You must be signed in to change notification settings - Fork 6
/
signup.tsx
110 lines (106 loc) · 2.84 KB
/
signup.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React, { Component } from 'react';
import { List, Button, WhiteSpace, WingBlank, InputItem } from 'antd-mobile';
import { createForm } from 'rc-form';
import event from 'utils/event';
interface Props {
form?: any;
}
interface State {
isSignupShow: boolean;
}
@createForm()
class Signup extends Component<Props, State> {
constructor(props) {
super(props);
this.state = {
isSignupShow: false
};
}
componentDidMount() {
event.on('showSignup', bool => {
this.setState({ isSignupShow: bool });
});
}
handleSubmit = e => {
const {
form: { validateFields, getFieldValue }
} = this.props;
e.preventDefault();
validateFields(async (err, values) => {
if (!err) {
console.log('Received values of form: ', values);
const query = {
username: getFieldValue('username'),
password: getFieldValue('password'),
repeatPwd: getFieldValue('repeatPwd')
};
const url = window.$api.user.signup;
try {
await window.$http.put(url, { query });
event.emit('showSignup', false);
event.emit('showLogin', true);
} catch (err) {
window.$commonErrorHandler(url)(err);
}
}
});
};
render() {
const { getFieldProps } = this.props.form;
const { isSignupShow } = this.state;
const signupHtml = () => (
<div className="login">
<div
onClick={() => this.setState({ isSignupShow: false })}
className="mask"
/>
<div className="login-form">
<WingBlank>
<p className="flex-box">注册</p>
<List>
<InputItem
{...getFieldProps('username')}
type="text"
placeholder="用户名"
clear
moneyKeyboardAlign="left"
/>
</List>
<WhiteSpace />
<List>
<InputItem
{...getFieldProps('password')}
type="password"
placeholder="密码"
clear
moneyKeyboardAlign="left"
/>
</List>
<WhiteSpace />
<List>
<InputItem
{...getFieldProps('repeatPwd')}
type="password"
placeholder="确认密码"
clear
moneyKeyboardAlign="left"
/>
</List>
<WhiteSpace />
<List>
<Button
onClick={this.handleSubmit}
type="primary"
style={{ color: '#fff' }}
>
注册
</Button>
</List>
</WingBlank>
</div>
</div>
);
return <div>{isSignupShow ? signupHtml() : null}</div>;
}
}
export default Signup;