123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import { GameListRep, GameRequest, getGameDetailApi } from "@/api/home";
- import { useEventPoint } from "@/hooks/useEventPoint";
- import { defaultLocale, usePathname, useRouter } from "@/i18n/routing";
- import { getCookies } from "@/utils/Cookies";
- import { Toast } from "antd-mobile";
- import { useTranslations } from "next-intl";
- // 地址白名单
- const whiteUrls = ["192.168.0.84", "localhost", "192.168.0.46"];
- const useGame = () => {
- const router = useRouter();
- 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",
- duration: 0,
- maskStyle: { zIndex: 99999, background: "rgba(0,0,0,0.5)" },
- });
- // const brand = brandList.find((item) => item.gid === game.game_id)?.brand ?? "";
- const lang = getCookies("language") || defaultLocale;
- getGameDetailApi({ ...params, language: lang === "br" ? "pt" : lang })
- .then((res) => {
- console.log('category_name',game)
- Toast.clear();
- if (res.data && res.data.game_url) {
- eventStartTrial();
- const game_url = res.data.game_url;
- // 获取游戏的品牌
- const categoryName:any = game?.category_name;
- console.log('category_name222',game,categoryName.toLowerCase())
- // 然后是文档对象
- if (game_url.indexOf("!doctype") !== -1) {
- sessionStorage.setItem("game_url", res.data.game_url);
- const url = `${encodeURI(window.location.href)}&return_url=${encodeURI(window.location.href.replace(pathname, ""))}&category_name=${game.provider}`;
- router.push(`/game?${url}`);
- return;
- }
- const url = `${encodeURI(res.data.game_url)}&return_url=${encodeURI(window.location.href.replace(pathname, ""))}&category_name=${game.provider}`;
- // 如果是pp游戏,则当前窗口打开新的地址,不需要加return_url
- if(categoryName.toLowerCase() === 'pp'){
- const ppUrl = `${encodeURI(res.data.game_url)}&category_name=${game.provider}`;
- console.log('ppUrl',ppUrl)
- return
- window.open(ppUrl,'_self');
- return
- }
- if (new RegExp("https").test(game_url)) {
- // 如果是https
- router.push(`/game?${url}`);
- return;
- } else {
- window.open(url);
- }
- } else {
- Toast.show(t("code.500"));
- }
- })
- .catch((error) => {
- Toast.clear();
- });
- };
- return {
- getGameUrl: getGameUrl,
- getCoinType: getCoinType,
- };
- };
- export default useGame;
|