|
@@ -0,0 +1,53 @@
|
|
|
+"use client";
|
|
|
+import { AdItem } from "@/api/customservice";
|
|
|
+import { useRouter } from "@/i18n/routing";
|
|
|
+import React from "react";
|
|
|
+import { Autoplay, 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, Autoplay]}
|
|
|
+ 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;
|