Kaynağa Gözat

feat: 增加代理推广url动态获取

ansoni 4 ay önce
ebeveyn
işleme
15b3528666

+ 46 - 0
src/api/config.ts

@@ -86,3 +86,49 @@ export const getSidebarActivitiesApi = async () => {
         method: "POST",
     });
 };
+/**
+ * 获取分享和推广的URl
+ *   POST /v1/api/front/system/configs_url
+ *   接口ID:267745030
+ *   接口地址:https://app.apifox.com/link/project/4790544/apis/api-267745030
+ */
+
+export interface LinksType {
+    /**
+     * 备注
+     */
+    comment: string;
+    /**
+     * 创建时间
+     */
+    create_at: string;
+    /**
+     * 主键 ID
+     */
+    id: string;
+    /**
+     * 租户 ID
+     */
+    renter_id: string;
+    /**
+     * 状态 1:开始 2:关闭
+     */
+    status: string;
+    /**
+     * 类型 1:分享 2:代理 :3:推广
+     */
+    type: 1 | 2 | 3;
+    /**
+     * 更新时间
+     */
+    update_at: string;
+    /**
+     * URL
+     */
+    url: string;
+}
+export const getShareLinkApi = () => {
+    return server.post<LinksType[]>({
+        url: "/v1/api/front/system/configs_url",
+    });
+};

+ 3 - 3
src/app/[locale]/(TabBar)/[[...share]]/@clientWidget/page.tsx

@@ -1,8 +1,8 @@
 "use client";
 import { getShareApi } from "@/api/config";
 import { useEventPoint } from "@/hooks/useEventPoint";
-import { usePathname } from "@/i18n/routing";
 import { Local } from "@/utils/storage";
+import { useSearchParams } from "next/navigation";
 import { useEffect } from "react";
 
 /**
@@ -12,7 +12,7 @@ const Page = () => {
     const { eventView } = useEventPoint();
 
     // 获取分享id
-    const pathname = usePathname();
+    const searchParams = useSearchParams();
     useEffect(() => {
         // pixel 埋点
         eventView();
@@ -21,7 +21,7 @@ const Page = () => {
         // 统计访问
         getShareApi({ channel_url: window.location.href });
 
-        const [, shareId] = pathname.split("/");
+        const shareId = searchParams.get("share_id");
         if (!shareId || shareId === "xxxxxx") return;
         if (shareId.length !== 8) {
             sessionStorage.removeItem("shareId");

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

@@ -1,6 +1,7 @@
 "use client";
 
 import { getWheelReceiveApi } from "@/api/cashWheel";
+import { getShareLinkApi } from "@/api/config";
 import Box from "@/components/Box";
 import { WheelClient } from "@/components/ModalPopup/WheelModal";
 import useCountDown from "@/hooks/useCountdown";
@@ -201,7 +202,6 @@ const WheelWallet = () => {
     }));
     const [count, setCount] = useState<number>(0);
     useEffect(() => {
-        console.log(`🚀🚀🚀🚀🚀-> in CashWheelClient.tsx on 252`, currentWheel);
         setCount(currentWheel.amount || 0);
     }, [currentWheel.amount]);
     return (
@@ -471,7 +471,12 @@ const ShareClient = forwardRef<{ open: () => void }, {}>(function ShareClient(pr
         window.location.href = phoneNumber;
     };
     useEffect(() => {
-        setBaseUrl(window.location.href.replace(pathname, ""));
+        getShareLinkApi().then((res) => {
+            const url =
+                res.data.find((item) => item.type === 1)?.url ??
+                window.location.href.replace(pathname, "");
+            setBaseUrl(url);
+        });
     }, []);
     return (
         <>

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

@@ -1,4 +1,5 @@
 "use client";
+import { getShareLinkApi } from "@/api/config";
 import {
     getCommissionApi,
     getRegisterCountApi,
@@ -183,7 +184,7 @@ const App: FC<Props> = (props) => {
     // 生成分享链接
     // const BASE_URL = window.location.href.replace(pathname, "");
 
-    const shareUrl = `${BASE_URL}/${userInfo ? userInfo.referrer_code : "xxxxxx"}`;
+    const shareUrl = `${BASE_URL}?share_id=${userInfo ? userInfo.referrer_code : "xxxxxx"}`;
 
     const url = encodeURIComponent(`${shareUrl}`);
 
@@ -336,7 +337,12 @@ const App: FC<Props> = (props) => {
     };
 
     useEffect(() => {
-        setBaseUrl(window.location.href.replace(pathname, ""));
+        getShareLinkApi().then((res) => {
+            const url =
+                res.data.find((item) => item.type === 2)?.url ??
+                window.location.href.replace(pathname, "");
+            setBaseUrl(url);
+        });
     }, []);
     return (
         <div className="content">

+ 1 - 4
src/app/[locale]/providers.tsx

@@ -57,9 +57,7 @@ const initFirebase = () => {
     // if (process.env.NODE_ENV === "development") {
     getToken(messaging, {
         vapidKey: process.env.NEXT_PUBLIC_FIREBASE_KEYS,
-    }).then((res) => {
-        console.log(`🚀🚀🚀🚀🚀-> `, res);
-    });
+    }).then((res) => {});
     // }
     onMessage(messaging, (payload) => {
         const notifica = new Notification(payload.data?.title || "", {
@@ -212,7 +210,6 @@ const InitAdvertise = () => {
     const kwaiClick_id = pathname.get("click_id");
     // facebook id
     const facebookPixel = pathname.get("fbPixel");
-    console.log(`🚀🚀🚀🚀🚀-> in providers.tsx on 215`);
     // console.log(
     //     `🚀🚀🚀🚀🚀-> in providers.tsx on 152`,
     //     typeof window,