Skip to content

Commit

Permalink
realization of i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
wfnuser committed Jan 9, 2019
1 parent f77dbd0 commit d09c0e5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ const I18N_CONF = {
community: 'COMMUNITY',
languageSwitchButton: '中',
},
Login: {
pleaseLogin: 'Plase login',
submit: 'Submit',
pleaseInputUsername: 'Please input username',
pleaseInputPassword: 'Please input password',
invalidUsernameOrPassword: 'invalid username or password',
},
MainLayout: {
nacosName: 'NACOS',
nacosVersion: '0.7.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ const I18N_CONF = {
community: '社区',
languageSwitchButton: 'En',
},
Login: {
pleaseLogin: '请登录',
submit: '提交',
pleaseInputUsername: '请输入用户名',
pleaseInputPassword: '请输入密码',
invalidUsernameOrPassword: '用户名或密码错误',
},
MainLayout: {
nacosName: 'NACOS',
nacosVersion: '0.7.0',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Card, Form, Input, Message } from '@alifd/next';
import { Card, Form, Input, Message, ConfigProvider } from '@alifd/next';
import { withRouter } from 'react-router-dom';

import './index.scss';
Expand All @@ -9,8 +9,10 @@ import { request } from '../../globalLib';
const FormItem = Form.Item;

@withRouter
@ConfigProvider.config
class Login extends React.Component {
handleSubmit = values => {
const { locale = {} } = this.props;
request({
type: 'get',
url: 'v1/auth/login',
Expand All @@ -23,16 +25,23 @@ class Login extends React.Component {
// TODO: 使用react router
this.props.history.push('/');
}
if (res.code === 401) {
Message.error({
content: locale.invalidUsernameOrPassword,
});
}
},
error: () => {
Message.error({
content: '登录失败',
content: locale.invalidUsernameOrPassword,
});
},
});
};

render() {
const { locale = {} } = this.props;

return (
<div className="home-page">
<Header />
Expand All @@ -56,16 +65,20 @@ class Login extends React.Component {
<div className="animation animation4" />
<div className="animation animation5" />
<Card className="login-panel" contentHeight="auto">
<div className="login-header">请登录</div>
<div className="login-header">{locale.pleaseLogin}</div>
<Form className="login-form">
<FormItem>
<Input htmlType="text" name="username" placeholder="请输入账号名" />
<Input htmlType="text" name="username" placeholder={locale.pleaseInputUsername} />
</FormItem>
<FormItem>
<Input htmlType="password" name="password" placeholder="请输入密码" />
<Input
htmlType="password"
name="password"
placeholder={locale.pleaseInputPassword}
/>
</FormItem>
<FormItem label=" ">
<Form.Submit onClick={this.handleSubmit}>提交</Form.Submit>
<Form.Submit onClick={this.handleSubmit}>{locale.submit}</Form.Submit>
</FormItem>
</Form>
</Card>
Expand Down

0 comments on commit d09c0e5

Please sign in to comment.