index.js 1.72 KB
Newer Older
陈帅's avatar
陈帅 committed
1
import React, { PureComponent, Fragment } from 'react';
WhatAKitty's avatar
WhatAKitty committed
2 3
import { Route, Redirect, Switch } from 'dva/router';
import { Card, Steps } from 'antd';
4
import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
WhatAKitty's avatar
WhatAKitty committed
5
import { getRoutes } from '../../../utils/utils';
6 7
import styles from '../style.less';

afc163's avatar
afc163 committed
8
const { Step } = Steps;
9

WhatAKitty's avatar
WhatAKitty committed
10
export default class StepForm extends PureComponent {
11
  getCurrentStep() {
ddcat1115's avatar
ddcat1115 committed
12 13 14 15
    const { location } = this.props;
    const { pathname } = location;
    const pathList = pathname.split('/');
    switch (pathList[pathList.length - 1]) {
WhatAKitty's avatar
WhatAKitty committed
16
      case 'info': return 0;
17 18 19 20 21 22
      case 'confirm': return 1;
      case 'result': return 2;
      default: return 0;
    }
  }
  render() {
WhatAKitty's avatar
WhatAKitty committed
23
    const { match, routerData } = this.props;
24
    return (
afc163's avatar
afc163 committed
25
      <PageHeaderLayout title="分步表单" content="将一个冗长或用户不熟悉的表单任务分成多个步骤,指导用户完成。">
26
        <Card bordered={false}>
陈帅's avatar
陈帅 committed
27
          <Fragment>
28 29 30 31 32
            <Steps current={this.getCurrentStep()} className={styles.steps}>
              <Step title="填写转账信息" />
              <Step title="确认转账信息" />
              <Step title="完成" />
            </Steps>
WhatAKitty's avatar
WhatAKitty committed
33 34 35 36 37 38 39 40 41 42 43 44
            <Switch>
              {
                getRoutes(match.path, routerData).map(item => (
                  <Route
                    key={item.key}
                    path={item.path}
                    component={item.component}
                    exact={item.exact}
                  />
                ))
              }
              <Redirect exact from="/form/step-form" to="/form/step-form/info" />
陈帅's avatar
陈帅 committed
45
              <Redirect to="/exception/404" />
WhatAKitty's avatar
WhatAKitty committed
46
            </Switch>
陈帅's avatar
陈帅 committed
47
          </Fragment>
48 49 50 51 52
        </Card>
      </PageHeaderLayout>
    );
  }
}