Menu.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import styles from "./Menu.module.less";
  2. import clsx from "clsx";
  3. import { useEffect, useState } from "react";
  4. import { useNavigate } from "react-router-dom";
  5. export default function Menu() {
  6. let navigate = useNavigate();
  7. const [active, setActive] = useState<string>("");
  8. useEffect(() => {
  9. initMenu();
  10. }, []);
  11. async function initMenu() {
  12. // const config = LogicalSize;
  13. // console.log({ LogicalSize: new LogicalSize() });
  14. // console.log(window);
  15. // setHeight(await window);
  16. }
  17. const menuConfig = [
  18. {
  19. label: "常用",
  20. child: [
  21. {
  22. label: "文件整理",
  23. path: "/file-sort",
  24. },
  25. {
  26. label: "文件清理",
  27. path: "/file-clear",
  28. },
  29. {
  30. label: "重复文件",
  31. path: "/duplicateFile",
  32. },
  33. ],
  34. },
  35. {
  36. label: "系统",
  37. child: [
  38. {
  39. label: "字符查询",
  40. },
  41. {
  42. label: "设置",
  43. path: "/setting",
  44. },
  45. {
  46. label: "关于我们",
  47. path: "/about",
  48. },
  49. ],
  50. },
  51. ];
  52. function menuHandle(path: string, label: string) {
  53. setActive(label);
  54. navigate(path);
  55. }
  56. return (
  57. <div className={clsx(styles.box, styles.parent)}>
  58. <div className={styles.logoBox}>占位符:</div>
  59. {menuConfig.map((item) => (
  60. <div className={styles.menuBox} key={item.label}>
  61. <div className={styles.label}>{item.label}</div>
  62. <div className={styles.menuChildBox}>
  63. {item?.child?.length > 0 &&
  64. item?.child.map((childItem) => (
  65. <div
  66. key={childItem.label}
  67. className={clsx(
  68. styles.childItemLabel,
  69. active === childItem.label && styles.active
  70. )}
  71. onClick={() =>
  72. menuHandle(childItem.path || "", childItem.label)
  73. }
  74. >
  75. {childItem.label}
  76. </div>
  77. ))}
  78. </div>
  79. </div>
  80. ))}
  81. </div>
  82. );
  83. }