Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Commit e55714b

Browse files
committed
Update login page and env.
1 parent 342e8b9 commit e55714b

File tree

4 files changed

+128
-14
lines changed

4 files changed

+128
-14
lines changed

json-server.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"port": "3031",
33
"watch": true,
4+
"delay": "2000",
45
"routes": "mock/routes.json"
56
}

src/env.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ const serverEnvironments: {
1818
} = {
1919
[EnvType.Local]: {
2020
host: 'http://localhost:3000',
21-
api: 'http://localhost:3001',
21+
api: 'http://localhost:3031',
2222
},
2323
[EnvType.Test]: {
2424
host: 'http://localhost:3000',
25-
api: 'http://localhost:3001',
25+
api: 'http://localhost:3031',
2626
},
2727
[EnvType.Development]: {
28-
host: 'https://chachaxw.github.io',
29-
api: 'https://chachaxw.github.io',
28+
host: 'http://localhost:3000',
29+
api: 'http://localhost:3031',
3030
},
3131
[EnvType.Production]: {
3232
host: 'https://chachaxw.github.io',

src/index.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import './index.css';
2-
3-
import { message } from 'antd';
41
import dva from 'dva';
52
import createLoading from 'dva-loading';
63
import * as React from 'react';
74
import { reducer as formReducer } from 'redux-form';
85
import { createLogger } from 'redux-logger';
96

7+
import { Env, EnvType } from './env';
8+
import './index.css';
109
import { Global } from './models';
1110
import Page from './Page';
11+
import { errorHandle } from './utils/errorHandle';
1212

13-
const errorDuration = 3;
13+
const logger = Env === EnvType.Development ? createLogger() : () => null;
1414

15-
const app = dva({
16-
onError(e) {
15+
const app: any = dva({
16+
onError(error: any) {
1717
// Catch redux action errors
18-
message.error(e.message, errorDuration);
18+
errorHandle(error, app._store.dispatch);
1919
},
2020

21-
onAction: createLogger(),
21+
onAction: logger,
2222

2323
// 其他第三方 Reducer 配置
2424
extraReducers: {

src/pages/Login/Login.tsx

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,126 @@
1+
import { Button, Form, Icon, Input } from 'antd';
2+
import { FormComponentProps } from 'antd/lib/form';
3+
import { connect } from 'dva';
14
import React, { PureComponent } from 'react';
5+
import { EmailRxp } from '../../utils/constant';
26
import styles from './Login.module.scss';
37

4-
export default class Login extends PureComponent {
8+
interface FormProps extends FormComponentProps {
9+
email: string;
10+
password: string;
11+
}
12+
13+
interface DvaProps {
14+
loading: boolean;
15+
login: (params: any) => void;
16+
}
17+
18+
interface InternalProps extends DvaProps {
19+
form: any;
20+
}
21+
22+
export class Login extends PureComponent<InternalProps> {
23+
24+
public onSubmit = () => {
25+
const { login, form } = this.props;
26+
const { validateFields } = form;
27+
28+
validateFields((err: any, values: any) => {
29+
if (!err) {
30+
login(values);
31+
}
32+
});
33+
}
534

635
public render() {
36+
const color = 'rgba(0,0,0,.25)';
37+
const { form, loading } = this.props;
38+
const { getFieldDecorator } = form;
39+
740
return (
841
<div className={styles.login}>
9-
Login
42+
<svg className="Header__svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1337.97 684.43">
43+
<path
44+
className="Header__shape bigSquare" fill="#16d5d1"
45+
d="M546.519 349.271l86.383-56.098 56.097 86.383-86.383 56.098z"
46+
/>
47+
<path
48+
className="Header__shape triangle"
49+
fill="none" stroke="#ff4676" strokeWidth="8"
50+
d="M372.15 462.17L321 434.58l-4.88 56.16z"
51+
/>
52+
<circle
53+
className="Header__shape bigCircle"
54+
fill="#ff4676" cx="1076.52" cy="262.17" r="59"
55+
/>
56+
<path
57+
className="Header__shape littleSquare" fill="#ffe430"
58+
d="M285.523 262.61l12.372-53.59 53.59 12.372-12.372 53.59z"
59+
/>
60+
<circle
61+
className="Header__shape hoop" fill="none" stroke="#ffe430"
62+
strokeWidth="13" cx="905.52" cy="447.17" r="45"
63+
/>
64+
<circle
65+
className="Header__shape littleCircle"
66+
fill="#0f1c70" cx="1036.52" cy="203.17" r="27"
67+
/>
68+
</svg>
69+
<Form style={{ width: 320 }} onSubmit={this.onSubmit}>
70+
<Form.Item>
71+
{getFieldDecorator('email', {
72+
rules: [
73+
{ required: true, message: 'Please input email!' },
74+
{ pattern: EmailRxp, message: 'Please input right email!' },
75+
],
76+
})(
77+
<Input
78+
prefix={<Icon type="inbox" style={{ color }} />}
79+
placeholder="Email"
80+
/>
81+
)}
82+
</Form.Item>
83+
<Form.Item>
84+
{getFieldDecorator('password', {
85+
rules: [
86+
{ required: true, message: 'Please input password!' },
87+
],
88+
})(
89+
<Input
90+
type="password"
91+
prefix={<Icon type="key" style={{ color }} />}
92+
placeholder="Password"
93+
/>
94+
)}
95+
</Form.Item>
96+
<Form.Item>
97+
<Button block type="primary" htmlType="submit" loading={loading}>
98+
登录
99+
</Button>
100+
</Form.Item>
101+
</Form>
10102
</div>
11103
);
12104
}
13105
}
106+
107+
const CreateLogin = Form.create<FormProps>()(Login);
108+
109+
const mapStateToProps = ({ global, loading }: any) => {
110+
return {
111+
loading: loading.effects['global/login'],
112+
};
113+
};
114+
115+
const mapDispatchToProps = (dispatch: any, ownProps: any) => {
116+
return {
117+
login: (params: object) => {
118+
dispatch({
119+
type: 'global/login',
120+
payload: params,
121+
});
122+
},
123+
};
124+
};
125+
126+
export default connect(mapStateToProps, mapDispatchToProps)(CreateLogin);

0 commit comments

Comments
 (0)