Explorar o código

fix: 动态判断代币类型

ansoni hai 4 meses
pai
achega
2f19f0ffa5

+ 3 - 110
src/app/[locale]/(TabBar)/[[...share]]/_home/HomePrize.tsx

@@ -1,14 +1,8 @@
 "use client";
 import { PrizeTypes } from "@/api/home";
-import Box from "@/components/Box";
-import styles from "@/components/Card/style.module.scss";
-import useGame from "@/hooks/useGame";
-import { useRouter } from "@/i18n/routing";
-import { useWalletStore } from "@/stores/useWalletStore";
-import { getToken } from "@/utils/Cookies";
-import { Button, Popup } from "antd-mobile";
+import { Card } from "@/components/Card";
 import { useTranslations } from "next-intl";
-import { FC, useRef, useState } from "react";
+import { FC } from "react";
 import { Autoplay } from "swiper/modules";
 import { Swiper, SwiperSlide } from "swiper/react";
 
@@ -21,53 +15,6 @@ const HomePrize: FC<Props> = (props) => {
     const t = useTranslations("HomePage");
     const tt = useTranslations("Game");
 
-    const [winImg, setWinImg] = useState<any>([{}]);
-    // const { run, cancel } = useRequest(gamesNoticeWinApi, {
-    //     pollingInterval: 600000,
-    //     pollingWhenHidden: true,
-    //     pollingErrorRetryCount: 3,
-    //     staleTime: 5000,
-    //     onError: (error) => {},
-    //     onSuccess: (res) => {
-    //         console.log(`🚀🚀🚀🚀🚀-> in HomePrize.tsx on 30`, res);
-    //         setWinImg(res.data || []);
-    //     },
-    // });
-
-    const [visible, setVisible] = useState(false);
-    // const [gameInfo, setGameInfo] = useState<any>({});
-    const gameInfo = useRef<PrizeTypes | null>(null);
-    const handler = (game: PrizeTypes) => {
-        setVisible(true);
-        console.log(`🚀🚀🚀🚀🚀-> in HomePrize.tsx on 39`, game);
-        // setGameInfo(game);
-
-        gameInfo.current = game;
-    };
-
-    const router = useRouter();
-    const token = getToken();
-    const wallet = useWalletStore((state) => state.wallet);
-    const { getGameUrl } = useGame();
-    const playGameHandler = () => {
-        setVisible(true);
-        if (!token) {
-            router.push("/login?redirect=/");
-            return;
-        }
-        let groupType = 1;
-        if (groupType === 1 && Number(wallet.score) + wallet.point <= 0) {
-            router.push("/deposit");
-            return;
-        }
-
-        const params: any = {
-            id: gameInfo.current?.id + "",
-            mode: groupType!,
-        };
-        getGameUrl(gameInfo.current!, params);
-    };
-
     return (
         <div className={"my-[0.0694rem]"}>
             <div className={"mb-[0.0347rem]"}>{t("prize")}</div>
@@ -88,15 +35,9 @@ const HomePrize: FC<Props> = (props) => {
                     <SwiperSlide key={index}>
                         <div
                             className={"w-[1.1rem] bg-[#1c1e22]"}
-                            onClick={() => handler(prize)}
                             style={{ borderRadius: ".1rem" }}
                         >
-                            <img
-                                className={"h-[1.54rem]"}
-                                src={prize.game_icon}
-                                alt=""
-                                style={{ borderRadius: ".1rem" }}
-                            />
+                            <Card item={prize} />
                             <div className={"px-[0.13rem] pb-[0.0347rem] text-[0.13rem]"}>
                                 <p className={"text-[#98a7b5]"}>
                                     {prize.phone
@@ -109,54 +50,6 @@ const HomePrize: FC<Props> = (props) => {
                     </SwiperSlide>
                 ))}
             </Swiper>
-            <Popup
-                visible={visible}
-                onMaskClick={() => {
-                    setVisible(false);
-                }}
-                onClose={() => {
-                    setVisible(false);
-                }}
-                showCloseButton={true}
-                getContainer={() => document.querySelector("#app")!}
-                bodyStyle={{ background: "#1c1c1c" }}
-            >
-                <Box className={"w-1/1 flex w-[4.02rem] flex-1"}>
-                    <div className={styles.cardWrap} style={{ width: "1.1rem" }}>
-                        <img
-                            src={gameInfo.current?.game_icon}
-                            alt={gameInfo.current?.game_name}
-                            className={"h-[100%] w-[100%]"}
-                        />
-                    </div>
-                    <div className={styles.cardWrapGmeInfo}>
-                        <p className={"h-[0.6rem]"}>{gameInfo.current?.game_name}</p>
-
-                        <div className={"flex w-[2.2rem] justify-around"}>
-                            {/*<Button*/}
-                            {/*    onClick={playGameHandler}*/}
-                            {/*    className={*/}
-                            {/*        "h-[0.39rem] w-[0.89rem] rounded-[0.05rem] text-[0.15rem]" +*/}
-                            {/*        " bg-[#3a3a3a]" +*/}
-                            {/*        " font-bold"*/}
-                            {/*    }*/}
-                            {/*>*/}
-                            {/*    {t("demo")}*/}
-                            {/*</Button>*/}
-                            <Button
-                                onClick={playGameHandler}
-                                style={{
-                                    "--background-color": "#009d80",
-                                    "--border-color": "#009d80",
-                                }}
-                                className={`h-[0.39rem] w-[0.89rem] rounded-[0.05rem] bg-[#] text-[0.15rem] font-bold`}
-                            >
-                                {tt("join")}
-                            </Button>
-                        </div>
-                    </div>
-                </Box>
-            </Popup>
         </div>
     );
 };

