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.

74 lines
1.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
5 months ago
  1. import React, { useEffect } from "react";
  2. import "./App.scss";
  3. import { Outlet, useNavigate } from "react-router";
  4. import { Layout } from "antd";
  5. import { default as AppHeader } from "./components/Header";
  6. import { default as AppFooter } from "./components/Footer";
  7. import SideMenu from "./components/SideMenu";
  8. import { createWebSocket, sharedWsUrl } from "./services/socket";
  9. import { updateUser } from "./store/features/contextSlice";
  10. import { useAppDispatch } from "./utils/hooks";
  11. import { updateDeviceState } from "./store/device/deviceState";
  12. const { Header, Footer, Sider, Content } = Layout;
  13. function App() {
  14. const navigate = useNavigate();
  15. const dispatch = useAppDispatch();
  16. useEffect(() => {
  17. //连接websocket
  18. const wsClient = createWebSocket(sharedWsUrl);
  19. const subscription = wsClient.dataOb.subscribe(data => {
  20. if (data.messageType === "DeviceContext") {
  21. // if (data.data.loginFlag) {
  22. // dispatch(updateUser(data.data));
  23. // navigate("/measure/config");
  24. // } else {
  25. // navigate("/login");
  26. // }
  27. }else if(data.messageType === 'STATE'){
  28. dispatch(updateDeviceState(data.data));
  29. }
  30. });
  31. wsClient.connect();
  32. return () => subscription.unsubscribe();
  33. });
  34. const headerStyle: React.CSSProperties = {
  35. height: 64,
  36. padding: 0,
  37. };
  38. const footerStyle: React.CSSProperties = {
  39. height: 64,
  40. padding: 0,
  41. };
  42. const layoutStyle = {
  43. overflow: "hidden",
  44. };
  45. return (
  46. <div className="">
  47. <Layout style={layoutStyle}>
  48. <Sider width="200px">
  49. <SideMenu />
  50. </Sider>
  51. <Layout>
  52. <Header style={headerStyle}>
  53. <AppHeader />
  54. </Header>
  55. <Content>
  56. <Outlet />
  57. </Content>
  58. <Footer style={footerStyle}>
  59. <AppFooter />
  60. </Footer>
  61. </Layout>
  62. </Layout>
  63. </div>
  64. );
  65. }
  66. export default App;