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.

139 lines
3.8 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
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. import { useSelector } from "react-redux";
  2. import bluetooth_nc from "../assets/bluetooth_nc.svg";
  3. import bluetooth_c from "../assets/bluetooth_c.svg";
  4. import icon_avatar from "../assets/icon_avatar.svg";
  5. import icon_logout from "../assets/icon_logout.svg";
  6. import check_mark from "../assets/check_mark.svg";
  7. import icon_pwd from "../assets/icon_pwd.svg";
  8. import { useState, useEffect } from "react";
  9. import {updateDeviceState } from '../store/device/deviceState';
  10. // import { bluetoothList, bluetoothInfo } from '../mock/recordList'
  11. import { Dropdown, MenuProps, message, Button, Popover } from "antd";
  12. import { logout } from "../services/user/user";
  13. import { getDeviceInfo } from "../services/device/deviceState"
  14. import "./bluetooth.scss";
  15. import { useAppSelector } from "../utils/hooks";
  16. import { Device } from "../services/measure/type";
  17. export default function Header() {
  18. console.log('updateDeviceState---', updateDeviceState)
  19. let [isConnect, setIsConnect] = useState(false)
  20. //@ts-ignoref
  21. const deviceState = useSelector(store => store.deviceState);
  22. const [bluetoothInfo, setBluetoothInfo] = useState(deviceState)
  23. console.log('deviceState---',deviceState)
  24. //获取当前websocet的状态
  25. const showBlueImg = () => {
  26. if(!isConnect){
  27. return <Popover content={getBtList()} title="可连接设备">
  28. <div ></div>
  29. <img src={bluetooth_nc} alt="" className="ext-base ml-2 h-6" />
  30. </Popover>
  31. }else {
  32. return <Popover content={getBtContent()} title="">
  33. <img src={bluetooth_c} onClick={onDisconnectBt} alt="" className="ext-base ml-2 h-6" />
  34. </Popover>
  35. }
  36. }
  37. let [bluetoothList, setbluetoothList] = useState<Device[]>([])
  38. //获取mock数据
  39. useEffect(()=>{
  40. getDeviceInfo().then(res => {
  41. console.log('res===', res)
  42. //@ts-ignore
  43. setbluetoothList(res.data.list)
  44. })
  45. })
  46. //@ts-ignore
  47. const context = useSelector(store => store.context);
  48. const [messageApi, contextHolder] = message.useMessage();
  49. const items: MenuProps["items"] = [
  50. // {
  51. // key: "1",
  52. // label: "修改密码",
  53. // icon: <img src={icon_pwd} alt="" className="w-[18px]" />,
  54. // onClick: () => {
  55. // messageApi.info('ok')
  56. // },
  57. // },
  58. {
  59. key: "2",
  60. label: "退出登录",
  61. icon: <img src={icon_logout} alt="icon" className="w-5" />,
  62. onClick: () => {
  63. logout({}).then(res => {
  64. if (res.status !== 0) {
  65. messageApi.error(res.data.info)
  66. }
  67. })
  68. }
  69. },
  70. ];
  71. const getBtList = () => {
  72. let Dom = null
  73. if(!isConnect){
  74. Dom = <div>
  75. {bluetoothList.map(item => {
  76. return <div className="mt-[1rem]" onClick={connectBt}>
  77. <Button type="link">{item.name}</Button>
  78. </div>
  79. })}
  80. </div>
  81. }
  82. return Dom
  83. }
  84. //蓝牙已连接
  85. const getBtContent = ()=> {
  86. return <div>
  87. <div>
  88. <div className="bluetooth_c">
  89. <img src={check_mark} alt="" className="ext-base ml-2 h-4" />
  90. <div className="ml-[10px]"></div>
  91. </div>
  92. <div className="pl-[15px]">
  93. <div className="mt-[1rem]">{bluetoothInfo.connectPort}</div>
  94. {/* <div className="mt-[1rem]">电量:{bluetoothInfo.power}</div> */}
  95. </div>
  96. </div>
  97. </div>
  98. }
  99. //断开蓝牙连接
  100. const onDisconnectBt = ()=> {
  101. setIsConnect(false)
  102. }
  103. const connectBt = () => {
  104. setIsConnect(true)
  105. setTimeout(()=>{
  106. },1000)
  107. }
  108. return (
  109. <>
  110. {contextHolder}
  111. <div className="bg-[--bgColor] h-full flex items-center">
  112. <div className="ml-auto mr-8 flex items-center">
  113. <div className="ml-auto mr-8 flex items-center w-[5rem]">
  114. {showBlueImg()}
  115. </div>
  116. <Dropdown menu={{ items }} trigger={["click"]}>
  117. <section className="flex items-center">
  118. <img src={icon_avatar} alt="" className="h-8" />
  119. <p className="text-base ml-2">{context.user.loginFlag ? context.user.loginUser.nickname : "未登录"}</p>
  120. </section>
  121. </Dropdown>
  122. </div>
  123. </div>
  124. </>
  125. );
  126. }