|
@@ -3,6 +3,7 @@ import { PromotionRep } from "@/api/home";
|
|
|
import { usePathname } from "@/i18n/routing";
|
|
|
import { useUserInfoStore } from "@/stores/useUserInfoStore";
|
|
|
import useWheelStore from "@/stores/useWheelStore";
|
|
|
+import { commonMask } from "@/utils";
|
|
|
import { server } from "@/utils/client";
|
|
|
import { getToken } from "@/utils/Cookies";
|
|
|
import { Local } from "@/utils/storage";
|
|
@@ -33,13 +34,19 @@ const AutoShowDialog = () => {
|
|
|
const [data, setData] = React.useState<PromotionRep[]>([]);
|
|
|
const { userInfo } = useUserInfoStore();
|
|
|
const wheelState = useWheelStore((state) => state);
|
|
|
+ const [cacheUserInfo, setCacheUserInfo] = React.useState<any>({});
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
- getData();
|
|
|
- }, [userInfo]);
|
|
|
+ if (cacheUserInfo.id !== userInfo.id) {
|
|
|
+ getData();
|
|
|
+ setCacheUserInfo(userInfo);
|
|
|
+ }
|
|
|
+ }, [userInfo, cacheUserInfo]);
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
- if (!data.length) return;
|
|
|
+ if (!data?.length) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
setTimeout(() => {
|
|
|
doShow();
|
|
|
}, 300);
|
|
@@ -47,19 +54,17 @@ const AutoShowDialog = () => {
|
|
|
}, [data]);
|
|
|
|
|
|
const getData = async () => {
|
|
|
- const dom: HTMLDialogElement | null = document.querySelector("#globalMask");
|
|
|
- if (dom) {
|
|
|
- dom.style.display = "flex";
|
|
|
- }
|
|
|
+ commonMask.show();
|
|
|
try {
|
|
|
const res = await getPromotions();
|
|
|
if (res?.code === 200 && res?.data?.length) {
|
|
|
setData(res.data);
|
|
|
+ if (!res.data?.length) {
|
|
|
+ commonMask.hide();
|
|
|
+ }
|
|
|
}
|
|
|
- } finally {
|
|
|
- // if (dom) {
|
|
|
- // dom.style.display = "none";
|
|
|
- // }
|
|
|
+ } catch {
|
|
|
+ commonMask.hide();
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -107,7 +112,6 @@ const AutoShowDialog = () => {
|
|
|
popData[userInfo.id] = {};
|
|
|
}
|
|
|
popData[userInfo.id][popid] = true;
|
|
|
-
|
|
|
Local.setKey(keyMap[type], JSON.stringify(popData));
|
|
|
};
|
|
|
|
|
@@ -116,6 +120,9 @@ const AutoShowDialog = () => {
|
|
|
};
|
|
|
|
|
|
const doShow = async () => {
|
|
|
+ setTimeout(() => {
|
|
|
+ commonMask.hide();
|
|
|
+ }, 500);
|
|
|
//记录点击的索引
|
|
|
let showIndex = sessionStorage.getItem("dialogShow");
|
|
|
let startShow = showIndex ? Number(showIndex) : 0;
|
|
@@ -124,9 +131,6 @@ const AutoShowDialog = () => {
|
|
|
}
|
|
|
|
|
|
for (let i = startShow; i < data.length; i++) {
|
|
|
- if (pathName === "/") {
|
|
|
- return;
|
|
|
- }
|
|
|
const curData = data[i];
|
|
|
if (!checkIsCanShow(curData)) {
|
|
|
saveShowIndex(i);
|