SiderBlock.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import React from 'react';
  2. import {Layout, Menu} from "antd";
  3. import {
  4. BorderBottomOutlined,
  5. HeatMapOutlined, MacCommandOutlined, OneToOneOutlined, SlidersOutlined,
  6. UploadOutlined,
  7. UserOutlined,
  8. VideoCameraOutlined, WindowsOutlined
  9. } from "@ant-design/icons";
  10. import CollapsedStore from "../../store/CollapsedStore.ts";
  11. import {observer} from "mobx-react-lite";
  12. import {useLocation, useNavigate} from "react-router-dom";
  13. import {MyItemType} from "../../pages/UniService/type.ts";
  14. function SiderBlock() {
  15. const { Sider} = Layout;
  16. const navigate = useNavigate();
  17. const menuItems:MyItemType[] = [
  18. {
  19. key: '1',
  20. icon: <UserOutlined />,
  21. label: '统一服务',
  22. to:'/'
  23. },
  24. {
  25. key: '2',
  26. icon: <VideoCameraOutlined />,
  27. label: '报警联动',
  28. to:'/alarm'
  29. },
  30. {
  31. key: '3',
  32. icon: <UploadOutlined />,
  33. label: '设备接入',
  34. to:'/devicesInsert'
  35. },
  36. {
  37. key: '4',
  38. icon: <BorderBottomOutlined />,
  39. label: '阈值修改',
  40. to:'/threshold'
  41. },
  42. {
  43. key: '5',
  44. icon: <HeatMapOutlined />,
  45. label: '报警查看处理',
  46. to:'/CheckProcess'
  47. },
  48. {
  49. key: '6',
  50. icon: <SlidersOutlined />,
  51. label: '参数监测',
  52. to:'/monitor'
  53. },
  54. {
  55. key: '7',
  56. icon: <WindowsOutlined />,
  57. label: '远程控制',
  58. to:'/remoteControl'
  59. },
  60. {
  61. key: '8',
  62. icon: <MacCommandOutlined />,
  63. label: '远程自检',
  64. to:'/remoteCheck'
  65. },
  66. {
  67. key: '9',
  68. icon: <OneToOneOutlined />,
  69. label: '定时任务',
  70. to:'/timingTask'
  71. },
  72. {
  73. key: '10',
  74. icon: <VideoCameraOutlined />,
  75. label: '历史统计',
  76. to:'/history'
  77. },
  78. ];
  79. const selectedKeys = ['1'];
  80. const {pathname} = useLocation();
  81. const currentMenu = menuItems.find(item => item.to == pathname);
  82. if (currentMenu) {
  83. selectedKeys[0] = currentMenu.key;
  84. }
  85. const onMenuSelect = ({key}) => {
  86. const item:MyItemType | undefined= menuItems.find(item => item.key === key);
  87. if (item) {
  88. if(item.to){
  89. navigate(item.to)
  90. }
  91. }
  92. };
  93. return (
  94. <>
  95. <Sider trigger={null} collapsible collapsed={CollapsedStore.collapsed}>
  96. <div className={'text-white text-center p-20px font-900 text-18px bg-gray bg-op-80 m-20px rounded-lg'}>
  97. {!CollapsedStore.collapsed?
  98. (<div className={'flex flex-col items-center'}>
  99. <div className={'w-50px h-50px m-auto'}>
  100. <img className={'w-full h-full'} src={'./src/assets/灯杆.png'}/>
  101. </div>
  102. <span className={'line-clamp-1'}>智慧灯杆系统</span>
  103. </div>):
  104. <img className={'w-30px h-20px translate-x--13px'} src={'./src/assets/灯杆.png'}/>}
  105. </div>
  106. <Menu
  107. theme="dark"
  108. mode="inline"
  109. defaultSelectedKeys={selectedKeys}
  110. onSelect={onMenuSelect}
  111. items={menuItems.map(item => ({
  112. key: item.key,
  113. icon: item.icon,
  114. label: item.label,
  115. }))}
  116. />
  117. </Sider>
  118. </>
  119. );
  120. }
  121. export default observer(SiderBlock);