+ 1 - 5
src/app/[locale]/(TabBar)/gameList/[[...gameListFlag]]/page.tsx

@@ -51,11 +51,7 @@ const GameListFlag: FC<Props> = (props) => {
             <HeaderBack showBack={true} title={searchParams.name} />
             <main className={"main-header bg-[#1f1f1f]"}>
                 <Box>
-                    <GroupCard
-                        data={target.games}
-                        row={1}
-                        groupType={Number(searchParams.bet_type) as Category["bet_type"]}
-                    />
+                    <GroupCard data={target.games} row={1} />
                     <InfiniteScroll loadMore={loadMore} hasMore={!target.page.is_end!} />
                 </Box>
             </main>

+ 2 - 1
src/app/[locale]/providers.tsx

@@ -15,6 +15,7 @@ import { getMessaging, getToken, onMessage } from "firebase/messaging";
 import { useSearchParams } from "next/navigation";
 import Script from "next/script";
 
+import { setupFontSize } from "@/utils";
 import { motion } from "framer-motion";
 export interface ProvidersProps {
     children: ReactNode;
@@ -287,7 +288,7 @@ export const Providers = ({ children, themeProps }: ProvidersProps) => {
         // 初始化配置
         setupConfig();
         // 初始化字体
-        // setupFontSize();
+        setupFontSize();
     }, []);
 
     return (

+ 19 - 15
src/components/Card/Card.tsx

@@ -20,7 +20,7 @@ export interface CardProps {
 const Card: FC<PropsWithChildren<CardProps>> = (props) => {
     const { render, item, groupType } = props;
 
-    const { getGameUrl } = useGame();
+    const { getGameUrl, getCoinType } = useGame();
 
     const t = useTranslations("Game");
     const brandRef = useRef<GameListRep | null>(null);
@@ -42,36 +42,32 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
         element.current = document.getElementById("app");
     }, []);
     const playGameHandler = async (game: GameListRep) => {
+        const type = getCoinType(game, groupType);
+
         if (!token) {
             router.push("/login?redirect=/");
             return;
         }
         // 现金游戏
-        if (groupType === 1 && Number(wallet.score) + wallet.point <= 0) {
+        if (type === 1 && Number(wallet.score) + wallet.point <= 0) {
             router.push("/deposit");
             return;
         }
         // 免费游戏
-        if (groupType === 2 && Number(wallet.free_score) <= 0) {
+        if (type === 2 && Number(wallet.free_score) <= 0) {
             router.push("/deposit");
             return;
         }
         // 重玩游戏
-        if (groupType === 3 && Number(wallet.lose_score) <= 0) {
+        if (type === 3 && Number(wallet.lose_score) <= 0) {
             router.push("/deposit");
             return;
         }
+
         let params: any = {
             id: game.id + "",
-            mode: groupType!,
+            mode: type!,
         };
-        // demo试玩
-        if (game?.demo) {
-            params = {
-                id: game.id + "",
-                demo: game.demo,
-            };
-        }
         // 判断是否有未结算的游戏
         const { data }: any = await userInfoApi();
         const play_list = data?.play_list.map((item: any) => {
@@ -93,10 +89,10 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
             };
         });
         let gameList = [...free_game_list, ...lose_game_list];
-        if (groupType === 2) {
+        if (type === 2) {
             gameList = [...play_list, ...lose_game_list];
         }
-        if (groupType === 3) {
+        if (type === 3) {
             gameList = [...play_list, ...free_game_list];
         }
         let unfinishedGame = gameList.find((item: { id: number }) => item?.id === game.id);
@@ -115,6 +111,14 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
             mode: gameRef.current?.mode!,
         });
     };
+
+    const demoPlayGameHandler = (game) => {
+        const params = {
+            id: game.id + "",
+            demo: game.demo,
+        };
+        getGameUrl(game, params);
+    };
     return (
         <>
             {render ? (
@@ -157,7 +161,7 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
                             {(item?.category_name === "Pragmaticplay" ||
                                 item?.category_name === "PP") && (
                                 <Button
-                                    onClick={() => playGameHandler({ ...item!, demo: 1 })}
+                                    onClick={() => demoPlayGameHandler({ ...item!, demo: 1 })}
                                     className={
                                         "h-[0.39rem] w-[0.89rem] rounded-[0.05rem] text-[0.15rem]" +
                                         " bg-[#3a3a3a]" +

+ 19 - 0
src/hooks/useGame.tsx

@@ -11,6 +11,24 @@ const useGame = () => {
     const t = useTranslations();
     const { eventStartTrial } = useEventPoint();
     const pathname = usePathname();
+
+    const getCoinType = (game: GameListRep, mode: number) => {
+        const type = game.coin_types;
+        // 本金加彩金
+        if (mode) return mode;
+        if (type & 1 || type & 2) {
+            return 1;
+        }
+        // 免费币
+        if (type & 4) {
+            return 2;
+        }
+        // 重币
+        if (type & 8) {
+            return 3;
+        }
+        return;
+    };
     const getGameUrl = (game: GameListRep, params: GameRequest) => {
         Toast.show({
             icon: "loading",
@@ -51,6 +69,7 @@ const useGame = () => {
     };
     return {
         getGameUrl: getGameUrl,
+        getCoinType: getCoinType,
     };
 };