Card.tsx 5.1 KB

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