import React, { Component } from 'react';
import { connect } from 'dva';
import { Dispatch } from 'redux';
import { FormattedMessage } from 'umi-plugin-react/locale';
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';
import { CurrentUser } from './data';
const { Item } = Menu;
interface PAGE_NAME_UPPER_CAMEL_CASEProps {
dispatch: Dispatch;
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 } }) => ({
currentUser: BLOCK_NAME_CAMEL_CASE.currentUser,
}))
class PAGE_NAME_UPPER_CAMEL_CASE extends Component<
PAGE_NAME_UPPER_CAMEL_CASEProps,
PAGE_NAME_UPPER_CAMEL_CASEState
> {
constructor(props: PAGE_NAME_UPPER_CAMEL_CASEProps) {
super(props);
const menuMap = {
base: ,
security: (
),
binding: (
),
notification: (
),
};
this.state = {
mode: 'inline',
menuMap,
selectKey: 'base',
};
}
main: HTMLDivElement | undefined;
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);
}
getMenu = () => {
const { menuMap } = this.state;
return Object.keys(menuMap).map(item => - {menuMap[item]}
);
};
getRightTitle = () => {
const { selectKey, menuMap } = this.state;
return menuMap[selectKey];
};
selectKey = (key: PAGE_NAME_UPPER_CAMEL_CASEStateKeys) => {
this.setState({
selectKey: key,
});
};
resize = () => {
if (!this.main) {
return;
}
requestAnimationFrame(() => {
if (!this.main) {
return;
}
let mode: 'inline' | 'horizontal' = 'inline';
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 ;
case 'security':
return ;
case 'binding':
return ;
case 'notification':
return ;
default:
break;
}
return null;
};
render() {
const { currentUser } = this.props;
if (!currentUser.userid) {
return '';
}
const { mode, selectKey } = this.state;
return (
{
if (ref) {
this.main = ref;
}
}}
>
{this.getRightTitle()}
{this.renderChildren()}
);
}
}
export default PAGE_NAME_UPPER_CAMEL_CASE;