You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. import type { MenuProps } from "antd";
  2. import { Menu } from "antd";
  3. import icon_logo from "../assets/icon_logo.svg";
  4. import icon_measure from "../assets/menu/icon_measure.svg";
  5. import { useNavigate, useLocation } from "react-router-dom";
  6. import "./SideMenu.scss";
  7. type MenuItem = Required<MenuProps>["items"][number];
  8. const items: MenuItem[] = [
  9. {
  10. key: "measure",
  11. label: "测量",
  12. icon: <img src={icon_measure} alt="" />,
  13. children: [
  14. {
  15. key: "/measure/config",
  16. label: "新测量",
  17. },
  18. {
  19. key: "/measure/detail",
  20. label: "测量记录",
  21. }
  22. ],
  23. },
  24. ];
  25. export default function SideMenu() {
  26. const navigate = useNavigate();
  27. const location = useLocation();
  28. const key =
  29. location.pathname === "/measure/detail"
  30. ? "/measure/detail"
  31. : location.pathname.startsWith("/measure")
  32. ? "/measure/config"
  33. : location.pathname;
  34. const onClick: MenuProps["onClick"] = e => {
  35. navigate(e.key);
  36. };
  37. return (
  38. <div className="h-[100vh] bg-primary flex flex-col">
  39. <img src={icon_logo} alt="" className="w-[120px] block mx-auto py-4 " />
  40. <Menu
  41. className="side-menu"
  42. onClick={onClick}
  43. style={{ width: "100%", backgroundColor: "transparent", color: "#fff" }}
  44. defaultOpenKeys={["measure"]}
  45. selectedKeys={[key]}
  46. mode="inline"
  47. items={items}
  48. />
  49. <p className="text-white/[0.7] text-center mt-auto mb-4 text-lg">V1.0</p>
  50. </div>
  51. );
  52. }