Login登录

支持多种登录方式切换,内置了几种常见的登录控件,可以灵活组合,也支持和自定义控件配合使用。

引用方式:

  1. import Login from 'ant-design-pro/lib/Login';

详细使用方式请参照:独立使用 pro 组件

代码演示

Login 登录 - 图1

标准登录

Support login with account and mobile number.

  1. import Login from 'ant-design-pro/lib/Login';
  2. import { Alert, Checkbox } from 'antd';
  3. const { Tab, UserName, Password, Mobile, Captcha, Submit } = Login;
  4. class LoginDemo extends React.Component {
  5. state = {
  6. notice: '',
  7. type: 'tab2',
  8. autoLogin: true,
  9. };
  10. onSubmit = (err, values) => {
  11. console.log('value collected ->', {
  12. ...values,
  13. autoLogin: this.state.autoLogin,
  14. });
  15. if (this.state.type === 'tab1') {
  16. this.setState(
  17. {
  18. notice: '',
  19. },
  20. () => {
  21. if (!err && (values.username !== 'admin' || values.password !== '888888')) {
  22. setTimeout(() => {
  23. this.setState({
  24. notice: 'The combination of username and password is incorrect!',
  25. });
  26. }, 500);
  27. }
  28. }
  29. );
  30. }
  31. };
  32. onTabChange = key => {
  33. this.setState({
  34. type: key,
  35. });
  36. };
  37. changeAutoLogin = e => {
  38. this.setState({
  39. autoLogin: e.target.checked,
  40. });
  41. };
  42. render() {
  43. return (
  44. <div className="login-warp">
  45. <Login
  46. defaultActiveKey={this.state.type}
  47. onTabChange={this.onTabChange}
  48. onSubmit={this.onSubmit}
  49. >
  50. <Tab key="tab1" tab="Account">
  51. {this.state.notice && (
  52. <Alert
  53. style={{ marginBottom: 24 }}
  54. message={this.state.notice}
  55. type="error"
  56. showIcon
  57. closable
  58. />
  59. )}
  60. <UserName name="username" />
  61. <Password name="password" />
  62. </Tab>
  63. <Tab key="tab2" tab="Mobile">
  64. <Mobile name="mobile" />
  65. <Captcha onGetCaptcha={() => console.log('Get captcha!')} name="captcha" />
  66. </Tab>
  67. <div>
  68. <Checkbox checked={this.state.autoLogin} onChange={this.changeAutoLogin}>
  69. Keep me logged in
  70. </Checkbox>
  71. <a style={{ float: 'right' }} href="">
  72. Forgot password
  73. </a>
  74. </div>
  75. <Submit>Login</Submit>
  76. <div>
  77. Other login methods
  78. <span className="icon icon-alipay" />
  79. <span className="icon icon-taobao" />
  80. <span className="icon icon-weibo" />
  81. <a style={{ float: 'right' }} href="">
  82. Register
  83. </a>
  84. </div>
  85. </Login>
  86. </div>
  87. );
  88. }
  89. }
  90. ReactDOM.render(<LoginDemo />, mountNode);

API

Login

参数说明类型默认值
defaultActiveKey默认激活 tab 面板的 keyString-
onTabChange切换页签时的回调(key) => void-
onSubmit点击提交时的回调(err, values) => void-

Login.Tab

参数说明类型默认值
key对应选项卡的 keyString-
tab选项卡头显示文字ReactNode-

Login.UserName

参数说明类型默认值
name控件标记,提交数据中同样以此为 keyString-
rules校验规则,同 Form getFieldDecorator(id, options) 中 option.rules 的规则)object[]-

除上述属性以外,Login.UserName 还支持 antd.Input 的所有属性,并且自带默认的基础配置,包括 placeholder size prefix 等,这些基础配置均可被覆盖。

Login.Password、Login.Mobile 同 Login.UserName

Login.Captcha

参数说明类型默认值
onGetCaptcha点击获取校验码的回调() => (void | false | Promise)-
countDown倒计时number-
buttonText点击获取校验码的说明文字ReactNode'获取验证码'

除上述属性以外,Login.Captcha 支持的属性与 Login.UserName 相同。

Login.Submit

支持 antd.Button 的所有属性。