Jelajahi Sumber

feat: 登陆界面广告

year 2 bulan lalu
induk
melakukan
5fa6d146ca

+ 24 - 0
src/api/customservice.ts

@@ -53,3 +53,27 @@ export const getSocialsApi = async () => {
             return [];
         });
 };
+
+export interface AdItem {
+    id: number;
+    sort: number;
+    show_platform: number;
+    action_type: number;
+    action_params: string;
+    content: string;
+    is_badge: boolean;
+}
+
+export const getLoginAdApi = async () => {
+    return server
+        .request<AdItem[]>({
+            url: "/v1/api/front/activity_promotion_guests",
+            method: "POST",
+        })
+        .then((res) => {
+            return res.data;
+        })
+        .catch((err) => {
+            return [];
+        });
+};

+ 53 - 0
src/app/[locale]/(enter)/login/adbox.tsx

@@ -0,0 +1,53 @@
+"use client";
+import { AdItem } from "@/api/customservice";
+import { useRouter } from "@/i18n/routing";
+import React from "react";
+import { Pagination } from "swiper/modules";
+import { Swiper, SwiperSlide } from "swiper/react";
+
+interface AdboxProps {
+    data: AdItem[];
+}
+
+const Adbox: React.FC<AdboxProps> = ({ data }) => {
+    const router = useRouter();
+    const doClick = async (data: AdItem) => {
+        switch (data.action_type) {
+            case 2:
+                window.open(data.action_params, "_blank");
+                break;
+            case 3:
+                let path = data.action_params;
+                if (path) router.push(path);
+                break;
+
+            case 5:
+                data?.action_params ? await eval(data?.action_params || "") : "";
+                break;
+            default:
+                break;
+        }
+    };
+
+    return (
+        <div className="p-[.1rem]">
+            <Swiper
+                spaceBetween={10}
+                autoplay
+                modules={[Pagination]}
+                pagination={{ clickable: true }}
+            >
+                {!!data?.length &&
+                    data.map((item) => {
+                        return (
+                            <SwiperSlide key={item.id} onClick={() => doClick(item)}>
+                                <img src={item.content} alt="" />
+                            </SwiperSlide>
+                        );
+                    })}
+            </Swiper>
+        </div>
+    );
+};
+
+export default Adbox;

+ 5 - 2
src/app/[locale]/(enter)/login/page.tsx

@@ -1,16 +1,18 @@
 "use server";
-import { getServicesApi } from "@/api/customservice";
+import { getLoginAdApi, getServicesApi } from "@/api/customservice";
 import { Link } from "@/i18n/routing";
 import { getTranslations } from "next-intl/server";
 import Form from "../components/Form";
 import GoogleCom from "../components/GoogleCom";
+import Adbox from "./adbox";
 import "./index.scss";
 
 const Login = async () => {
     const t = await getTranslations("LoginPage");
     const services = await getServicesApi();
+    const adInfo = await getLoginAdApi();
     const defaultService = services?.filter((item) => item.register_show === 1);
-
+    console.log(1122, adInfo);
     return (
         <>
             <GoogleCom />
@@ -20,6 +22,7 @@ const Login = async () => {
                 <span className={"iconfont icon-a-18 text-[red]"}></span>
             </div>
 
+            <Adbox data={adInfo}></Adbox>
             <div
                 className={`absolute bottom-[0.84rem] right-[0.12rem] z-50 flex w-[0.6944rem] flex-col items-center justify-center`}
             >