index.js 1.82 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 6
import NotFound from '../../Exception/404';
import { getRoutes } from '../../../utils/utils';
7 8
import styles from '../style.less';

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

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