index.tsx 933 B

12345678910111213141516171819202122232425262728
  1. import React, { useEffect, useState } from "react";
  2. import styles from "./index.module.scss";
  3. import history from "@/utils/history";
  4. function TopBarM() {
  5. const [activeIndex, setActiveIndex] = useState(0);
  6. useEffect(() => {
  7. const path = window.location.hash.split('/')[1]
  8. const index = myDataTemp.siderDataM.findIndex(item => item.path === path)
  9. setActiveIndex(index)
  10. }, [])
  11. const handleClick = (index: number, path: string) => {
  12. const pathRes = path === 'view' ? 'view/three' : path
  13. history.push(`/${pathRes}`)
  14. }
  15. return (
  16. <div className={styles.TopBarM}>
  17. {myDataTemp.siderDataM.map((item, index) => (
  18. <div className={`item ${index === activeIndex ? 'itemAc' : ''}`} key={index} onClick={() => handleClick(index, item.path)}>
  19. <div className="title">{item.title}</div>
  20. </div>
  21. ))}
  22. </div>
  23. )
  24. }
  25. const MemoTopBarM = React.memo(TopBarM);
  26. export default MemoTopBarM;