123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import { Form, Tabs } from 'antd';
- import React, { Component } from 'react';
- import classNames from 'classnames';
- import LoginContext from './LoginContext';
- import LoginItem from './LoginItem';
- import LoginSubmit from './LoginSubmit';
- import styles from './index.less';
-
-
- class Login extends Component {
-
- static Submit = LoginSubmit;
- static defaultProps = {
- className: '',
- defaultActiveKey: '',
- onTabChange: () => { },
- onSubmit: () => { },
- };
-
- constructor(props) {
- super(props);
- this.state = {
- type: props.defaultActiveKey,
- tabs: [],
- active: {},
- };
- }
-
- componentDidMount() {
- const { form, onCreate } = this.props;
-
- if (onCreate) {
- onCreate(form);
- }
- }
-
- onSwitch = type => {
- this.setState(
- {
- type,
- },
- () => {
- const { onTabChange } = this.props;
-
- if (onTabChange) {
- onTabChange(type);
- }
- },
- );
- };
- getContext = () => {
- const { form } = this.props;
- const { tabs = [] } = this.state;
- return {
- tabUtil: {
- addTab: id => {
- this.setState({
- tabs: [...tabs, id],
- });
- },
- removeTab: id => {
- this.setState({
- tabs: tabs.filter(currentId => currentId !== id),
- });
- },
- },
- form: { ...form },
- updateActive: activeItem => {
- const { type = '', active = {} } = this.state;
-
- if (active[type]) {
- active[type].push(activeItem);
- } else {
- active[type] = [activeItem];
- }
-
- this.setState({
- active,
- });
- },
- };
- };
- handleSubmit = e => {
- e.preventDefault();
- const { active = {}, type = '' } = this.state;
- const { form, onSubmit } = this.props;
- const activeFields = active[type] || [];
-
- if (form) {
- form.validateFields(
- activeFields,
- {
- force: true,
- },
- (err, values) => {
- if (onSubmit) {
- onSubmit(err, values);
- }
- },
- );
- }
- };
-
- render() {
- const { className, children } = this.props;
- const { type, tabs = [] } = this.state;
- const TabChildren = [];
- const otherChildren = [];
- React.Children.forEach(children, child => {
- if (!child) {
- return;
- }
-
- });
- return (
- <>
- <div className={styles.topBox}>
- <div className={styles.con}>
- <p className={styles.welcome}>欢迎使用</p>
- <div className={styles.title}>
- <p className={styles.name}>远道荟 · 系统</p>
- {/* <span style={{fontSize:' 0.106rem',lineHeight:' 0.106rem'}}>YUANDAO HUI</span> */}
- </div>
- </div>
- </div>
- <LoginContext.Provider value={this.getContext()}>
- <div className={styles.login}>
- <Form onSubmit={this.handleSubmit}>
- {children}
- </Form>
- </div>
- </LoginContext.Provider>
- </>
- );
- }
- }
-
- Object.keys(LoginItem).forEach(item => {
- Login[item] = LoginItem[item];
- });
- export default Form.create()(Login);
|