index.tsx 957 B

12345678910111213141516171819202122232425262728293031323334
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import { useEffect, useState } from 'react';
  3. import Comprehensive from './comprehensive';
  4. import Device from './device';
  5. import Init from './init';
  6. import Ops from './ops';
  7. import Service from './service';
  8. export const service = new Service();
  9. const Home = () => {
  10. type ViewType = keyof typeof ViewMap;
  11. const [current, setCurrent] = useState<ViewType>('comprehensive');
  12. const ViewMap = {
  13. init: <Init changeView={(value: ViewType) => setCurrent(value)} />,
  14. device: <Device />,
  15. ops: <Ops />,
  16. comprehensive: <Comprehensive />,
  17. };
  18. useEffect(() => {
  19. service.queryView().then((resp) => {
  20. if (resp.status === 200) {
  21. if (resp.result.length == 0) {
  22. setCurrent('init');
  23. } else {
  24. setCurrent(resp.result[0]?.content);
  25. }
  26. }
  27. });
  28. }, []);
  29. return <PageContainer>{ViewMap[current]}</PageContainer>;
  30. };
  31. export default Home;