|
@@ -1,12 +1,15 @@
|
|
|
"use client";
|
|
|
import { BannerRep, PrizeTypes } from "@/api/home";
|
|
|
import { Card } from "@/components/Card";
|
|
|
+import NoticeBox from "@/components/NoticeBox";
|
|
|
import { Tabs } from "antd-mobile";
|
|
|
import clsx from "clsx";
|
|
|
import React, { FC } from "react";
|
|
|
-import { Autoplay, FreeMode } from "swiper/modules";
|
|
|
+import "swiper/css";
|
|
|
+import { Autoplay } from "swiper/modules";
|
|
|
import { Swiper, SwiperSlide } from "swiper/react";
|
|
|
import styles from "./prize.module.scss";
|
|
|
+
|
|
|
interface Props {
|
|
|
data: PrizeTypes[];
|
|
|
notices?: BannerRep[];
|
|
@@ -15,22 +18,29 @@ interface Props {
|
|
|
|
|
|
const HomePrize: FC<Props> = (props) => {
|
|
|
const { data, type, notices } = props;
|
|
|
+ const noticeSwiperRef = React.useRef<any>(null);
|
|
|
+ const [act, setAct] = React.useState<number>(0);
|
|
|
|
|
|
const renderData = React.useMemo(() => {
|
|
|
if (type !== "notice") return data;
|
|
|
const result: any = [];
|
|
|
if (!!data?.length) {
|
|
|
+ let bigWin: string[] = [];
|
|
|
data.forEach((item) => {
|
|
|
- result.push({
|
|
|
- text: ` ${item.phone ? item.phone.slice(0, 1) + "*****" + item.phone.slice(-3) : ""}
|
|
|
- acabou de retirar {prize.amount} R$`,
|
|
|
- });
|
|
|
+ bigWin.push(
|
|
|
+ `${item.phone ? item.phone.slice(0, 1) + "*****" + item.phone.slice(-3) : ""} acabou de retirar {prize.amount} R$`
|
|
|
+ );
|
|
|
+ });
|
|
|
+ result.push({
|
|
|
+ dataType: "bigWin",
|
|
|
+ data: bigWin,
|
|
|
});
|
|
|
}
|
|
|
if (!!notices?.length) {
|
|
|
notices?.forEach((item) => {
|
|
|
result.push({
|
|
|
- text: item.content,
|
|
|
+ dataType: "notice",
|
|
|
+ data: item.content,
|
|
|
});
|
|
|
});
|
|
|
}
|
|
@@ -38,6 +48,14 @@ const HomePrize: FC<Props> = (props) => {
|
|
|
return result;
|
|
|
}, [data, notices, type]);
|
|
|
|
|
|
+ const noticeEnd = (idx: number) => {
|
|
|
+ if (noticeSwiperRef.current) {
|
|
|
+ const toIndex = idx + 1 >= renderData.length ? 0 : idx + 1;
|
|
|
+ setAct(toIndex);
|
|
|
+ noticeSwiperRef.current?.slideToLoop(toIndex);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
if (!renderData?.length) return null;
|
|
|
|
|
|
if (type === "notice") {
|
|
@@ -52,26 +70,23 @@ const HomePrize: FC<Props> = (props) => {
|
|
|
"iconfont icon-yangshengqi mr-[0.06rem] text-[.14rem] text-[var(--textColor6)]"
|
|
|
}
|
|
|
></div>
|
|
|
+ {/* <NoticeBox content={renderData[0].data}></NoticeBox> */}
|
|
|
<Swiper
|
|
|
- spaceBetween={30}
|
|
|
+ direction="vertical"
|
|
|
loop
|
|
|
- autoplay={{
|
|
|
- delay: 0,
|
|
|
- }}
|
|
|
- speed={5000}
|
|
|
- freeMode
|
|
|
- slidesPerView={"auto"}
|
|
|
- modules={[Autoplay, FreeMode]}
|
|
|
+ slidesPerView={1}
|
|
|
className="homeNoticeSwiper"
|
|
|
+ onSwiper={(swiper) => {
|
|
|
+ noticeSwiperRef.current = swiper;
|
|
|
+ }}
|
|
|
>
|
|
|
{renderData.map((item: any, index: number) => (
|
|
|
<SwiperSlide key={index}>
|
|
|
- <div
|
|
|
- className={
|
|
|
- "textBox inline-block !text-[.12rem] text-[var(--textColor1)]"
|
|
|
- }
|
|
|
- dangerouslySetInnerHTML={{ __html: item.text }}
|
|
|
- ></div>
|
|
|
+ <NoticeBox
|
|
|
+ content={item.data}
|
|
|
+ start={index === act}
|
|
|
+ onEnd={() => noticeEnd(index)}
|
|
|
+ ></NoticeBox>
|
|
|
</SwiperSlide>
|
|
|
))}
|
|
|
</Swiper>
|