index.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import {Alert} from 'antd';
  2. import React, {useState} from 'react';
  3. import {connect, Dispatch} from 'umi';
  4. import {StateType} from '@/models/login';
  5. import {LoginParamsType} from '@/services/login';
  6. import {ConnectState} from '@/models/connect';
  7. import LoginFrom from './components/Login';
  8. import styles from './style.less';
  9. const {Tab, UserName, Password, Mobile, Captcha, Submit} = LoginFrom;
  10. interface LoginProps {
  11. dispatch: Dispatch;
  12. userLogin: StateType;
  13. submitting?: boolean;
  14. }
  15. const LoginMessage: React.FC<{
  16. content: string;
  17. }> = ({content}) => (
  18. <Alert
  19. style={{
  20. marginBottom: 24,
  21. }}
  22. message={content}
  23. type="error"
  24. showIcon
  25. />
  26. );
  27. const Login: React.FC<LoginProps> = (props) => {
  28. const {userLogin = {}, submitting} = props;
  29. // const {status, type: loginType} = userLogin;
  30. // const [autoLogin, setAutoLogin] = useState(true);
  31. const [identityType, setType] = useState<string>('account');
  32. const handleSubmit = (values: LoginParamsType) => {
  33. const {dispatch} = props;
  34. dispatch({
  35. type: 'login/login',
  36. payload: {...values, identityType},
  37. });
  38. };
  39. const getSuccess = () => {
  40. const item = localStorage.getItem("success");
  41. return item == null ? "SUCCESS" : item;
  42. }
  43. return (
  44. <div className={styles.main}>
  45. <LoginFrom activeKey={identityType} onTabChange={setType} onSubmit={handleSubmit}>
  46. <Tab key="account" tab="账户密码登录">
  47. {getSuccess() !== 'SUCCESS' && !submitting && (
  48. <LoginMessage content="账户或密码错误"/>
  49. )}
  50. <UserName
  51. name="identify"
  52. placeholder="用户名"
  53. rules={[
  54. {
  55. required: true,
  56. message: '请输入用户名!',
  57. },
  58. ]}
  59. />
  60. <Password
  61. name="credential"
  62. placeholder="密码"
  63. rules={[
  64. {
  65. required: true,
  66. message: '请输入密码!',
  67. },
  68. ]}
  69. />
  70. </Tab>
  71. {/*
  72. <Tab key="mobile" tab="手机号登录">
  73. {status === 'error' && loginType === 'mobile' && !submitting && (
  74. <LoginMessage content="验证码错误"/>
  75. )}
  76. <Mobile
  77. name="mobile"
  78. placeholder="手机号"
  79. rules={[
  80. {
  81. required: true,
  82. message: '请输入手机号!',
  83. },
  84. {
  85. pattern: /^1\d{10}$/,
  86. message: '手机号格式错误!',
  87. },
  88. ]}
  89. />
  90. <Captcha
  91. name="captcha"
  92. placeholder="验证码"
  93. countDown={120}
  94. getCaptchaButtonText=""
  95. getCaptchaSecondText="秒"
  96. rules={[
  97. {
  98. required: true,
  99. message: '请输入验证码!',
  100. },
  101. ]}
  102. />
  103. </Tab>
  104. <div>
  105. <a
  106. style={{
  107. float: 'right',
  108. }}
  109. >
  110. 忘记密码
  111. </a>
  112. </div>
  113. */}
  114. <Submit loading={submitting}>登录</Submit>
  115. {/*
  116. <div className={styles.other}>
  117. 其他登录方式
  118. <AlipayCircleOutlined className={styles.icon}/>
  119. <TaobaoCircleOutlined className={styles.icon}/>
  120. <WeiboCircleOutlined className={styles.icon}/>
  121. <Link className={styles.register} to="/user/register">
  122. 注册账户
  123. </Link>
  124. </div>
  125. */}
  126. </LoginFrom>
  127. </div>
  128. );
  129. };
  130. export default connect(({login, loading}: ConnectState) => ({
  131. userLogin: login,
  132. submitting: loading.effects['login/login'],
  133. }))(Login);