"src/locales/pt-BR/analysis.js" did not exist on "3e9d2956bb0fc3dd607b713ca9078d1cc1408b7b"
index.tsx 4.29 KB
Newer Older
1 2
import React, { Component } from 'react';
import { connect } from 'dva';
3
import { Dispatch } from 'redux';
陈帅's avatar
陈帅 committed
4
import { FormattedMessage } from 'umi-plugin-react/locale';
陈帅's avatar
陈帅 committed
5
import { GridContent } from '@ant-design/pro-layout';
6 7 8 9 10 11
import { Menu } from 'antd';
import styles from './style.less';
import BaseView from './components/base';
import SecurityView from './components/security';
import BindingView from './components/binding';
import NotificationView from './components/notification';
12
import { CurrentUser } from './data';
13 14 15

const { Item } = Menu;

16
interface PAGE_NAME_UPPER_CAMEL_CASEProps {
陈帅's avatar
陈帅 committed
17
  dispatch: Dispatch<any>;
18 19 20 21 22 23 24 25 26 27 28 29
  currentUser: CurrentUser;
}

type PAGE_NAME_UPPER_CAMEL_CASEStateKeys = 'base' | 'security' | 'binding' | 'notification';
interface PAGE_NAME_UPPER_CAMEL_CASEState {
  mode: 'inline' | 'horizontal';
  menuMap: {
    [key: string]: React.ReactNode;
  };
  selectKey: PAGE_NAME_UPPER_CAMEL_CASEStateKeys;
}
@connect(({ BLOCK_NAME_CAMEL_CASE }: { BLOCK_NAME_CAMEL_CASE: { currentUser: CurrentUser } }) => ({
30 31
  currentUser: BLOCK_NAME_CAMEL_CASE.currentUser,
}))
32 33 34 35
class PAGE_NAME_UPPER_CAMEL_CASE extends Component<
  PAGE_NAME_UPPER_CAMEL_CASEProps,
  PAGE_NAME_UPPER_CAMEL_CASEState
> {
陈帅's avatar
陈帅 committed
36
  main: HTMLDivElement | undefined;
陈帅's avatar
陈帅 committed
37

38
  constructor(props: PAGE_NAME_UPPER_CAMEL_CASEProps) {
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    super(props);
    const menuMap = {
      base: <FormattedMessage id="BLOCK_NAME.menuMap.basic" defaultMessage="Basic Settings" />,
      security: (
        <FormattedMessage id="BLOCK_NAME.menuMap.security" defaultMessage="Security Settings" />
      ),
      binding: (
        <FormattedMessage id="BLOCK_NAME.menuMap.binding" defaultMessage="Account Binding" />
      ),
      notification: (
        <FormattedMessage
          id="BLOCK_NAME.menuMap.notification"
          defaultMessage="New Message Notification"
        />
      ),
    };
    this.state = {
      mode: 'inline',
      menuMap,
      selectKey: 'base',
    };
  }

  componentDidMount() {
    const { dispatch } = this.props;
    dispatch({
      type: 'BLOCK_NAME_CAMEL_CASE/fetchCurrent',
    });
    window.addEventListener('resize', this.resize);
    this.resize();
  }

  componentWillUnmount() {
    window.removeEventListener('resize', this.resize);
  }

75
  getMenu = () => {
76 77 78 79 80 81 82 83 84
    const { menuMap } = this.state;
    return Object.keys(menuMap).map(item => <Item key={item}>{menuMap[item]}</Item>);
  };

  getRightTitle = () => {
    const { selectKey, menuMap } = this.state;
    return menuMap[selectKey];
  };

85
  selectKey = (key: PAGE_NAME_UPPER_CAMEL_CASEStateKeys) => {
86 87 88 89 90 91 92 93 94 95 96 97 98
    this.setState({
      selectKey: key,
    });
  };

  resize = () => {
    if (!this.main) {
      return;
    }
    requestAnimationFrame(() => {
      if (!this.main) {
        return;
      }
99
      let mode: 'inline' | 'horizontal' = 'inline';
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
      const { offsetWidth } = this.main;
      if (this.main.offsetWidth < 641 && offsetWidth > 400) {
        mode = 'horizontal';
      }
      if (window.innerWidth < 768 && offsetWidth > 400) {
        mode = 'horizontal';
      }
      this.setState({
        mode,
      });
    });
  };

  renderChildren = () => {
    const { selectKey } = this.state;
    switch (selectKey) {
      case 'base':
        return <BaseView />;
      case 'security':
        return <SecurityView />;
      case 'binding':
        return <BindingView />;
      case 'notification':
        return <NotificationView />;
      default:
        break;
    }

    return null;
  };

  render() {
    const { currentUser } = this.props;
    if (!currentUser.userid) {
      return '';
    }
    const { mode, selectKey } = this.state;
    return (
陈帅's avatar
陈帅 committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
      <GridContent>
        <div
          className={styles.main}
          ref={ref => {
            if (ref) {
              this.main = ref;
            }
          }}
        >
          <div className={styles.leftMenu}>
            <Menu
              mode={mode}
              selectedKeys={[selectKey]}
              onClick={({ key }) => this.selectKey(key as PAGE_NAME_UPPER_CAMEL_CASEStateKeys)}
            >
              {this.getMenu()}
            </Menu>
          </div>
          <div className={styles.right}>
            <div className={styles.title}>{this.getRightTitle()}</div>
            {this.renderChildren()}
          </div>
160
        </div>
陈帅's avatar
陈帅 committed
161
      </GridContent>
162 163 164 165 166
    );
  }
}

export default PAGE_NAME_UPPER_CAMEL_CASE;