UserLayout.js 2.46 KB
Newer Older
陈帅's avatar
陈帅 committed
1
import React, { Fragment } from 'react';
2
import { Link, Redirect, Switch, Route } from 'dva/router';
3 4 5 6
import DocumentTitle from 'react-document-title';
import { Icon } from 'antd';
import GlobalFooter from '../components/GlobalFooter';
import styles from './UserLayout.less';
afc163's avatar
afc163 committed
7
import logo from '../assets/logo.svg';
ddcat1115's avatar
ddcat1115 committed
8
import { getRoutes } from '../utils/utils';
9

jim's avatar
jim committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
const links = [
  {
    key: 'help',
    title: '帮助',
    href: '',
  },
  {
    key: 'privacy',
    title: '隐私',
    href: '',
  },
  {
    key: 'terms',
    title: '条款',
    href: '',
  },
];
27

jim's avatar
jim committed
28 29 30 31 32
const copyright = (
  <Fragment>
    Copyright <Icon type="copyright" /> 2018 蚂蚁金服体验技术部出品
  </Fragment>
);
33

34 35 36 37 38 39 40 41 42 43
function getLoginPathWithRedirectPath() {
  const routePath = '/user/login';
  const urlParams = new URL(window.location.href);
  const redirect = urlParams.searchParams.get('redirect');
  if (redirect) {
    return `${routePath}?redirect=${encodeURIComponent(redirect)}`;
  }
  return routePath;
}

44 45
class UserLayout extends React.PureComponent {
  getPageTitle() {
ddcat1115's avatar
ddcat1115 committed
46
    const { routerData, location } = this.props;
ddcat1115's avatar
ddcat1115 committed
47 48
    const { pathname } = location;
    let title = 'Ant Design Pro';
ddcat1115's avatar
ddcat1115 committed
49 50 51
    if (routerData[pathname] && routerData[pathname].name) {
      title = `${routerData[pathname].name} - Ant Design Pro`;
    }
ddcat1115's avatar
ddcat1115 committed
52
    return title;
53
  }
陈帅's avatar
陈帅 committed
54

55
  render() {
ddcat1115's avatar
ddcat1115 committed
56
    const { routerData, match } = this.props;
57 58 59
    return (
      <DocumentTitle title={this.getPageTitle()}>
        <div className={styles.container}>
60 61 62 63 64 65 66 67 68
          <div className={styles.content}>
            <div className={styles.top}>
              <div className={styles.header}>
                <Link to="/">
                  <img alt="logo" className={styles.logo} src={logo} />
                  <span className={styles.title}>Ant Design</span>
                </Link>
              </div>
              <div className={styles.desc}>Ant Design 是西湖区最具影响力的 Web 设计规范</div>
69
            </div>
70
            <Switch>
jim's avatar
jim committed
71 72 73 74 75 76 77 78
              {getRoutes(match.path, routerData).map(item => (
                <Route
                  key={item.key}
                  path={item.path}
                  component={item.component}
                  exact={item.exact}
                />
              ))}
79
              <Redirect from="/user" to={getLoginPathWithRedirectPath()} />
80
            </Switch>
81
          </div>
82
          <GlobalFooter links={links} copyright={copyright} />
83 84 85 86 87 88 89
        </div>
      </DocumentTitle>
    );
  }
}

export default UserLayout;