Card.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 whiteUrls = ["192.168.0.84", "localhost", "192.168.0.46"];
  18. const Card: FC<PropsWithChildren<CardProps>> = (props) => {
  19. const { render, item, groupType } = props;
  20. const t = useTranslations("Game");
  21. const tcode = useTranslations();
  22. const brandRef = useRef<string>("");
  23. const wallet = useWalletStore((state) => state.wallet);
  24. const [visible, setVisible] = useState(false);
  25. const router = useRouter();
  26. const token = getToken();
  27. const handler = (game: GameListRep) => {
  28. setVisible(true);
  29. brandRef.current = brandList.find((item) => item.gid === game.game_id)?.brand ?? "";
  30. };
  31. const playGameHandler = (game: GameListRep) => {
  32. if (!token) {
  33. router.push("/login?redirect=/");
  34. return;
  35. }
  36. if (groupType === 1 && Number(wallet.score) <= 0) {
  37. router.push("/deposit");
  38. return;
  39. }
  40. Toast.show({
  41. icon: "loading",
  42. duration: 0,
  43. maskStyle: { zIndex: 99999, background: "rgba(0,0,0,0.5)" },
  44. });
  45. const params = {
  46. id: game.id + "",
  47. mode: groupType!,
  48. };
  49. getGameDetailApi(params)
  50. .then((res) => {
  51. Toast.clear();
  52. if (res.data && res.data.game_url) {
  53. const url = `${res.data?.game_url}&brand=${brandRef.current}&return_url=${process.env.NEXT_PUBLIC_SHARE_URL}`;
  54. const protocol = new URL(url).protocol;
  55. if (
  56. whiteUrls.indexOf(window.location.hostname) !== -1 ||
  57. protocol === "https:"
  58. ) {
  59. router.push(`/game?${url}`);
  60. } else {
  61. window.open(url);
  62. }
  63. } else {
  64. Toast.show(tcode("code.500"));
  65. }
  66. })
  67. .catch((error) => {
  68. Toast.clear();
  69. });
  70. };
  71. return (
  72. <>
  73. {render ? (
  74. render(item!)
  75. ) : (
  76. <div className={styles.cardWrap} onClick={() => handler(item!)}>
  77. <img
  78. src={item?.game_icon}
  79. alt={item?.game_name_cn}
  80. className={"h-[100%] w-[100%]"}
  81. />
  82. </div>
  83. )}
  84. <Popup
  85. visible={visible}
  86. onMaskClick={() => {
  87. setVisible(false);
  88. }}
  89. onClose={() => {
  90. setVisible(false);
  91. }}
  92. showCloseButton={true}
  93. getContainer={() => document.querySelector("#app")!}
  94. bodyStyle={{ background: "#1c1c1c" }}
  95. >
  96. <Box className={"w-1/1 flex w-[4.02rem] flex-1"}>
  97. <div className={styles.cardWrap} style={{ width: "1.1rem" }}>
  98. <img
  99. src={item?.game_icon}
  100. alt={item?.game_name_cn}
  101. className={"h-[100%] w-[100%]"}
  102. />
  103. </div>
  104. <div className={styles.cardWrapGmeInfo}>
  105. <p className={"h-[0.6rem]"}>{item?.game_name_cn}</p>
  106. <div className={"flex w-[2.2rem] justify-around"}>
  107. {/*<Button*/}
  108. {/* onClick={playGameHandler}*/}
  109. {/* className={*/}
  110. {/* "h-[0.39rem] w-[0.89rem] rounded-[0.05rem] text-[0.15rem]" +*/}
  111. {/* " bg-[#3a3a3a]" +*/}
  112. {/* " font-bold"*/}
  113. {/* }*/}
  114. {/*>*/}
  115. {/* {t("demo")}*/}
  116. {/*</Button>*/}
  117. <Button
  118. onClick={() => playGameHandler(item!)}
  119. style={{
  120. "--background-color": "#009d80",
  121. "--border-color": "#009d80",
  122. }}
  123. className={`h-[0.39rem] w-[0.89rem] rounded-[0.05rem] bg-[#] text-[0.15rem] font-bold`}
  124. >
  125. {t("join")}
  126. </Button>
  127. </div>
  128. </div>
  129. </Box>
  130. </Popup>
  131. </>
  132. );
  133. };
  134. export default Card;