index.jsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { Form, Tabs } from 'antd';
  2. import React, { Component } from 'react';
  3. import classNames from 'classnames';
  4. import LoginContext from './LoginContext';
  5. import LoginItem from './LoginItem';
  6. import LoginSubmit from './LoginSubmit';
  7. import styles from './index.less';
  8. class Login extends Component {
  9. static Submit = LoginSubmit;
  10. static defaultProps = {
  11. className: '',
  12. defaultActiveKey: '',
  13. onTabChange: () => { },
  14. onSubmit: () => { },
  15. };
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. type: props.defaultActiveKey,
  20. tabs: [],
  21. active: {},
  22. };
  23. }
  24. componentDidMount() {
  25. const { form, onCreate } = this.props;
  26. if (onCreate) {
  27. onCreate(form);
  28. }
  29. }
  30. onSwitch = type => {
  31. this.setState(
  32. {
  33. type,
  34. },
  35. () => {
  36. const { onTabChange } = this.props;
  37. if (onTabChange) {
  38. onTabChange(type);
  39. }
  40. },
  41. );
  42. };
  43. getContext = () => {
  44. const { form } = this.props;
  45. const { tabs = [] } = this.state;
  46. return {
  47. tabUtil: {
  48. addTab: id => {
  49. this.setState({
  50. tabs: [...tabs, id],
  51. });
  52. },
  53. removeTab: id => {
  54. this.setState({
  55. tabs: tabs.filter(currentId => currentId !== id),
  56. });
  57. },
  58. },
  59. form: { ...form },
  60. updateActive: activeItem => {
  61. const { type = '', active = {} } = this.state;
  62. if (active[type]) {
  63. active[type].push(activeItem);
  64. } else {
  65. active[type] = [activeItem];
  66. }
  67. this.setState({
  68. active,
  69. });
  70. },
  71. };
  72. };
  73. handleSubmit = e => {
  74. e.preventDefault();
  75. const { active = {}, type = '' } = this.state;
  76. const { form, onSubmit } = this.props;
  77. const activeFields = active[type] || [];
  78. if (form) {
  79. form.validateFields(
  80. activeFields,
  81. {
  82. force: true,
  83. },
  84. (err, values) => {
  85. if (onSubmit) {
  86. onSubmit(err, values);
  87. }
  88. },
  89. );
  90. }
  91. };
  92. render() {
  93. const { className, children } = this.props;
  94. const { type, tabs = [] } = this.state;
  95. const TabChildren = [];
  96. const otherChildren = [];
  97. React.Children.forEach(children, child => {
  98. if (!child) {
  99. return;
  100. }
  101. });
  102. return (
  103. <>
  104. <div className={styles.topBox}>
  105. <div className={styles.con}>
  106. <p className={styles.welcome}>欢迎使用</p>
  107. <div className={styles.title}>
  108. <p className={styles.name}>远道荟 · 系统</p>
  109. {/* <span style={{fontSize:' 0.106rem',lineHeight:' 0.106rem'}}>YUANDAO HUI</span> */}
  110. </div>
  111. </div>
  112. </div>
  113. <LoginContext.Provider value={this.getContext()}>
  114. <div className={styles.login}>
  115. <Form onSubmit={this.handleSubmit}>
  116. {children}
  117. </Form>
  118. </div>
  119. </LoginContext.Provider>
  120. </>
  121. );
  122. }
  123. }
  124. Object.keys(LoginItem).forEach(item => {
  125. Login[item] = LoginItem[item];
  126. });
  127. export default Form.create()(Login);