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
74 lines
1.8 KiB
import React, { useEffect } from "react";
|
|
|
|
import "./App.scss";
|
|
import { Outlet, useNavigate } from "react-router";
|
|
import { Layout } from "antd";
|
|
import { default as AppHeader } from "./components/Header";
|
|
import { default as AppFooter } from "./components/Footer";
|
|
import SideMenu from "./components/SideMenu";
|
|
import { createWebSocket, sharedWsUrl } from "./services/socket";
|
|
import { updateUser } from "./store/features/contextSlice";
|
|
import { useAppDispatch } from "./utils/hooks";
|
|
import { updateDeviceState } from "./store/device/deviceState";
|
|
const { Header, Footer, Sider, Content } = Layout;
|
|
|
|
function App() {
|
|
const navigate = useNavigate();
|
|
const dispatch = useAppDispatch();
|
|
|
|
useEffect(() => {
|
|
//连接websocket
|
|
const wsClient = createWebSocket(sharedWsUrl);
|
|
const subscription = wsClient.dataOb.subscribe(data => {
|
|
if (data.messageType === "DeviceContext") {
|
|
// if (data.data.loginFlag) {
|
|
// dispatch(updateUser(data.data));
|
|
// navigate("/measure/config");
|
|
// } else {
|
|
// navigate("/login");
|
|
// }
|
|
}else if(data.messageType === 'STATE'){
|
|
dispatch(updateDeviceState(data.data));
|
|
}
|
|
});
|
|
wsClient.connect();
|
|
return () => subscription.unsubscribe();
|
|
});
|
|
|
|
const headerStyle: React.CSSProperties = {
|
|
height: 64,
|
|
padding: 0,
|
|
};
|
|
|
|
const footerStyle: React.CSSProperties = {
|
|
height: 64,
|
|
padding: 0,
|
|
};
|
|
|
|
const layoutStyle = {
|
|
overflow: "hidden",
|
|
};
|
|
|
|
return (
|
|
<div className="">
|
|
<Layout style={layoutStyle}>
|
|
<Sider width="200px">
|
|
<SideMenu />
|
|
</Sider>
|
|
<Layout>
|
|
<Header style={headerStyle}>
|
|
<AppHeader />
|
|
</Header>
|
|
<Content>
|
|
<Outlet />
|
|
</Content>
|
|
<Footer style={footerStyle}>
|
|
<AppFooter />
|
|
</Footer>
|
|
</Layout>
|
|
</Layout>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default App;
|