Browse Source

feat:更新动态路由

Before 6 months ago
parent
commit
6f8482a3ce

+ 1 - 2
next.config.mjs

@@ -20,12 +20,11 @@ const nextConfig = {
         },
     },
     experimental: {
-        instrumentationHook: true,
         staleTimes: {
             dynamic: 0,
             static: 180,
         },
-        scrollRestoration: true,
+        scrollRestoration: false,
     },
     images: {
         domains: [

File diff suppressed because it is too large
+ 2450 - 129
pnpm-lock.yaml


+ 44 - 0
src/api/setup.ts

@@ -0,0 +1,44 @@
+/**
+ * @description 初始化配置
+ */
+export interface DefaultConfigTypes {
+    NEXT_PUBLIC_BASE_URL: string;
+    NEXT_PUBLIC_SHARE_URL: string;
+}
+const getDefaultConfig = async (): Promise<DefaultConfigTypes> => {
+    return fetch("https://static.tiktokjakjkl.icu/test/index.json", {
+        mode: "cors",
+        headers: {
+            "content-type": "application/json",
+        },
+        cache: "no-cache",
+    }).then((res) => res.json());
+};
+
+const developConfig = {
+    NEXT_PUBLIC_BASE_URL: process.env.NEXT_PUBLIC_BASE_URL as string,
+    NEXT_PUBLIC_SHARE_URL: process.env.NEXT_PUBLIC_SHARE_URL as string,
+};
+
+export const setupConfig = async (): Promise<DefaultConfigTypes> => {
+    if (typeof window !== "undefined") {
+        // 客户端
+        if (globalThis.config) return globalThis.config;
+
+        return getDefaultConfig().then((config) => {
+            // const data = process.env.NODE_ENV === "development" ? developConfig : config;
+            const data = developConfig;
+            globalThis.config = data;
+            return data;
+        });
+    } else {
+        // 服务端
+        // if (globalThis.config) return globalThis.config;
+        return getDefaultConfig().then((config) => {
+            // const data = process.env.NODE_ENV === "development" ? developConfig : config;
+            const data = developConfig;
+            globalThis.config = data;
+            return data;
+        });
+    }
+};

+ 0 - 1
src/app/[locale]/(TabBar)/[[...share]]/@prizeWidget/page.tsx

@@ -10,7 +10,6 @@ const getPrizeApi = () => {
 };
 const Page = async () => {
     const result = await getPrizeApi();
-    console.log(`🚀🚀🚀🚀🚀-> in page.tsx on 12`, result.data);
     return <HomePrize data={result.data}></HomePrize>;
 };
 export default Page;

+ 1 - 1
src/app/[locale]/(wheel)/cashWheel/CashWheelClient.tsx

@@ -421,7 +421,7 @@ const ShareClient = forwardRef<{ open: () => void }, {}>(function ShareClient(pr
 
     const [currentPhoneIndex, setCurrentPhoneIndex] = useState(0);
 
-    const shareUrl = `${process.env.NEXT_PUBLIC_SHARE_URL}/br/sharecwbr?turntable=${currentWheel.id}&user=${user.id}&time=${currentWheel.end_time}`;
+    const shareUrl = `${globalThis.config.NEXT_PUBLIC_SHARE_URL}/br/sharecwbr?turntable=${currentWheel.id}&user=${user.id}&time=${currentWheel.end_time}`;
     const url = encodeURIComponent(`${shareUrl}`);
     const text = encodeURIComponent(`Receba 100 BRL de graça,Pix SAQUE RÁPIDO`);
     const t = useTranslations();

+ 7 - 7
src/app/[locale]/affiliate/summary/page.tsx

@@ -5,16 +5,16 @@ import {
     getTotalCountApi,
     getWithdrawalApi,
 } from "@/api/summary";
-import { useUserInfoStore } from "@/stores/useUserInfoStore";
-import { useRequest } from "ahooks";
-import { Mask, Toast } from "antd-mobile";
-import { useLocale, useTranslations } from "next-intl";
 import { CommissionModel } from "@/app/[locale]/affiliate/component/TabsCom";
 import Table, { TableHeaderItem } from "@/components/Table";
 import TipsModal, { ModalProps } from "@/components/TipsModal";
+import { useUserInfoStore } from "@/stores/useUserInfoStore";
 import { server } from "@/utils/client";
 import { getToken } from "@/utils/Cookies";
 import { copyText } from "@/utils/methods";
+import { useRequest } from "ahooks";
+import { Mask, Toast } from "antd-mobile";
+import { useLocale, useTranslations } from "next-intl";
 import Image from "next/image";
 import { FC, useEffect, useRef, useState } from "react";
 import "./page.scss";
@@ -39,7 +39,7 @@ const RulesClient = () => {
             dataIndex: "bet",
             align: "center",
             render: (item: any) => (
-                <div className={"text-[0.12rem] text-[#98a7b5]"}>{item?.bet/ 10000} Dez mil+</div>
+                <div className={"text-[0.12rem] text-[#98a7b5]"}>{item?.bet / 10000} Dez mil+</div>
             ),
         },
         {
@@ -65,7 +65,7 @@ const RulesClient = () => {
             })
             .then((res) => {
                 return {
-                    rules: res.data || []
+                    rules: res.data || [],
                 };
             })
             .catch((error) => {
@@ -178,7 +178,7 @@ const App: FC<Props> = (props) => {
     const token = getToken();
 
     // 生成分享链接
-    const BASE_URL = process.env.NEXT_PUBLIC_SHARE_URL;
+    const BASE_URL = globalThis.config.NEXT_PUBLIC_SHARE_URL;
     const shareUrl = `${BASE_URL}/${locale}/${userInfo ? userInfo.referrer_code : "xxxxxx"}`;
 
     const url = encodeURIComponent(`${shareUrl}`);

+ 3 - 3
src/hooks/useGame.tsx

@@ -1,5 +1,5 @@
 import { GameListRep, GameRequest, getGameDetailApi } from "@/api/home";
-import { useRouter, defaultLocale } from "@/i18n/routing";
+import { defaultLocale, useRouter } from "@/i18n/routing";
 import { brandList } from "@/utils/constant";
 import { getCookies } from "@/utils/Cookies";
 import { Toast } from "antd-mobile";
@@ -17,11 +17,11 @@ const useGame = () => {
         });
         const brand = brandList.find((item) => item.gid === game.game_id)?.brand ?? "";
         const lang = getCookies("language") || defaultLocale;
-        getGameDetailApi({...params, language: lang === 'br' ? 'pt' : lang})
+        getGameDetailApi({ ...params, language: lang === "br" ? "pt" : lang })
             .then((res) => {
                 Toast.clear();
                 if (res.data && res.data.game_url) {
-                    const url = `${encodeURI(res.data.game_url)}&brand=${brand}&return_url=${process.env.NEXT_PUBLIC_SHARE_URL}&category_name=${game.category_name}`;
+                    const url = `${encodeURI(res.data.game_url)}&brand=${brand}&return_url=${globalThis.config.NEXT_PUBLIC_SHARE_URL}&category_name=${game.category_name}`;
                     const protocol = new URL(url).protocol;
                     if (
                         whiteUrls.indexOf(window.location.hostname) !== -1 ||

+ 0 - 30
src/instrumentation.ts

@@ -1,30 +0,0 @@
-const initConfig = () => {
-    fetch("https://static.tiktokjakjkl.icu/test/index.json", {
-        mode: "cors",
-        headers: {
-            "content-type": "application/json",
-        },
-    })
-        .then((res) => res.json())
-        .then((data) => {
-            console.log(`🚀🚀🚀🚀🚀-> in instrumentation.ts on 10`, data);
-            globalThis.config = {
-                NEXT_PUBLIC_BASE_URL: "http://192.168.0.84:8800",
-                NEXT_PUBLIC_SHARE_URL: "http://192.168.0.84:3000",
-            };
-        });
-};
-export async function register() {
-    initConfig();
-    setInterval(() => {
-        initConfig();
-    }, 100000);
-    if (process.env.NEXT_RUNTIME === "nodejs") {
-    }
-
-    if (process.env.NEXT_RUNTIME === "edge") {
-        console.log(`🚀🚀🚀🚀🚀-> in instrumentation.ts on 26`, 123);
-        process.env.NEXT_PUBLIC_CONFIG_URL = "http://192.168.0.84:8800";
-        // sessionStorage.setItem("http://192.168.0.84:8800", "NEXT_PUBLIC_CONFIG_URL");
-    }
-}

+ 8 - 0
src/types/global.d.ts

@@ -0,0 +1,8 @@
+import { DefaultConfigTypes } from "@/api/setup";
+
+declare global {
+    namespace globalThis {
+        var config: DefaultConfigTypes;
+    }
+}
+export {};

+ 14 - 0
src/utils/client/axios.ts

@@ -3,6 +3,7 @@ import { Toast } from "antd-mobile";
 import axios, { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from "axios";
 import type { AxiosOptions } from "./type";
 
+import { setupConfig } from "@/api/setup";
 import { defaultLocale } from "@/i18n/routing";
 import { getCookies, getToken } from "@/utils/Cookies";
 
@@ -10,6 +11,17 @@ interface CustomRequestConfig {
     toast?: boolean;
 }
 
+const getInitBaseUrl = () => {
+    const str = sessionStorage.getItem("config");
+    if (str) return JSON.parse(str);
+    return fetch("https://static.tiktokjakjkl.icu/test/index.json")
+        .then((res) => res.json())
+        .then((config) => {
+            sessionStorage.setItem("config", JSON.stringify(config));
+            return config;
+        });
+};
+
 export default class Request {
     private axiosInstance: AxiosInstance;
     private readonly options: AxiosOptions;
@@ -41,6 +53,8 @@ export default class Request {
          */
         axiosInstance.interceptors.request.use(
             async (config: InternalAxiosRequestConfig & CustomRequestConfig) => {
+                const result = await setupConfig();
+                config.baseURL = result.NEXT_PUBLIC_BASE_URL;
                 if (requestInterceptor) {
                     config = requestInterceptor(config);
                     // header请求头添加token

+ 0 - 3
src/utils/client/index.ts

@@ -3,11 +3,8 @@ import { useWalletStore } from "@/stores/useWalletStore";
 import actions from "@/utils/client/actions";
 import Request from "./axios";
 
-const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL;
-console.log(`🚀🚀🚀🚀🚀-> in index.ts on 7`, process.env);
 const server = new Request({
     timeout: 10 * 1000,
-    baseURL: BASE_URL,
     transform: {
         // instance  interceptor
         requestInterceptor: (config) => {

+ 6 - 10
src/utils/server/index.ts

@@ -1,3 +1,4 @@
+import { setupConfig } from "@/api/setup";
 import { defaultLocale, redirect } from "@/i18n/routing";
 import { Response } from "@/types";
 import { cookies } from "next/headers";
@@ -43,20 +44,15 @@ const responseInterceptor = <T = any, R = unknown>(
 };
 class Server {
     private static instance: Server;
-    private BASE_URL: string;
-    constructor() {
-        console.log(`🚀🚀🚀🚀🚀-> in index.ts on 48`, globalThis.config);
-        if (globalThis.config) {
-            this.BASE_URL = globalThis.config.NEXT_PUBLIC_BASE_URL as string;
-        }
-    }
+    constructor() {}
 
     async request<T, R = unknown>(options: ServerOptions): Promise<Response<T> & R> {
+        const config = await setupConfig();
         options = requestInterceptor(options);
         const { method = "GET", url, headers = {}, data = {}, body, ...other } = options;
         const params = JSON.stringify(data);
         try {
-            const response = await fetch(`${this.BASE_URL}${url}`, {
+            const response = await fetch(`${config.NEXT_PUBLIC_BASE_URL}${url}`, {
                 method: method,
                 headers: {
                     Token: cookies().get("Token")?.value || "",
@@ -72,12 +68,12 @@ class Server {
                     console.log(`🚀🚀🚀🚀🚀-> in index.ts on 68`, error);
                     return {};
                 });
-            return responseInterceptor<T, R>(response, options, this.BASE_URL);
+            return responseInterceptor<T, R>(response, options, config.NEXT_PUBLIC_BASE_URL);
         } catch (error) {
             console.log(
                 `🚀🚀🚀🚀🚀-> in index.ts on 67`,
                 error,
-                `${this.BASE_URL}${options.url}`,
+                `${config.NEXT_PUBLIC_BASE_URL}${options.url}`,
                 JSON.stringify(options)
             );
             return Promise.reject(error);

Some files were not shown because too many files changed in this diff