Card.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. "use client";
  2. import { Category, GameListRep, getGameDetailApi } from "@/api/home";
  3. import Box from "@/components/Box";
  4. import { useRouter } from "@/i18n/routing";
  5. import { useWalletStore } from "@/stores/useWalletStore";
  6. import { brandList } from "@/utils/constant";
  7. import { getToken } from "@/utils/Cookies";
  8. import { Button, Popup, Toast } from "antd-mobile";
  9. import { useTranslations } from "next-intl";
  10. import { FC, PropsWithChildren, ReactNode, useRef, useState } from "react";
  11. import styles from "./style.module.scss";
  12. export interface CardProps {
  13. item?: GameListRep;
  14. render?: (value: GameListRep) => ReactNode;
  15. groupType: Category["bet_type"];
  16. }
  17. const Card: FC<PropsWithChildren<CardProps>> = (props) => {
  18. const { render, item, groupType } = props;
  19. const t = useTranslations("Game");
  20. const brandRef = useRef<string>("");
  21. const score = useWalletStore((state) => state.score);
  22. const [visible, setVisible] = useState(false);
  23. const router = useRouter();
  24. const token = getToken();
  25. const handler = (game: GameListRep) => {
  26. setVisible(true);
  27. brandRef.current = brandList.find((item) => item.gid === game.game_id)?.brand ?? "";
  28. if (!token) return;
  29. };
  30. const playGameHandler = (game: GameListRep) => {
  31. if (!token) {
  32. router.push("/login?redirect=/");
  33. return;
  34. }
  35. if (Number(score) <= 0) {
  36. router.push("/deposit");
  37. return;
  38. }
  39. Toast.show({
  40. icon: "loading",
  41. duration: 0,
  42. maskStyle: { zIndex: 99999, background: "rgba(0,0,0,0.5)" },
  43. });
  44. const params = {
  45. id: game.id + "",
  46. mode: groupType,
  47. };
  48. getGameDetailApi(params).then((res) => {
  49. if (res.data && res.data.game_url) {
  50. window.open(`${res.data?.game_url}&brand=${brandRef.current}`);
  51. } else {
  52. Toast.show("数据错误");
  53. }
  54. });
  55. };
  56. return (
  57. <>
  58. {render ? (
  59. render(item!)
  60. ) : (
  61. <div className={styles.cardWrap} onClick={() => handler(item!)}>
  62. <img
  63. src={item?.game_icon}
  64. alt={item?.game_name_cn}
  65. className={"h-[100%] w-[100%]"}
  66. />
  67. </div>
  68. )}
  69. <Popup
  70. visible={visible}
  71. onMaskClick={() => {
  72. setVisible(false);
  73. }}
  74. onClose={() => {
  75. setVisible(false);
  76. }}
  77. showCloseButton={true}
  78. getContainer={() => document.querySelector("#app")!}
  79. bodyStyle={{ background: "#1c1c1c" }}
  80. >
  81. <Box className={"w-1/1 flex w-[4.02rem] flex-1"}>
  82. <div className={styles.cardWrap} style={{ width: "1.1rem" }}>
  83. <img
  84. src={item?.game_icon}
  85. alt={item?.game_name_cn}
  86. className={"h-[100%] w-[100%]"}
  87. />
  88. </div>
  89. <div className={styles.cardWrapGmeInfo}>
  90. <p className={"h-[0.6rem]"}>{item?.game_name_cn}</p>
  91. <div className={"flex w-[2.2rem] justify-around"}>
  92. {/*<Button*/}
  93. {/* onClick={playGameHandler}*/}
  94. {/* className={*/}
  95. {/* "h-[0.39rem] w-[0.89rem] rounded-[0.05rem] text-[0.15rem]" +*/}
  96. {/* " bg-[#3a3a3a]" +*/}
  97. {/* " font-bold"*/}
  98. {/* }*/}
  99. {/*>*/}
  100. {/* {t("demo")}*/}
  101. {/*</Button>*/}
  102. <Button
  103. onClick={() => playGameHandler(item!)}
  104. style={{
  105. "--background-color": "#009d80",
  106. "--border-color": "#009d80",
  107. }}
  108. className={`h-[0.39rem] w-[0.89rem] rounded-[0.05rem] bg-[#] text-[0.15rem] font-bold`}
  109. >
  110. {t("join")}
  111. </Button>
  112. </div>
  113. </div>
  114. </Box>
  115. </Popup>
  116. </>
  117. );
  118. };
  119. export default Card;