page.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use client";
  2. import {Flex} from "antd";
  3. import {getCookie} from "cookies-next";
  4. import {useRouter} from "next/navigation";
  5. import {useEffect, useState} from "react";
  6. import PuffLoader from "react-spinners/PuffLoader";
  7. import styles from "./page.module.css";
  8. import {displayModeIsDark} from "./_modules/func";
  9. //浅色
  10. const lightColor = "white";
  11. //深色
  12. const darkColor = "black";
  13. //主要颜色
  14. const color = "#1677ff";
  15. export default function Home() {
  16. const { push } = useRouter();
  17. //是否深色模式
  18. const [backgroundColor, setBackgroundColor] = useState(lightColor);
  19. useEffect(() => {
  20. const token = getCookie("token");
  21. if (token === "") {
  22. push("/login");
  23. } else {
  24. push("/home");
  25. }
  26. setBackgroundColor(displayModeIsDark() ? darkColor : lightColor);
  27. }, []);
  28. return (
  29. <Flex
  30. vertical
  31. className={styles.bodyContent}
  32. style={{ backgroundColor: backgroundColor }}
  33. justify="center"
  34. align="center"
  35. >
  36. <PuffLoader
  37. color={color}
  38. loading={true}
  39. size={150}
  40. aria-label="Loading"
  41. />
  42. <span style={{ color: color, marginTop: "16px" }}>
  43. 正在加载...请稍后...
  44. </span>
  45. </Flex>
  46. );
  47. }