auto.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use client";
  2. import React from "react";
  3. import dialogManage from "./manager";
  4. const AutoShowDialog = () => {
  5. const [data, setData] = React.useState<string[]>([]);
  6. React.useEffect(() => {
  7. getData();
  8. }, []);
  9. React.useEffect(() => {
  10. if (!data.length) return;
  11. setTimeout(() => {
  12. doShow();
  13. }, 300);
  14. // eslint-disable-next-line react-hooks/exhaustive-deps
  15. }, [data]);
  16. const getData = async () => {
  17. //"ImgDialog",
  18. setData(["WheelSection", "SignInSection", "HomePromotion"]);
  19. };
  20. const doShow = async () => {
  21. let showIndex = sessionStorage.getItem("dialogShow");
  22. let startShow = showIndex ? Number(showIndex) : 0;
  23. if (startShow > data.length - 1) {
  24. startShow = 0;
  25. }
  26. for (let i = startShow; i < data.length; i++) {
  27. const key = data[i];
  28. await dialogManage.showDialog(key);
  29. sessionStorage.setItem("dialogShow", `${i + 1}`);
  30. }
  31. };
  32. return null;
  33. };
  34. export default AutoShowDialog;