index.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Api from './Api';
  8. import Service from './service';
  9. import { Skeleton } from 'antd';
  10. export const service = new Service();
  11. const Home = () => {
  12. type ViewType = keyof typeof ViewMap;
  13. const [current, setCurrent] = useState<ViewType>('init'); // 默认为初始化
  14. const [loading, setLoading] = useState(true);
  15. const [detail, setDetail] = useState<any>({});
  16. const ViewMap = {
  17. init: <Init changeView={(value: ViewType) => setCurrent(value)} />,
  18. device: <Device />,
  19. ops: <Ops />,
  20. comprehensive: <Comprehensive />,
  21. };
  22. useEffect(() => {
  23. service.queryView().then((resp) => {
  24. setLoading(false);
  25. if (resp.status === 200) {
  26. if (resp.result.length == 0) {
  27. setCurrent('init');
  28. } else {
  29. setCurrent(resp.result[0]?.content);
  30. }
  31. }
  32. });
  33. }, []);
  34. useEffect(() => {
  35. service.userDetail().then((res) => {
  36. if (res.status === 200) {
  37. service
  38. .apiDetail({
  39. terms: [
  40. {
  41. column: 'userId',
  42. value: res.result.id,
  43. },
  44. ],
  45. })
  46. .then((response) => {
  47. if (response.status === 200) {
  48. setDetail(response.result?.data);
  49. }
  50. });
  51. }
  52. });
  53. }, []);
  54. return (
  55. <PageContainer>
  56. <Skeleton loading={loading} active>
  57. {detail && detail.length > 0 ? <Api /> : <>{ViewMap[current]}</>}
  58. </Skeleton>
  59. </PageContainer>
  60. );
  61. };
  62. export default Home;