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.

57 lines
2.3 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. import icon_bluetooth from '../assets/icon_bluetooth.svg';
  2. import icon_arr_d from '../assets/icon_arr_down.svg';
  3. import './CustomNavBar.scss';
  4. import { useState } from 'react';
  5. import { useAppSelector } from '../utils/hooks';
  6. import { useNavigate } from 'react-router-dom';
  7. export default function CustomNavBar({ title }: { title: string }) {
  8. const navigate = useNavigate();
  9. const device = useAppSelector((state) => state.context.device);
  10. const [showDetail, setShowDetail] = useState(false);
  11. return (
  12. <div className="relative bg-white h-[--navBarHeight] border-b border-[#D8D8D8]">
  13. {/** 温度,水平仪 */}
  14. <div
  15. className="absolute h-[30px] w-full bg-white border border-[#D8D8D8] flex items-center gap-2 px-2"
  16. style={{ top: device.connected && showDetail ? '100%' : 0, transition: 'top 300ms' }}
  17. >
  18. <span className="flex-1">: {device.temperature.toFixed(1)}°C</span>
  19. <span className="flex-1">X轴倾斜: {device.inclinatorX.toFixed(2)}</span>
  20. <span className="flex-1">Y轴倾斜: {device.inclinatorY.toFixed(2)}</span>
  21. </div>
  22. {/** 导航栏 */}
  23. <div className="absolute left-0 top-0 w-full h-full flex items-center px-3 bg-white">
  24. <h1 className="text-lg text-text ml-3">{title}</h1>
  25. {/** 蓝牙连接状态 */}
  26. {device.connected ? (
  27. <div
  28. className="ml-auto flex items-center cursor-pointer"
  29. onClick={() => setShowDetail(!showDetail)}
  30. >
  31. <div className="bluetooth-battery flex justify-center items-center">{device.power}%</div>
  32. <img src={icon_bluetooth} alt="icon" className="mx-2" />
  33. <span></span>
  34. <img
  35. src={icon_arr_d}
  36. alt="arr"
  37. style={{
  38. transform: device.connected && showDetail ? 'rotate(180deg)' : 'rotate(0deg)',
  39. transition: 'transform 300ms',
  40. }}
  41. />
  42. </div>
  43. ) : (
  44. <div
  45. className="ml-auto flex items-center cursor-pointer"
  46. onClick={() => navigate('/home/bluetooth')}
  47. >
  48. <img src={icon_bluetooth} alt="icon" className="mx-2" />
  49. <span></span>
  50. </div>
  51. )}
  52. </div>
  53. </div>
  54. );
  55. }