|
| 1 | +import React from 'react' |
| 2 | +import {Input, InputAdornment, IconButton, Button, FormControl, Select, MenuItem, InputLabel} from '@material-ui/core' |
| 3 | +import { withStyles } from '@material-ui/core/styles' |
| 4 | +import {Visibility, VisibilityOff} from '@material-ui/icons' |
| 5 | + |
| 6 | +export interface Props { |
| 7 | + |
| 8 | +} |
| 9 | + |
| 10 | +interface State { |
| 11 | + showPassword: boolean; |
| 12 | + showEnterPassword: boolean; |
| 13 | + params: object; |
| 14 | + sendCode: boolean; |
| 15 | +} |
| 16 | + |
| 17 | +const StyledSelect = withStyles({ |
| 18 | + icon: { |
| 19 | + display: 'none' |
| 20 | + } |
| 21 | +})(Select); |
| 22 | + |
| 23 | +const styles = theme => ({ |
| 24 | + form: { |
| 25 | + padding: '0px 50px 50px 50px' |
| 26 | + }, |
| 27 | + formControl: { |
| 28 | + minWidth: 120, |
| 29 | + width: '100%', |
| 30 | + }, |
| 31 | + formSelectControl: { |
| 32 | + width: 'calc(50% - 6px)' |
| 33 | + }, |
| 34 | + formLeftSelectControl: { |
| 35 | + marginRight: 6 |
| 36 | + }, |
| 37 | + formRightSelectControl: { |
| 38 | + marginLeft: 6 |
| 39 | + }, |
| 40 | + input: { |
| 41 | + height: 60, |
| 42 | + marginTop: '0px !important', |
| 43 | + icon: { |
| 44 | + fontSize: 40 |
| 45 | + } |
| 46 | + }, |
| 47 | + button: { |
| 48 | + minWidth: 115, |
| 49 | + textAlign: 'right', |
| 50 | + color: '#FF40AEA8' |
| 51 | + }, |
| 52 | + submitButton: { |
| 53 | + marginTop: 50, |
| 54 | + borderRadius: 0, |
| 55 | + color: '#FFFFFF', |
| 56 | + width: '100%', |
| 57 | + backgroundColor: '#40AEA8', |
| 58 | + fontSize: 20 |
| 59 | + } |
| 60 | +}) |
| 61 | +class RegisterForm extends React.Component<Props, State> { |
| 62 | + |
| 63 | + constructor(props: Props) { |
| 64 | + super(props) |
| 65 | + this.state = { |
| 66 | + showPassword: false, |
| 67 | + showEnterPassword: false, |
| 68 | + sendCode: false, |
| 69 | + params: { |
| 70 | + exp: '', |
| 71 | + role: '' |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + handleSubmit = (e) => { |
| 77 | + e.preventDefault(); |
| 78 | + console.log(this.state.params) |
| 79 | + } |
| 80 | + |
| 81 | + sendCode = () => { |
| 82 | + this.setState({ |
| 83 | + sendCode: true |
| 84 | + }) |
| 85 | + } |
| 86 | + |
| 87 | + handleClickShowPassword(name: string) { |
| 88 | + this.setState({ |
| 89 | + [name]: !this.state[name] |
| 90 | + }) |
| 91 | + } |
| 92 | + |
| 93 | + inputChange = (e) => { |
| 94 | + const {name, value} = e.target |
| 95 | + this.setState({ |
| 96 | + params: Object.assign({}, this.state.params, {[name]: value}) |
| 97 | + }) |
| 98 | + } |
| 99 | + |
| 100 | + render() { |
| 101 | + const { classes } = this.props; |
| 102 | + const { showPassword, showEnterPassword, sendCode, params } = this.state |
| 103 | + const { role, exp } = params |
| 104 | + return ( |
| 105 | + <div className="register"> |
| 106 | + <form onSubmit={this.handleSubmit} className={classes.form}> |
| 107 | + <FormControl className={classes.formControl}> |
| 108 | + <Input |
| 109 | + name={'phone'} |
| 110 | + className={classes.input} |
| 111 | + placeholder="请输入邮箱或手机号" |
| 112 | + onChange={this.inputChange} |
| 113 | + /> |
| 114 | + </FormControl> |
| 115 | + <FormControl className={classes.formControl}> |
| 116 | + <Input |
| 117 | + className={classes.input} |
| 118 | + name={'code'} |
| 119 | + placeholder="输入6位验证码" |
| 120 | + onChange={this.inputChange} |
| 121 | + endAdornment={ |
| 122 | + <Button |
| 123 | + onClick={this.sendCode} |
| 124 | + className={classes.button} |
| 125 | + >{`${sendCode ? '重新': ''}获取验证码`}</Button> |
| 126 | + } |
| 127 | + /> |
| 128 | + </FormControl> |
| 129 | + <FormControl className={classes.formControl}> |
| 130 | + <Input |
| 131 | + className={classes.input} |
| 132 | + name={'password'} |
| 133 | + placeholder="密码" |
| 134 | + type={showPassword ? 'text' : 'password'} |
| 135 | + onChange={this.inputChange} |
| 136 | + endAdornment={ |
| 137 | + <InputAdornment position="end"> |
| 138 | + <IconButton |
| 139 | + onClick={this.handleClickShowPassword.bind(this, 'showPassword')} |
| 140 | + > |
| 141 | + {showPassword ? <Visibility /> : <VisibilityOff />} |
| 142 | + </IconButton> |
| 143 | + </InputAdornment> |
| 144 | + } |
| 145 | + /> |
| 146 | + </FormControl> |
| 147 | + <FormControl className={classes.formControl}> |
| 148 | + <Input |
| 149 | + className={classes.input} |
| 150 | + name={'enterpassword'} |
| 151 | + placeholder="确认密码" |
| 152 | + type={showEnterPassword ? 'text' : 'password'} |
| 153 | + onChange={this.inputChange} |
| 154 | + endAdornment={ |
| 155 | + <InputAdornment position="end"> |
| 156 | + <IconButton |
| 157 | + onClick={this.handleClickShowPassword.bind(this, 'showEnterPassword')} |
| 158 | + > |
| 159 | + {showEnterPassword ? <Visibility /> : <VisibilityOff />} |
| 160 | + </IconButton> |
| 161 | + </InputAdornment> |
| 162 | + } |
| 163 | + /> |
| 164 | + </FormControl> |
| 165 | + <FormControl className={classes.formControl}> |
| 166 | + <Input |
| 167 | + className={classes.input} |
| 168 | + name={'name'} |
| 169 | + placeholder="昵称" |
| 170 | + onChange={this.inputChange} |
| 171 | + /> |
| 172 | + </FormControl> |
| 173 | + <FormControl className={`${classes.formSelectControl} ${classes.formLeftSelectControl}`}> |
| 174 | + {role ? null: <InputLabel shrink={false}>选择角色</InputLabel>} |
| 175 | + <StyledSelect |
| 176 | + name={'role'} |
| 177 | + value={role} |
| 178 | + onChange={this.inputChange} |
| 179 | + displayEmpty |
| 180 | + className={classes.input} |
| 181 | + > |
| 182 | + <MenuItem value={10}>产品经理</MenuItem> |
| 183 | + <MenuItem value={20}>设计师</MenuItem> |
| 184 | + <MenuItem value={30}>前端工程师</MenuItem> |
| 185 | + <MenuItem value={40}>移动端端工程师</MenuItem> |
| 186 | + <MenuItem value={50}>小程序</MenuItem> |
| 187 | + </StyledSelect> |
| 188 | + </FormControl> |
| 189 | + <FormControl className={`${classes.formSelectControl} ${classes.formRighttSelectControl}`}> |
| 190 | + {exp ? null: <InputLabel shrink={false}>工作经验</InputLabel>} |
| 191 | + <StyledSelect |
| 192 | + name={'exp'} |
| 193 | + value={exp} |
| 194 | + onChange={this.inputChange} |
| 195 | + displayEmpty |
| 196 | + className={classes.input} |
| 197 | + > |
| 198 | + <MenuItem value={10}>0-3年</MenuItem> |
| 199 | + <MenuItem value={20}>3-5年</MenuItem> |
| 200 | + <MenuItem value={30}>5-9年</MenuItem> |
| 201 | + <MenuItem value={40}>10年以上</MenuItem> |
| 202 | + </StyledSelect> |
| 203 | + </FormControl> |
| 204 | + <Button type="submit" variant="contained" className={classes.submitButton}> |
| 205 | + 注册 |
| 206 | + </Button> |
| 207 | + </form> |
| 208 | + </div> |
| 209 | + ) |
| 210 | + } |
| 211 | +} |
| 212 | + |
| 213 | + |
| 214 | +export default withStyles(styles)(RegisterForm) |
0 commit comments