Commit b405a52d authored by 陈帅's avatar 陈帅

UserRegister finish

parent cdc57db2
export default { export default {
'POST /api/BLOCK_NAME/register': (req, res) => { 'POST /api/BLOCK_NAME/register': (
req: any,
res: { send: (arg0: { status: string; currentAuthority: string }) => void }
) => {
res.send({ status: 'ok', currentAuthority: 'user' }); res.send({ status: 'ok', currentAuthority: 'user' });
}, },
}; };
...@@ -2,9 +2,11 @@ import React, { Component } from 'react'; ...@@ -2,9 +2,11 @@ import React, { Component } from 'react';
import { connect } from 'dva'; import { connect } from 'dva';
import { formatMessage, FormattedMessage } from 'umi-plugin-react/locale'; import { formatMessage, FormattedMessage } from 'umi-plugin-react/locale';
import Link from 'umi/link'; import Link from 'umi/link';
import router from 'umi/router'; import { Form, Input, message, Button, Select, Row, Col, Popover, Progress } from 'antd';
import { Form, Input, Button, Select, Row, Col, Popover, Progress } from 'antd';
import styles from './style.less'; import styles from './style.less';
import { Dispatch } from 'redux';
import { IStateType } from './model';
import { FormComponentProps } from 'antd/lib/form';
const FormItem = Form.Item; const FormItem = Form.Item;
const { Option } = Select; const { Option } = Select;
...@@ -28,19 +30,59 @@ const passwordStatusMap = { ...@@ -28,19 +30,59 @@ const passwordStatusMap = {
), ),
}; };
const passwordProgressMap = { const passwordProgressMap: {
ok: 'success';
pass: 'normal';
poor: 'exception';
} = {
ok: 'success', ok: 'success',
pass: 'normal', pass: 'normal',
poor: 'exception', poor: 'exception',
}; };
@connect(({ BLOCK_NAME_CAMEL_CASE, loading }) => ({ interface BLOCK_NAME_CAMEL_CASEProps extends FormComponentProps {
BLOCK_NAME_CAMEL_CASE, dispatch: Dispatch;
submitting: loading.effects['BLOCK_NAME_CAMEL_CASE/submit'], BLOCK_NAME_CAMEL_CASE: IStateType;
})) submitting: boolean;
@Form.create() }
class PAGE_NAME_UPPER_CAMEL_CASE extends Component { interface BLOCK_NAME_CAMEL_CASEState {
state = { count: number;
confirmDirty: boolean;
visible: boolean;
help: string;
prefix: string;
}
export interface IUserRegisterParams {
mail: string;
password: string;
confirm: string;
mobile: string;
captcha: string;
prefix: string;
}
@connect(
({
BLOCK_NAME_CAMEL_CASE,
loading,
}: {
BLOCK_NAME_CAMEL_CASE: IStateType;
loading: {
effects: {
[key: string]: string;
};
};
}) => ({
BLOCK_NAME_CAMEL_CASE,
submitting: loading.effects['BLOCK_NAME_CAMEL_CASE/submit'],
})
)
class PAGE_NAME_UPPER_CAMEL_CASE extends Component<
BLOCK_NAME_CAMEL_CASEProps,
BLOCK_NAME_CAMEL_CASEState
> {
state: BLOCK_NAME_CAMEL_CASEState = {
count: 0, count: 0,
confirmDirty: false, confirmDirty: false,
visible: false, visible: false,
...@@ -52,23 +94,18 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -52,23 +94,18 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
const { form, BLOCK_NAME_CAMEL_CASE } = this.props; const { form, BLOCK_NAME_CAMEL_CASE } = this.props;
const account = form.getFieldValue('mail'); const account = form.getFieldValue('mail');
if (BLOCK_NAME_CAMEL_CASE.status === 'ok') { if (BLOCK_NAME_CAMEL_CASE.status === 'ok') {
router.push({ message.success('注册成功!');
pathname: '/user/register-result',
state: {
account,
},
});
} }
} }
componentWillUnmount() { componentWillUnmount() {
clearInterval(this.interval); clearInterval(this.interval);
} }
interval: number | undefined;
onGetCaptcha = () => { onGetCaptcha = () => {
let count = 59; let count = 59;
this.setState({ count }); this.setState({ count });
this.interval = setInterval(() => { this.interval = window.setInterval(() => {
count -= 1; count -= 1;
this.setState({ count }); this.setState({ count });
if (count === 0) { if (count === 0) {
...@@ -89,7 +126,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -89,7 +126,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
return 'poor'; return 'poor';
}; };
handleSubmit = e => { handleSubmit = (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
const { form, dispatch } = this.props; const { form, dispatch } = this.props;
form.validateFields({ force: true }, (err, values) => { form.validateFields({ force: true }, (err, values) => {
...@@ -106,13 +143,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -106,13 +143,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
}); });
}; };
handleConfirmBlur = e => { checkConfirm = (rule: any, value: string, callback: (messgae?: string) => void) => {
const { value } = e.target;
const { confirmDirty } = this.state;
this.setState({ confirmDirty: confirmDirty || !!value });
};
checkConfirm = (rule, value, callback) => {
const { form } = this.props; const { form } = this.props;
if (value && value !== form.getFieldValue('password')) { if (value && value !== form.getFieldValue('password')) {
callback(formatMessage({ id: 'BLOCK_NAME.password.twice' })); callback(formatMessage({ id: 'BLOCK_NAME.password.twice' }));
...@@ -121,7 +152,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -121,7 +152,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
} }
}; };
checkPassword = (rule, value, callback) => { checkPassword = (rule: any, value: string, callback: (messgae?: string) => void) => {
const { visible, confirmDirty } = this.state; const { visible, confirmDirty } = this.state;
if (!value) { if (!value) {
this.setState({ this.setState({
...@@ -150,7 +181,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -150,7 +181,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
} }
}; };
changePrefix = value => { changePrefix = (value: string) => {
this.setState({ this.setState({
prefix: value, prefix: value,
}); });
...@@ -204,7 +235,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -204,7 +235,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
</FormItem> </FormItem>
<FormItem help={help}> <FormItem help={help}>
<Popover <Popover
getPopupContainer={node => node.parentNode} getPopupContainer={node => (node && node.parentNode ? node.parentNode : node)}
content={ content={
<div style={{ padding: '4px 0' }}> <div style={{ padding: '4px 0' }}>
{passwordStatusMap[this.getPasswordStatus()]} {passwordStatusMap[this.getPasswordStatus()]}
...@@ -303,7 +334,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -303,7 +334,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
<Col span={8}> <Col span={8}>
<Button <Button
size="large" size="large"
disabled={count} disabled={!!count}
className={styles.getCaptcha} className={styles.getCaptcha}
onClick={this.onGetCaptcha} onClick={this.onGetCaptcha}
> >
...@@ -334,4 +365,4 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -334,4 +365,4 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
} }
} }
export default PAGE_NAME_UPPER_CAMEL_CASE; export default Form.create()(PAGE_NAME_UPPER_CAMEL_CASE);
import { fakeRegister } from './service'; import { fakeRegister } from './service';
import { Reducer } from 'redux';
import { EffectsCommandMap } from 'dva';
import { AnyAction } from 'redux';
export default { export interface IStateType {
status?: 'ok' | 'error';
currentAuthority?: 'user' | 'guest' | 'admin';
}
export type Effect = (
action: AnyAction,
effects: EffectsCommandMap & { select: <T>(func: (state: IStateType) => T) => T }
) => void;
export interface ModelType {
namespace: string;
state: IStateType;
effects: {
submit: Effect;
};
reducers: {
registerHandle: Reducer<IStateType>;
};
}
const Model: ModelType = {
namespace: 'BLOCK_NAME_CAMEL_CASE', namespace: 'BLOCK_NAME_CAMEL_CASE',
state: { state: {
...@@ -26,3 +50,5 @@ export default { ...@@ -26,3 +50,5 @@ export default {
}, },
}, },
}; };
export default Model;
import request from 'umi-request'; import request from 'umi-request';
import { IUserRegisterParams } from './index';
export async function fakeRegister(params) { export async function fakeRegister(params: IUserRegisterParams) {
return request('/api/BLOCK_NAME/register', { return request('/api/BLOCK_NAME/register', {
method: 'POST', method: 'POST',
data: params, data: params,
......
{ {
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "cross-env PAGES_PATH='UserLogin/src' umi dev", "dev": "cross-env PAGES_PATH='UserRegister/src' umi dev",
"lint": "eslint --ext .js src mock tests && npm run lint:style", "lint": "eslint --ext .js src mock tests && npm run lint:style",
"lint-staged": "lint-staged", "lint-staged": "lint-staged",
"lint-staged:js": "eslint --ext .js", "lint-staged:js": "eslint --ext .js",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment