index.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { CollaspedType } from '@/types/LayoutType';
  2. import { Outlet, useModel } from '@umijs/max';
  3. import {Avatar, Layout, Popover, Tabs} from 'antd';
  4. import { Header } from 'antd/es/layout/layout';
  5. import React, {useEffect, useState} from 'react';
  6. import SideMenu from './SideMenu';
  7. import UserPopover from './UserPopContent';
  8. import './styles/index.less';
  9. import {history, useLocation, useRouteProps} from "@@/exports";
  10. const { Sider, Content } = Layout;
  11. const contentStyle: React.CSSProperties = {
  12. textAlign: 'center',
  13. minHeight: 120,
  14. lineHeight: '120px',
  15. color: '#fff',
  16. };
  17. const siderStyle: React.CSSProperties = {
  18. textAlign: 'center',
  19. color: '#fff',
  20. };
  21. const layoutStyle = {
  22. overflow: 'hidden',
  23. height: '100vh',
  24. };
  25. const App: React.FC = () => {
  26. const [menuWidth] = useState(CollaspedType.OPEN);
  27. const { userInfo } = useModel('global');
  28. const routeProps = useRouteProps();
  29. const location = useLocation();
  30. const [selectedKeys, setSelectedKeys] = useState(location.pathname);
  31. useEffect(() => {
  32. if(location.pathname) {
  33. setSelectedKeys(location.pathname);
  34. }
  35. }, [location.pathname]);
  36. return (
  37. <Layout style={layoutStyle}>
  38. <Sider theme="light" width={menuWidth} style={siderStyle}>
  39. <SideMenu
  40. initWidth={menuWidth}
  41. onCollaped={() => {}}
  42. />
  43. </Sider>
  44. <Layout>
  45. <Header className="app-header">
  46. <Popover placement="bottom" content={<UserPopover />}>
  47. <div className="header-user">
  48. <Avatar style={{ backgroundColor: '#fde3cf', color: '#f56a00' }}>
  49. {userInfo.realName.charAt(0)}
  50. </Avatar>
  51. <span className="header-user-name"> {userInfo.realName}</span>
  52. </div>
  53. </Popover>
  54. </Header>
  55. <Content style={contentStyle}>
  56. <Tabs
  57. tabBarStyle={{ backgroundColor: '#fff', padding: '5px 20px 0' }}
  58. defaultActiveKey={selectedKeys}
  59. items={routeProps.custom}
  60. onChange={(e) => {
  61. history.push(e);
  62. }}
  63. />
  64. <Outlet />
  65. </Content>
  66. </Layout>
  67. </Layout>
  68. );
  69. };
  70. export default App;