Browse Source

Merge branch 'feature-year0506' of bcwin/site_front into v1.4

year 2 tháng trước cách đây
mục cha
commit
79c90dbe07

+ 1 - 1
src/app/[locale]/(doings)/continuous/page.tsx

@@ -85,7 +85,7 @@ const DayItem = ({
                 <div className={styles.premioItemDay}>
                     <span style={{ color: dayColor }}>{data.days}</span>
                 </div>
-                <div className="flex flex-col justify-between">
+                <div className="flex flex-1 flex-col justify-between">
                     <div className="text-[.16rem] font-bold">
                         Recarga contínua por {data.days} dias
                     </div>

+ 1 - 1
src/app/[locale]/(doings)/rechargeproxy/page.tsx

@@ -71,7 +71,7 @@ const DayItem = ({
                 <div className={styles.premioItemDay}>
                     <span style={{ color: dayColor }}>{data.days}</span>
                 </div>
-                <div className="flex flex-col justify-between">
+                <div className="flex flex-1 flex-col justify-between">
                     <div className="text-[.16rem] font-bold">
                         Recarga contínua por {data.days} dias
                     </div>

+ 49 - 21
src/dialog/auto.ts

@@ -1,12 +1,17 @@
 "use client";
 import { PromotionRep } from "@/api/home";
+import { useUserInfoStore } from "@/stores/useUserInfoStore";
 import { server } from "@/utils/client";
-import { getToken } from "@/utils/Cookies";
+import { Local } from "@/utils/storage";
 import dayjs from "dayjs";
 import React from "react";
 import dialogManage from "./manager";
 
-//"ImgDialog","WheelSection", "SignInSection", "HomePromotion", "TextDialog"
+const keyMap: any = {
+    1: "ban_pop_type_1",
+    2: "pop_type_2",
+    3: "pop_type_3",
+};
 
 const getPromotions = async () => {
     return server
@@ -21,10 +26,11 @@ const getPromotions = async () => {
 
 const AutoShowDialog = () => {
     const [data, setData] = React.useState<PromotionRep[]>([]);
+    const { userInfo } = useUserInfoStore();
 
     React.useEffect(() => {
         getData();
-    }, []);
+    }, [userInfo]);
     React.useEffect(() => {
         if (!data.length) return;
         setTimeout(() => {
@@ -40,15 +46,45 @@ const AutoShowDialog = () => {
         }
     };
     const checkIsShowed = (data: PromotionRep) => {
-        const showTime = localStorage.getItem(`dialog_${data.id}`);
-        if (showTime) {
-            const nextDay = dayjs(Number(showTime)).add(1, "day").format("YYYY-MM-DD");
-            if ((dayjs(nextDay).isAfter(dayjs()), "day")) {
+        if (!data?.id || data.pop_type === 3) return false;
+        let popData = Local.getKey(keyMap[data.pop_type]);
+        if (!popData) return false;
+        try {
+            const isCurDay = dayjs(popData.date).add(1, "day").isAfter(dayjs(), "day");
+            if (isCurDay && popData[userInfo.id][data.id]) {
                 return true;
             }
-        }
+        } catch {}
         return false;
     };
+
+    const saveCache = (type: 1 | 2 | 3, popid: number) => {
+        if (!userInfo?.id) return;
+        const cachedData = Local.getKey(keyMap[type]);
+        console.log(cachedData);
+        let popData: any = {
+            date: Date.now(),
+        };
+        if (cachedData) {
+            try {
+                if (dayjs(cachedData.date).isSame(Date.now(), "day")) {
+                    popData = cachedData;
+                } else {
+                    Local.removeKey(keyMap[type]);
+                }
+            } catch {}
+        }
+        if (!popData[userInfo.id]) {
+            popData[userInfo.id] = {};
+        }
+        popData[userInfo.id][popid] = true;
+        Local.setKey(keyMap[type], JSON.stringify(popData));
+    };
+
+    const saveShowIndex = (idx: number) => {
+        sessionStorage.setItem("dialogShow", `${idx + 1}`);
+    };
+
     const doShow = async () => {
         //记录点击的索引
         let showIndex = sessionStorage.getItem("dialogShow");
@@ -59,13 +95,8 @@ const AutoShowDialog = () => {
         for (let i = startShow; i < data.length; i++) {
             const curData = data[i];
             // 一天只展示一次
-            if (curData.pop_type === 1 && checkIsShowed(curData)) {
-                sessionStorage.setItem("dialogShow", `${i + 1}`);
-                continue;
-            }
-            // 未登录的用户不展示
-            if (curData.pop_type === 2 && !getToken()) {
-                sessionStorage.setItem("dialogShow", `${i + 1}`);
+            if (checkIsShowed(curData)) {
+                saveShowIndex(i);
                 continue;
             }
 
@@ -86,15 +117,12 @@ const AutoShowDialog = () => {
                         break;
                 }
             } catch (err) {
-                sessionStorage.setItem("dialogShow", `${i + 1}`);
+                saveShowIndex(i);
                 continue;
             }
-            // 一天只展示一次
-            if (curData.pop_type === 1) {
-                localStorage.setItem(`dialog_${curData.id}`, Date.now().toString());
-            }
             // 记录当前展示到几个了
-            sessionStorage.setItem("dialogShow", `${i + 1}`);
+            saveShowIndex(i);
+            if (curData.id) saveCache(curData.pop_type, curData.id);
         }
     };
 

+ 9 - 5
src/hooks/useLogout.ts

@@ -19,12 +19,16 @@ export const useLogout = () => {
             restGlobal();
             resetSearch();
             restWalletStore();
-            for (let i = 0; i < Local.length; i++) {
-                const key = Local.key(i)!;
-                if (key.indexOf("ban") === -1) {
-                    Local.removeKey(key);
-                }
+            const keys: string[] = [];
+            for (let i = 0, len = Local.length; i < len; i++) {
+                const key = Local.key(i);
+                keys.push(key || "");
             }
+            keys.forEach((key) => {
+                if (key && key.indexOf("ban") === -1) {
+                    Local.removeKey(key as any);
+                }
+            });
             Cookies.remove("Token");
             router.replace("/login");
         }

+ 3 - 1
src/stores/useUserInfoStore.ts

@@ -22,7 +22,9 @@ export const useUserInfoStore = create<State & Action>()(
                         set({
                             userInfo,
                         }),
-                    reset: () => set(initialState),
+                    reset: () => {
+                        set(initialState);
+                    },
                 };
             },
             {

+ 3 - 0
src/utils/storage/index.ts

@@ -4,6 +4,9 @@ interface StorageKey {
     ban_pixel_id: string;
     ban_click_id: string;
     channel_code: string;
+    ban_pop_type_1: string;
+    pop_type_2: string;
+    pop_type_3: string;
 }
 type Key = Extract<keyof StorageKey, string>;
 class CustomStorage {