Pārlūkot izejas kodu

fix: 修改轮询

ansoni 1 mēnesi atpakaļ
vecāks
revīzija
775b69a126

+ 5 - 0
src/api/user.ts

@@ -320,6 +320,11 @@ export interface UserVipInfo {
      * vip等级经验
      */
     vip_score_exp: number;
+
+    /**
+     * vip 最高返水
+     */
+    vip_cashback: number;
 }
 export const getUserVipApi = () => {
     return server.post<UserVipInfo>({

+ 18 - 43
src/app/[locale]/(TabBar)/[[...share]]/@actionWidget/Service.tsx

@@ -1,8 +1,6 @@
 "use client";
 import { getWheelApi } from "@/api/cashWheel";
 import { ServiceTypes } from "@/api/customservice";
-import { lredPacketApi, redPacketApi } from "@/api/promo";
-import { getGiveInfoApi } from "@/api/slots";
 import { Timeout } from "@/components/ModalPopup/RechargeModal";
 import RedPacketModal, { RedPacketModalProps } from "@/components/ModalPopup/RedPacketModal";
 import SlotsModal, { SlotModalRefProps } from "@/components/ModalPopup/SlotsModal";
@@ -10,8 +8,10 @@ import dialogManage from "@/dialog/manager";
 
 import { useEventPoint } from "@/hooks/useEventPoint";
 import { Link } from "@/i18n/routing";
+import { useActivityStore } from "@/stores/useActivityStore";
 import { useFirstPayStore } from "@/stores/useFirstPayStore";
 import { useGlobalNoticeStore } from "@/stores/useGlobalNoticeStore";
+import { usePollingStore } from "@/stores/usePollingStore";
 import useWheelStore from "@/stores/useWheelStore";
 import { getToken } from "@/utils/Cookies";
 import { useRequest } from "ahooks";
@@ -32,23 +32,13 @@ interface SlotSectionProps {
  */
 const SlotSection: FC<SlotSectionProps> = ({ onDestory }) => {
     const slotsRef = useRef<SlotModalRefProps | null>(null);
-    const getSlots = async () => {
-        const token = getToken();
-        if (token) {
-            const result = await getGiveInfoApi();
-            return result.data;
-        } else {
-            destory();
-            return Promise.resolve({});
-        }
-    };
 
-    const { data: slots, run: slotRun } = useRequest<any, any>(getSlots, {
-        pollingInterval: 2000,
-        pollingErrorRetryCount: 1,
-    });
+    const { slotsData } = useActivityStore((state) => ({
+        slotsData: state.slotsData,
+    }));
+    const refresh = usePollingStore((state) => state.refresh);
     const slotHandler = () => {
-        slotsRef.current?.onOpen(slots);
+        slotsRef.current?.onOpen(slotsData);
     };
     const destory = () => {
         if (onDestory && typeof onDestory === "function") onDestory();
@@ -56,7 +46,7 @@ const SlotSection: FC<SlotSectionProps> = ({ onDestory }) => {
 
     return (
         <>
-            {slots?.id ? (
+            {slotsData?.id ? (
                 <img
                     src={"/slots/slots-icon.gif"}
                     className={"mb-[0.2778rem] w-[100%]"}
@@ -66,7 +56,7 @@ const SlotSection: FC<SlotSectionProps> = ({ onDestory }) => {
             ) : null}
 
             {/*随机送*/}
-            <SlotsModal ref={slotsRef} onAfterHandler={slotRun} onClose={destory} />
+            <SlotsModal ref={slotsRef} onAfterHandler={refresh} onClose={destory} />
         </>
     );
 };
@@ -155,33 +145,18 @@ const PaySection = () => {
 const RedPacketSection = () => {
     const token = getToken();
     const redPacketModalRef = useRef<RedPacketModalProps>(null);
-    const getRedPacketInfo = async () => {
-        try {
-            let redPacketInfo: any;
-            let actList: any = [];
-            if (token) {
-                redPacketInfo = await lredPacketApi();
-                actList = redPacketInfo.data?.red_packets || [];
-            } else {
-                redPacketInfo = await redPacketApi();
-                actList = redPacketInfo.data || [];
-            }
+    const refresh = usePollingStore((state) => state.refresh);
 
-            // 已经开始
-            return actList.filter((aItem: any) => {
-                return aItem.is_start;
-            });
-        } catch (error) {}
-    };
-    // 红包雨轮询
-    const { data: packets, run } = useRequest<any[], any>(getRedPacketInfo, {
-        pollingInterval: 5000,
-        pollingErrorRetryCount: 1,
-        pollingWhenHidden: false,
+    const { redPacketsData } = useActivityStore((state) => ({
+        redPacketsData: state.redPacketsData,
+    }));
+
+    const packets: any = redPacketsData?.red_packets?.filter((aItem: any) => {
+        return aItem.is_start;
     });
     return (
         <>
-            {packets?.map((item, index) => {
+            {packets?.map((item: any, index: number) => {
                 const icons = JSON.parse(item.icon);
                 const icon = icons[icons.length - 1];
                 return (
@@ -199,7 +174,7 @@ const RedPacketSection = () => {
             })}
 
             {/*红包雨弹窗*/}
-            <RedPacketModal ref={redPacketModalRef} onAfterHandler={run} />
+            <RedPacketModal ref={redPacketModalRef} onAfterHandler={refresh} />
         </>
     );
 };

+ 28 - 31
src/app/[locale]/(TabBar)/profile/ProfileHeader.tsx

@@ -1,14 +1,7 @@
 "use client";
 import { GameListRep, GameRequest } from "@/api/home";
 import { userInfoApi } from "@/api/login";
-import {
-    UserInfoRep,
-    UserVipInfo,
-    Wallet,
-    cleanBounsApi,
-    getUserMoneyApi,
-    getUserTransferApi,
-} from "@/api/user";
+import { UserInfoRep, cleanBounsApi, getUserTransferApi } from "@/api/user";
 import {
     BalanceContent,
     BonusContent,
@@ -18,6 +11,8 @@ import {
 import TipsModal, { ModalProps } from "@/components/TipsModal";
 import useGame from "@/hooks/useGame";
 import { Link, useRouter } from "@/i18n/routing";
+import { usePollingStore } from "@/stores/usePollingStore";
+import { useVipStore } from "@/stores/useVipStore";
 import { useWalletStore } from "@/stores/useWalletStore";
 import { WalletEnum } from "@/types";
 import { vipImages } from "@/utils/constant";
@@ -29,12 +24,10 @@ import { Fragment, useEffect, useRef, useState } from "react";
 
 type Props = {
     userInfo: UserInfoRep;
-    userMoney: Wallet;
-    userVip: UserVipInfo;
 };
-const VipCard = (props: { userVip: UserVipInfo }) => {
-    const { userVip } = props;
+const VipCard = () => {
     const t = useTranslations("ProfilePage");
+    const userVip = useVipStore((state) => state.vipData);
 
     // Vip 图标
     const vipIconElement = vipImages.map((item, index) => {
@@ -83,8 +76,9 @@ const VipCard = (props: { userVip: UserVipInfo }) => {
     );
 };
 
-const WalletCard = (props: { userMoney: Wallet }) => {
-    const { userMoney } = props;
+const WalletCard = () => {
+    // const { userMoney } = props;
+    const userMoney = useWalletStore((state) => state.wallet);
     const t = useTranslations("ProfilePage");
     const tcdoe = useTranslations();
 
@@ -223,7 +217,7 @@ const WalletCard = (props: { userMoney: Wallet }) => {
                             </div>
                             <div className="num">
                                 <span className="uppercase">brl </span>
-                                <span>{userMoney.score || 0.0}</span>
+                                <span>{userMoney?.score || 0.0}</span>
                             </div>
                         </section>
                     </div>
@@ -232,7 +226,7 @@ const WalletCard = (props: { userMoney: Wallet }) => {
                         onClick={() => modalHandler(WalletEnum.Bonus)}
                     >
                         <Badge
-                            content={userMoney.is_point_transfer ? Badge.dot : null}
+                            content={userMoney?.is_point_transfer ? Badge.dot : null}
                             style={{ right: "10px" }}
                         >
                             <div className="wallet-right-icon">
@@ -246,7 +240,7 @@ const WalletCard = (props: { userMoney: Wallet }) => {
                             </div>
                             <div className="num">
                                 <span className="uppercase">brl </span>
-                                <span>{userMoney.point || 0.0}</span>
+                                <span>{userMoney?.point || 0.0}</span>
                             </div>
                         </section>
                     </div>
@@ -359,27 +353,29 @@ const NoBounsWarn = ({ visible, onClose, onConfirm }: any) => {
     );
 };
 export const ProfileHeader = (props: Props) => {
-    const { userInfo, userVip } = props;
+    const { userInfo } = props;
     const t = useTranslations("ProfilePage");
-
-    const { wallet, setWallet } = useWalletStore((state) => ({
-        wallet: state.wallet,
-        setWallet: state.setWallet,
-    }));
+    const target_point_rollover = useWalletStore((state) => state.wallet?.target_point_rollover);
+    const score = useWalletStore((state) => state.wallet?.score);
+    const point = useWalletStore((state) => state.wallet?.point);
+    const no_bonus_config = useWalletStore((state) => state.wallet?.no_bonus_config);
+    const refresh = usePollingStore((state) => state.refresh);
     const router = useRouter();
     const [isShowNoBounsWarn, setIsShowNoBounsWarn] = useState(false);
     const [isShowed, setIsShowed] = useState(false);
+
     useEffect(() => {
-        const curMul = wallet.target_point_rollover / ((wallet?.score || 0) + (wallet.point || 0));
-        const config = wallet.no_bonus_config;
+        const curMul = target_point_rollover / ((score || 0) + (point || 0));
+
+        const config = no_bonus_config;
         if (curMul >= (config || 0) && !isShowed) {
             setIsShowNoBounsWarn(true);
             setIsShowed(true);
         }
-    }, [wallet]);
+    }, []);
 
     const handler = () => {
-        if (!!wallet.score) {
+        if (!!score) {
             router.push("/withdraw");
         } else {
             Toast.show("no money ");
@@ -404,8 +400,9 @@ export const ProfileHeader = (props: Props) => {
             content: t("success"),
             icon: "success",
         });
-        const walletRes = await getUserMoneyApi();
-        setWallet(walletRes?.data);
+        // const walletRes = await getUserMoneyApi();
+        // setWallet(walletRes?.data);
+        refresh && refresh();
     };
 
     return (
@@ -436,9 +433,9 @@ export const ProfileHeader = (props: Props) => {
                     ></Link>
                 </div>
                 {/*vipcard*/}
-                <VipCard userVip={userVip} />
+                <VipCard />
 
-                <WalletCard userMoney={wallet} />
+                <WalletCard />
             </div>
 
             <div className="link">

+ 4 - 9
src/app/[locale]/(TabBar)/profile/component/ItemCom/index.tsx

@@ -3,8 +3,8 @@ import { CashbackTypes } from "@/api/cashback";
 import { getWheelApi } from "@/api/cashWheel";
 import { useRouter } from "@/i18n/routing";
 import { useGlobalNoticeStore } from "@/stores/useGlobalNoticeStore";
+import { useVipStore } from "@/stores/useVipStore";
 import { server } from "@/utils/client";
-import { useRequest } from "ahooks";
 import { Badge, Toast } from "antd-mobile";
 import { useTranslations } from "next-intl";
 import { FC } from "react";
@@ -50,14 +50,9 @@ const ItemCom: FC<ItemComProps> = ({ type = "login" }) => {
         unread: state.unread,
         userUnread: state.userUnred,
     }));
-    const { data: cashback } = useRequest<any, any>(getCashBackApi, {
-        pollingErrorRetryCount: 1,
-    });
 
-    const max = cashback?.rules.reduce(
-        (acc: any, item: any) => (acc > item.cashback ? acc : item.cashback),
-        0
-    );
+    const vipInfo = useVipStore((state) => state.vipData);
+
     const links = [
         // { label: "gratis", desc: "gratisDesc", icon: "", url: "/", content: null },
         {
@@ -77,7 +72,7 @@ const ItemCom: FC<ItemComProps> = ({ type = "login" }) => {
             content: null,
         },
         {
-            label: t("cashback", { max: max }),
+            label: t("cashback", { max: vipInfo?.vip_cashback ?? 0 }),
             desc: "",
             icon: "icon-qiandai",
             color: "#ff9b23",

+ 2 - 6
src/app/[locale]/(TabBar)/profile/layout.tsx

@@ -1,6 +1,6 @@
 import HeaderBack from "@/components/HeaderBack";
 import { getTranslations } from "next-intl/server";
-import { ReactNode, Suspense } from "react";
+import { ReactNode } from "react";
 
 export const generateMetadata = async () => {
     const t = await getTranslations("titles");
@@ -18,11 +18,7 @@ export default async function LocaleLayout({
     return (
         <div className="profilPage h-[100%] overflow-auto bg-[url('/home/bg.jpg')]">
             <HeaderBack showBack={true} useBg={true} title="Perfil" />
-            <main className={"main-header"}>
-              <Suspense fallback={<div></div>}>
-                {children}
-              </Suspense>
-            </main>
+            <main className={"main-header"}>{children}</main>
         </div>
     );
 }

+ 0 - 82
src/app/[locale]/(TabBar)/profile/page-back.tsx

@@ -1,82 +0,0 @@
-import { CashbackTypes } from "@/api/cashback";
-import { UserInfoRep, UserVipInfo } from "@/api/user";
-import { getMoneyApi } from "@/api/userWallt";
-import { server } from "@/utils/server";
-import ItemCom from "./component/ItemCom";
-import ModalCom from "./component/ModalCom";
-import "./page.scss";
-import { ProfileHeader } from "./ProfileHeader";
-
-const getUserInfo = async () => {
-    return server
-        .request<UserInfoRep>({
-            url: "/v1/api/user/user_info",
-            method: "POST",
-            next: { revalidate: 0 },
-        })
-        .then((res) => {
-            if (res.code === 200) return res.data;
-            return {};
-        });
-};
-
-/**
- * @description  前台用户VIP信息 接口地址:https://app.apifox.com/link/project/4790544/apis/api-201160713
- */
-const getVipApi = async () => {
-    return server
-        .request<UserVipInfo>({
-            url: "/v1/api/user/user_vip_info",
-            method: "POST",
-            cache: "no-cache",
-        })
-        .then((res) => {
-            if (res.code === 200) return res.data;
-        });
-};
-
-const getCashBackApi = async () => {
-    return server
-        .request<CashbackTypes>({
-            url: "/v1/api/front/activity_cash",
-            method: "post",
-        })
-        .then((res) => {
-            return res.data;
-        })
-        .catch((error) => {
-            return {
-                rules: [],
-                last_period: { end_time: 0, start_time: 0 },
-                next_period: {
-                    end_time: 0,
-                    start_time: 0,
-                },
-                amount: 0,
-                bet: 0,
-                status: "expired",
-            };
-        });
-};
-export const dynamic = "force-dynamic";
-export const revalidate = 0;
-const Profile = async () => {
-    const userInfo = await getUserInfo();
-    const userMoney = await getMoneyApi();
-    const userVip = await getVipApi();
-    const cashback = await getCashBackApi();
-    const max = cashback?.rules.reduce(
-        (acc, item) => (acc > item.cashback ? acc : item.cashback),
-        0
-    );
-
-    return (
-        <div className="profile-box">
-            <ProfileHeader userInfo={userInfo} userMoney={userMoney} userVip={userVip!} />
-            <ItemCom />
-            <ModalCom />
-        </div>
-    );
-};
-
-export default Profile;

+ 1 - 28
src/app/[locale]/(TabBar)/profile/page.tsx

@@ -1,46 +1,19 @@
 "use client";
 import { userInfoApi } from "@/api/login";
-import { getUserMoneyApi, UserVipInfo } from "@/api/user";
-import { server } from "@/utils/client";
 import { useRequest } from "ahooks";
 import ItemCom from "./component/ItemCom";
 import ModalCom from "./component/ModalCom";
 import "./page.scss";
 import { ProfileHeader } from "./ProfileHeader";
 
-/**
- * @description  前台用户VIP信息 接口地址:https://app.apifox.com/link/project/4790544/apis/api-201160713
- */
-const getVipApi = async () => {
-    return server
-        .request<UserVipInfo>({
-            url: "/v1/api/user/user_vip_info",
-            method: "POST",
-        })
-        .then((res) => {
-            if (res.code === 200) return res.data;
-        });
-};
-
 const Profile = () => {
     const { data: userInfo } = useRequest<any, any>(userInfoApi, {
         pollingErrorRetryCount: 1,
     });
-    const { data: userMoney } = useRequest<any, any>(getUserMoneyApi, {
-        pollingErrorRetryCount: 1,
-        pollingWhenHidden: false,
-    });
-    const { data: userVip } = useRequest<any, any>(getVipApi, {
-        pollingErrorRetryCount: 1,
-    });
 
     return (
         <div className="profile-box">
-            <ProfileHeader
-                userInfo={userInfo?.data}
-                userMoney={userMoney?.data}
-                userVip={userVip}
-            />
+            <ProfileHeader userInfo={userInfo?.data} />
             <ItemCom />
             <ModalCom />
         </div>

+ 2 - 23
src/app/[locale]/(doings)/signin/page.tsx

@@ -1,48 +1,27 @@
 "use client";
 /* eslint-disable @next/next/no-img-element */
 import { claimActivityReward } from "@/api/activity";
-import { UserVipInfo } from "@/api/user";
 import GlobalNotify from "@/components/ModalPopup/GlobalNotifyModal";
 import { BoxListCom } from "@/components/ModalPopup/SignInModal";
 import { ClaimActiveErrorMap } from "@/enums";
 import { useSignStore } from "@/stores/useSignStore";
+import { useVipStore } from "@/stores/useVipStore";
 import { formatAmount } from "@/utils";
-import { server } from "@/utils/client";
 import { Toast } from "antd-mobile";
 import BigNumber from "bignumber.js";
 import { useTranslations } from "next-intl";
 import { useSearchParams } from "next/navigation";
 import { FC, useEffect, useMemo, useState } from "react";
 
-const getVipApi = async () => {
-    return server
-        .request<UserVipInfo>({
-            url: "/v1/api/user/user_vip_info",
-            method: "POST",
-        })
-        .then((res) => {
-            if (res.code === 200) return res.data;
-        });
-};
-
 const SignIn: FC = () => {
     const searchParams = useSearchParams();
     const activity_id = Number(searchParams.get("activity_id"));
     const t = useTranslations("signInPage");
     const tCode = useTranslations();
-    const [vipInfo, setVipInfo] = useState<UserVipInfo | null>(null);
     const [visible, setVisible] = useState(false);
     const [amount, setAmount] = useState({});
 
-    useEffect(() => {
-        getVipInfo();
-    }, []);
-    const getVipInfo = async () => {
-        const vipInfoRes = await getVipApi();
-        if (vipInfoRes) {
-            setVipInfo(vipInfoRes);
-        }
-    };
+    const vipInfo = useVipStore((state) => state.vipData);
 
     const { getSignData, signData } = useSignStore((state) => ({
         signData: state.signData,

+ 0 - 1
src/app/[locale]/(navbar)/cashback/page.tsx

@@ -55,7 +55,6 @@ const CashbackInfo = async () => {
     const vipInfo = await getVipInfoApi();
     const cashbackInfo = await getCashBackApi();
 
-    console.log(112233, cashbackInfo);
     const currentGrade = cashbackInfo.rules?.find(
         (item) => item.level === (vipInfo.vip_level || 1)
     );

+ 78 - 8
src/app/[locale]/providers.tsx

@@ -18,7 +18,12 @@ import { setupFontSize } from "@/utils";
 import { Local } from "@/utils/storage";
 import { motion } from "framer-motion";
 
+import { useEventPoint } from "@/hooks/useEventPoint";
+import { useActivityStore } from "@/stores/useActivityStore";
+import { useGlobalNoticeStore } from "@/stores/useGlobalNoticeStore";
 import { PollingState, usePollingStore } from "@/stores/usePollingStore";
+import { useSuspensionStore } from "@/stores/useSuspensionStore";
+import { useVipStore } from "@/stores/useVipStore";
 import { useWalletStore } from "@/stores/useWalletStore";
 import styles from "./style.module.scss";
 
@@ -95,11 +100,11 @@ const getStopServiceApi = () => {
  * @description  停服通知
  */
 const StopServiceClient = () => {
-    const data = usePollingStore((state) => state.system_suspension);
+    const able = useSuspensionStore((state) => state.able);
 
     return (
         <>
-            {data?.able && (
+            {able && (
                 <div
                     className={
                         "absolute left-0 right-0 top-[0.4rem] z-[99999] bg-[#fff] p-[20px]" +
@@ -141,15 +146,80 @@ const getPollingApi = () => {
 };
 
 const PollingClient = () => {
-    const setWallet = useWalletStore((state) => state.setWallet);
     // 用户钱包
-    useRequest(getPollingApi, {
-        pollingInterval: 3000,
+    const setWallet = useWalletStore((state) => state.setWallet);
+
+    // 系统通知
+    const { unread, userUnred, setNotices, setUserUnread, promotion_count, setPromotionCount } =
+        useGlobalNoticeStore((state) => ({
+            unread: state.unread,
+            setNotices: state.setNotices,
+            setUserUnread: state.setUserUnread,
+            setPromotionCount: state.setPromotionCount,
+            userUnred: state.userUnred,
+            promotion_count: state.promotion_count,
+        }));
+
+    //   事件上报
+    const { eventPurchase, eventFirstDeposit } = useEventPoint();
+    // 活动
+    const { setSlotsData, setRedPacketsData } = useActivityStore((state) => ({
+        setSlotsData: state.setSlotsData,
+        setRedPacketsData: state.setRedPacketsData,
+    }));
+    // 缓存刷新事件
+    const { setPollingRefresh, setPollingCancel } = usePollingStore((state) => ({
+        setPollingRefresh: state.setPollingRefresh,
+        setPollingCancel: state.setPollingCancel,
+    }));
+
+    // vip
+    const setVipData = useVipStore((state) => state.setVipData);
+    // 停服
+    const setSuspensionData = useSuspensionStore((state) => state.setSuspensionData);
+    const { data, run, cancel } = useRequest(getPollingApi, {
+        pollingInterval: 5000,
         pollingErrorRetryCount: 3,
         onSuccess: (data) => {
-            // setPollingState(data);
-            console.log(`🚀🚀🚀🚀🚀-> in providers.tsx on 151`, data.user_info);
-            setWallet(data.user_info);
+            const {
+                activity_give,
+                red_packets,
+                system_notice,
+                system_suspension,
+                user_info,
+                user_latest_deposit,
+                user_letter,
+                user_vip_info,
+            } = data;
+            setPollingRefresh(run);
+            setPollingCancel(cancel);
+            // 钱包信息
+            setWallet(user_info);
+            //  系统通知
+            setNotices(system_notice?.data || [], system_notice?.summery?.unread || 0);
+            setPromotionCount(system_notice?.summery?.promotion_count || 0);
+            // 站内信
+            setUserUnread(user_letter?.summery?.unread || 0);
+            // 活动相关 - 定时免费送
+            setSlotsData(activity_give);
+            // 活动 - 红包雨
+            setRedPacketsData(red_packets);
+
+            // vip
+            setVipData(user_vip_info);
+
+            // 停服
+            // @ts-ignore
+            setSuspensionData({ ...system_suspension });
+
+            //  首充事件上报
+            if (user_latest_deposit?.is_first_pay === 1) {
+                eventFirstDeposit();
+                return;
+            }
+            if (user_latest_deposit?.is_success === 1) {
+                eventPurchase();
+            }
         },
     });
 

+ 3 - 3
src/app/[locale]/template.tsx

@@ -10,9 +10,9 @@ const Template = ({ children }: { children: ReactNode }) => {
             <motion.div
                 layout
                 key={key}
-                initial={{ scale: 0.9, opacity: 0 }}
-                animate={{ scale: 1, opacity: 1 }}
-                exit={{ scale: 0.9, opacity: 0 }}
+                initial={{ y: 30, opacity: 0 }}
+                animate={{ y: 0, scale: 1, opacity: 1 }}
+                exit={{ y: -20, opacity: 0 }}
                 transition={{ duration: 0.3 }}
                 className={"h-[100%]"}
             >

+ 3 - 3
src/components/Footer/index.tsx

@@ -134,10 +134,10 @@ const Footer: FC = () => {
 
     useEffect(() => {
         if (getToken()) {
-            run();
+            // run();
             // walletRun();
-            userRun();
-            depositRun();
+            // userRun();
+            // depositRun();
         }
     }, []);
 

+ 1 - 3
src/components/Header/HeaderRight.tsx

@@ -10,10 +10,8 @@ import styles from "./style.module.scss";
 const HeaderRight = () => {
     const router = useRouter();
     const t = useTranslations("Header");
-
     const token = getToken();
-    const score = useWalletStore((state) => state.wallet.score);
-
+    const score = useWalletStore((state) => state?.wallet?.score);
     // ✅ 主动预加载常用页面,仅在浏览器 + router ready 时执行
     useEffect(() => {
         router.prefetch("/profile");

+ 2 - 2
src/components/ModalPopup/SlotsModal/index.tsx

@@ -383,7 +383,7 @@ const SlotsClient: FC<SlotsClientProps> = (props) => {
 };
 export type SlotModalRefProps = {
     onClose: () => void;
-    onOpen: (value: SlotType) => void;
+    onOpen: (value: SlotType | null) => void;
 };
 export interface SlotsModalProps {
     onClose?: () => void;
@@ -399,7 +399,7 @@ const SlotsModal = forwardRef<SlotModalRefProps, SlotsModalProps>(function Slots
     useImperativeHandle(ref, () => {
         return {
             onClose: () => setVisible(false),
-            onOpen: (source: SlotType) => {
+            onOpen: (source: SlotType | null) => {
                 setVisible(true);
                 setSlotSource(source);
             },

+ 21 - 1
src/stores/index.ts

@@ -1 +1,21 @@
-//  TODO 将各个store 整合为一个库 // 添加统一清除方法
+import type { StateCreator } from "zustand";
+import { create } from "zustand";
+
+const storeResetFns = new Set<() => void>();
+
+const resetAllStores = () => {
+    storeResetFns.forEach((resetFn) => {
+        resetFn();
+    });
+};
+
+export const actualCreate = (<T>() => {
+    return (stateCreator: StateCreator<T>) => {
+        const store = create(stateCreator);
+        const initialState = store.getInitialState();
+        storeResetFns.add(() => {
+            store.setState(initialState, true);
+        });
+        return store;
+    };
+}) as typeof create;

+ 31 - 0
src/stores/useActivityStore.ts

@@ -0,0 +1,31 @@
+import { SlotType } from "@/api/slots";
+import { create } from "zustand";
+interface SuspensionType {
+    able: boolean;
+}
+export interface ActivityState {
+    slotsData: SlotType | null;
+    redPacketsData: any | null;
+}
+
+interface Actions {
+    setSlotsData: (values: ActivityState["slotsData"]) => void;
+    setRedPacketsData: (values: ActivityState["redPacketsData"]) => void;
+    // reset: () => void;
+}
+
+const initialState: ActivityState = {
+    slotsData: null,
+    redPacketsData: null,
+};
+
+export const useActivityStore = create<ActivityState & Actions>((set, getState) => {
+    return {
+        ...initialState,
+        setSlotsData: (values: ActivityState["slotsData"]) =>
+            set((state) => ({ ...state, slotsData: values })),
+        setRedPacketsData: (values: ActivityState["redPacketsData"]) => {
+            set((state) => ({ ...state, redPacketsData: values }));
+        },
+    };
+});

+ 30 - 10
src/stores/usePollingStore.ts

@@ -1,6 +1,6 @@
 import { NoticeRep } from "@/api/home";
 import { SlotType } from "@/api/slots";
-import { DepositsLatestRep, Wallet } from "@/api/user";
+import { DepositsLatestRep, UserVipInfo, Wallet } from "@/api/user";
 import { create } from "zustand";
 interface SuspensionType {
     able: boolean;
@@ -9,15 +9,20 @@ export interface PollingState {
     /**
      * 免费领取活动信息
      */
-    activity_give?: SlotType;
+    activity_give: SlotType | null;
+    /**
+     * 用户VIP信息
+     */
+    user_vip_info: UserVipInfo | null;
     /**
      * 红包信息
      */
     red_packets?: { [key: string]: any };
+
     /**
      * 系统公告信息
      */
-    system_notice?: NoticeRep;
+    system_notice?: { data: NoticeRep[]; summery: { unread: number; promotion_count: number } };
     /**
      * 系统停服信息
      */
@@ -33,20 +38,31 @@ export interface PollingState {
     /**
      * 站内信消息
      */
-    user_letter?: NoticeRep;
+    user_letter?: { data: NoticeRep[]; summery: { unread: number } };
+
     /**
-     * 用户VIP信息
+     * 轮询刷新事件
+     */
+    refresh: () => void;
+    /**
+     * 轮询取消事件
      */
-    user_vip_info?: { [key: string]: any };
+    cancel: () => void;
 }
 
 interface Actions {
     setPollingState: (partialState: Partial<PollingState>) => void;
     // // setActivity: (values: PollingState["activity_give"]) => void;
     // reset: () => void;
+
+    setPollingRefresh: (func: () => void) => void;
+    setPollingCancel: (func: () => void) => void;
 }
 
-const initialState: PollingState = {};
+const initialState: Partial<PollingState> = {
+    refresh: () => {},
+    cancel: () => {},
+};
 
 // export const usePollingStore = create<PollingState & Actions>()(
 //     immer((set) => ({
@@ -58,14 +74,18 @@ const initialState: PollingState = {};
 //     }))
 // );
 
-export const usePollingStore = create<PollingState & Actions>((set, getState) => {
+export const usePollingStore = create<Partial<PollingState> & Actions>((set, getState) => {
     return {
         ...initialState,
         setPollingState: (values) => {
-            const preValue = JSON.stringify(values);
-            const oldValue = JSON.stringify(getState());
+            // const preValue = JSON.stringify(values);
+            // const oldValue = JSON.stringify(getState());
             //  todo 数据无变化则不更新。
             set((state) => ({ ...state, ...values }));
         },
+        setPollingRefresh: (func: PollingState["refresh"]) =>
+            set((state) => ({ ...state, refresh: func })),
+        setPollingCancel: (func: PollingState["cancel"]) =>
+            set((state) => ({ ...state, cancel: func })),
     };
 });

+ 21 - 0
src/stores/useSuspensionStore.ts

@@ -0,0 +1,21 @@
+import { create } from "zustand";
+interface SuspensionType {
+    able: boolean;
+    time: number;
+}
+
+interface Action {
+    setSuspensionData: (value: SuspensionType) => void;
+}
+
+const initialState: Partial<SuspensionType> = {};
+/**
+ * @description vip
+ */
+export const useSuspensionStore = create<Partial<SuspensionType> & Action>()((set, get) => {
+    return {
+        ...initialState,
+        setSuspensionData: (values) => set((state) => ({ ...state, ...values })),
+        // reset: () => set(initialState),
+    };
+});

+ 29 - 0
src/stores/useVipStore.ts

@@ -0,0 +1,29 @@
+import { UserVipInfo } from "@/api/user";
+import { create } from "zustand";
+
+interface State {
+    vipData: UserVipInfo | null;
+}
+
+interface Action {
+    setVipData: (value: State["vipData"]) => void;
+}
+
+const initialState: State = {
+    vipData: { vip_exp: 0, vip_level: 0, vip_next_level: 0, vip_score_exp: 0, vip_cashback: 0 },
+};
+/**
+ * @description vip
+ */
+export const useVipStore = create<State & Action>()((set, get) => {
+    return {
+        ...initialState,
+        setVipData: (values: State["vipData"]) =>
+            set((state) => {
+                return values
+                    ? { ...state, vipData: values }
+                    : { ...state, vipData: initialState.vipData };
+            }),
+        reset: () => set(initialState),
+    };
+});