index.js 1.95 KB
Newer Older
ddcat1115's avatar
ddcat1115 committed
1
import React, { PureComponent } from 'react';
2 3 4 5
import { connect } from 'dva';
import { Card, Steps, Form } from 'antd';
import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
import Step1 from './Step1';
ddcat1115's avatar
ddcat1115 committed
6 7
import Step2 from './Step2';
import Step3 from './Step3';
8 9
import styles from '../style.less';

afc163's avatar
afc163 committed
10
const { Step } = Steps;
11 12 13 14

@Form.create()
class StepForm extends PureComponent {
  getCurrentStep() {
ddcat1115's avatar
ddcat1115 committed
15 16 17 18
    const { location } = this.props;
    const { pathname } = location;
    const pathList = pathname.split('/');
    switch (pathList[pathList.length - 1]) {
19 20 21 22 23 24
      case 'step-form': return 0;
      case 'confirm': return 1;
      case 'result': return 2;
      default: return 0;
    }
  }
ddcat1115's avatar
ddcat1115 committed
25 26 27 28 29 30 31 32
  getCurrentComponent() {
    const componentMap = {
      0: Step1,
      1: Step2,
      2: Step3,
    };
    return componentMap[this.getCurrentStep()];
  }
33
  render() {
ddcat1115's avatar
ddcat1115 committed
34
    const { form, stepFormData, submitting, dispatch } = this.props;
35 36 37 38 39 40 41 42
    const formItemLayout = {
      labelCol: {
        span: 5,
      },
      wrapperCol: {
        span: 19,
      },
    };
ddcat1115's avatar
ddcat1115 committed
43
    const CurrentComponent = this.getCurrentComponent();
44 45 46 47 48 49 50 51 52
    return (
      <PageHeaderLayout title="分步表单" content="将表单内容进行分步可以提高用户处理的专注度,降低页面复杂性。">
        <Card bordered={false}>
          <div>
            <Steps current={this.getCurrentStep()} className={styles.steps}>
              <Step title="填写转账信息" />
              <Step title="确认转账信息" />
              <Step title="完成" />
            </Steps>
ddcat1115's avatar
ddcat1115 committed
53 54 55 56 57 58 59
            <CurrentComponent
              formItemLayout={formItemLayout}
              form={form}
              dispatch={dispatch}
              data={stepFormData}
              submitting={submitting}
            />
60 61 62 63 64 65 66 67 68 69 70
          </div>
        </Card>
      </PageHeaderLayout>
    );
  }
}

export default connect(state => ({
  stepFormData: state.form.step,
  submitting: state.form.stepFormSubmitting,
}))(StepForm);