Просмотр исходного кода

一种游戏同时只能使用1种钱包

XianCH 6 месяцев назад
Родитель
Сommit
3b47012cbb
1 измененных файлов с 69 добавлено и 3 удалено
  1. 69 3
      src/components/Card/Card.tsx

+ 69 - 3
src/components/Card/Card.tsx

@@ -1,5 +1,5 @@
 "use client";
-import { Category, GameListRep } from "@/api/home";
+import { Category, GameListRep, GameRequest } from "@/api/home";
 import Box from "@/components/Box";
 import useGame from "@/hooks/useGame";
 import { useRouter } from "@/i18n/routing";
@@ -9,6 +9,8 @@ import { Button, Popup } from "antd-mobile";
 import { useTranslations } from "next-intl";
 import { FC, PropsWithChildren, ReactNode, useRef, useState } from "react";
 import styles from "./style.module.scss";
+import { userInfoApi } from "@/api/login";
+import TipsModal, { ModalProps } from "../TipsModal";
 export interface CardProps {
     item?: GameListRep;
     render?: (value: GameListRep) => ReactNode;
@@ -23,6 +25,9 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
     const t = useTranslations("Game");
     const brandRef = useRef<GameListRep | null>(null);
     const wallet = useWalletStore((state) => state.wallet);
+    // 判断是否有未结算的对局
+    const gameModelRef = useRef<ModalProps>(null)
+    const game = useRef<GameListRep & { mode: GameRequest["mode"] } | null>(null);
 
     const [visible, setVisible] = useState(false);
 
@@ -32,7 +37,7 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
         setVisible(true);
         brandRef.current = game;
     };
-    const playGameHandler = (game: GameListRep) => {
+    const playGameHandler = async (game: GameListRep) => {
         if (!token) {
             router.push("/login?redirect=/");
             return;
@@ -52,8 +57,49 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
                 demo: game.demo,
             };
         }
+        // 判断是否有未结算的游戏
+        const { data }: any = await userInfoApi();
+        const play_list = data?.play_list.map((item: any) => {
+            return {
+                ...item,
+                mode: 1
+            }
+        })
+        const free_game_list = data?.free_game_list.map((item: any) => {
+            return {
+                ...item,
+                mode: 2
+            }
+        })
+        const lose_game_list = data?.lose_game_list.map((item: any) => {
+            return {
+                ...item,
+                mode: 3
+            }
+        })
+        let gameList = [...free_game_list, ...lose_game_list]
+        if (groupType === 2) {
+            gameList = [...play_list, ...lose_game_list]
+        }
+        if (groupType === 3) {
+            gameList = [...play_list, ...free_game_list]
+        }
+        let unfinishedGame = gameList.find((item: { id: number }) => item?.id === game.id)
+        if (unfinishedGame) {
+            game = unfinishedGame
+            setVisible(false);
+            gameModelRef.current?.onOpen()
+            return
+        }
         getGameUrl(brandRef.current!, params);
     };
+
+    const goGame = () => {
+        getGameUrl(game.current!, {
+            id: game.current?.id + "",
+            mode: game.current?.mode!
+        });
+    }
     return (
         <>
             {render ? (
@@ -84,7 +130,7 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
                     <div className={styles.cardWrap} style={{ width: "1.1rem" }}>
                         <img
                             src={item?.game_icon}
-                            alt={item?.game_name_cn +'-'+ item?.category_name}
+                            alt={item?.game_name_cn + '-' + item?.category_name}
                             className={"h-[100%] w-[100%]"}
                         />
                     </div>
@@ -119,6 +165,26 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
                     </div>
                 </Box>
             </Popup>
+
+            <TipsModal title={"Tips"} ref={gameModelRef}>
+                <p className={"text-left text-[0.12rem] font-medium text-[#666]"}>
+                    Há jogos inconclusos continuar o jogo
+                </p>
+
+                <div className={"mt-[0.0694rem] flex justify-center"}>
+                    <Button
+                        color={"primary"}
+                        className={"mx-auto"}
+                        style={{
+                            "--background-color": "var(--primary-color)",
+                            "--border-color": "var(--primary-color)",
+                        }}
+                        onClick={goGame}
+                    >
+                        para jogos
+                    </Button>
+                </div>
+            </TipsModal>
         </>
     );
 };