|
@@ -11,6 +11,7 @@ import SlotsModal, { SlotModalRefProps } from "@/components/ModalPopup/SlotsModa
|
|
|
import WheelModal, { WheelModalProps } from "@/components/ModalPopup/WheelModal";
|
|
|
import { useEventPoint } from "@/hooks/useEventPoint";
|
|
|
import { Link } from "@/i18n/routing";
|
|
|
+import { useModalShow } from "@/stores/modalShow";
|
|
|
import { useFirstPayStore } from "@/stores/useFirstPayStore";
|
|
|
import { useGlobalNoticeStore } from "@/stores/useGlobalNoticeStore";
|
|
|
import { useSignStore } from "@/stores/useSignStore";
|
|
@@ -21,15 +22,19 @@ import { Badge } from "antd-mobile";
|
|
|
import dayjs from "dayjs";
|
|
|
import { useTranslations } from "next-intl";
|
|
|
import Image from "next/image";
|
|
|
-import { FC, useEffect, useRef, useState } from "react";
|
|
|
+import { FC, useEffect, useMemo, useRef, useState } from "react";
|
|
|
|
|
|
interface Props {
|
|
|
services: ServiceTypes[];
|
|
|
}
|
|
|
+
|
|
|
+interface SlotSectionProps {
|
|
|
+ onDestory?: () => void;
|
|
|
+}
|
|
|
/**
|
|
|
* 免费送活动
|
|
|
*/
|
|
|
-const SlotSection = () => {
|
|
|
+const SlotSection: FC<SlotSectionProps> = ({ onDestory }) => {
|
|
|
const slotsRef = useRef<SlotModalRefProps | null>(null);
|
|
|
const getSlots = async () => {
|
|
|
const token = getToken();
|
|
@@ -37,6 +42,7 @@ const SlotSection = () => {
|
|
|
const result = await getGiveInfoApi();
|
|
|
return result.data;
|
|
|
} else {
|
|
|
+ destory();
|
|
|
return Promise.resolve({});
|
|
|
}
|
|
|
};
|
|
@@ -49,6 +55,10 @@ const SlotSection = () => {
|
|
|
const slotHandler = () => {
|
|
|
slotsRef.current?.onOpen(slots);
|
|
|
};
|
|
|
+ const destory = () => {
|
|
|
+ if (onDestory && typeof onDestory === "function") onDestory();
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
{slots?.id ? (
|
|
@@ -60,7 +70,7 @@ const SlotSection = () => {
|
|
|
) : null}
|
|
|
|
|
|
{/*随机送*/}
|
|
|
- <SlotsModal ref={slotsRef} onAfterHandler={slotRun} />
|
|
|
+ <SlotsModal ref={slotsRef} onAfterHandler={slotRun} onClose={destory} />
|
|
|
</>
|
|
|
);
|
|
|
};
|
|
@@ -70,6 +80,14 @@ const SlotSection = () => {
|
|
|
*/
|
|
|
const WheelSection = ({ onDestory }: any) => {
|
|
|
const wheelModalRef = useRef<WheelModalProps | null>(null);
|
|
|
+ const [data, setData] = useState<any>([]);
|
|
|
+ const { modalShow, closeModalShow } = useModalShow((state: any) => ({
|
|
|
+ modalShow: state.modalShow,
|
|
|
+ closeModalShow: state.closeModalShow,
|
|
|
+ }));
|
|
|
+ const keyName = useMemo(() => {
|
|
|
+ return "WheelSection";
|
|
|
+ }, []);
|
|
|
const { wheelStatus, wheelCurrent, setWheel } = useWheelStore((state) => ({
|
|
|
wheelStatus: state.status,
|
|
|
wheelCurrent: state.currentWheel,
|
|
@@ -79,11 +97,24 @@ const WheelSection = ({ onDestory }: any) => {
|
|
|
useEffect(() => {
|
|
|
setWheel().then((data) => {
|
|
|
if (data && useWheelStore.getState().status === 1) {
|
|
|
- wheelModalRef.current?.onOpen(data);
|
|
|
+ setData(data);
|
|
|
}
|
|
|
});
|
|
|
}, []);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (!data) return;
|
|
|
+ if (modalShow === keyName) {
|
|
|
+ wheelModalRef.current?.onOpen(data);
|
|
|
+ }
|
|
|
+ }, [modalShow, data, keyName]);
|
|
|
+
|
|
|
+ const destoryComponent = () => {
|
|
|
+ if (modalShow === keyName) {
|
|
|
+ closeModalShow(keyName);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
{wheelStatus === 2 ? (
|
|
@@ -99,7 +130,7 @@ const WheelSection = ({ onDestory }: any) => {
|
|
|
) : null}
|
|
|
|
|
|
{/* 轮盘弹窗 */}
|
|
|
- <WheelModal ref={wheelModalRef} />
|
|
|
+ <WheelModal ref={wheelModalRef} onDestory={destoryComponent} />
|
|
|
</>
|
|
|
);
|
|
|
};
|
|
@@ -174,16 +205,6 @@ const PaySection = () => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-/**
|
|
|
- * 神秘彩金
|
|
|
- */
|
|
|
-
|
|
|
-// const JackpotSection = () => {
|
|
|
-// const token = getToken();
|
|
|
-
|
|
|
-// return <div className={clsx("test1232 h-[.4rem] w-[.4rem] bg-[red]")}>2323</div>;
|
|
|
-// };
|
|
|
-
|
|
|
/**
|
|
|
* 红包雨
|
|
|
*/
|
|
@@ -306,9 +327,13 @@ const getMaxSignId = (obj: any) => {
|
|
|
* 签到活动
|
|
|
*/
|
|
|
const SignInSection: FC = () => {
|
|
|
+ const { modalShow, closeModalShow } = useModalShow((state: any) => ({
|
|
|
+ modalShow: state.modalShow,
|
|
|
+ closeModalShow: state.closeModalShow,
|
|
|
+ }));
|
|
|
const SignInRef = useRef<SignInModalProps>(null);
|
|
|
const [activityId, setActivityId] = useState<number | null>(null);
|
|
|
-
|
|
|
+ const keyName = "SignInSection";
|
|
|
const { getSignData, signData } = useSignStore((state) => {
|
|
|
return {
|
|
|
getSignData: state.getSignData,
|
|
@@ -322,26 +347,41 @@ const SignInSection: FC = () => {
|
|
|
if (activity_id) {
|
|
|
setActivityId(activity_id);
|
|
|
await getSignData({ activity_id: activity_id });
|
|
|
- setTimeout(() => {
|
|
|
- localStorage.setItem("sign", `${Date.now()}`);
|
|
|
- signInHandle();
|
|
|
- }, 1000);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
+ const checkIsShowed = () => {
|
|
|
const showTime = localStorage.getItem("sign");
|
|
|
-
|
|
|
if (showTime) {
|
|
|
const nextDay = dayjs(Number(showTime)).add(1, "day").format("YYYY-MM-DD");
|
|
|
if (dayjs(nextDay).isAfter(dayjs())) {
|
|
|
- return;
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|
|
|
- getUserInfo();
|
|
|
+ return false;
|
|
|
+ };
|
|
|
+ useEffect(() => {
|
|
|
+ // if (checkIsShowed()) return;
|
|
|
+ if (getToken()) getUserInfo();
|
|
|
+ // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
}, []);
|
|
|
|
|
|
+ const destoryComponent = () => {
|
|
|
+ closeModalShow(keyName);
|
|
|
+ };
|
|
|
+ useEffect(() => {
|
|
|
+ console.log(modalShow, modalShow === keyName, getToken());
|
|
|
+ if (modalShow === keyName && getToken()) {
|
|
|
+ if (checkIsShowed()) {
|
|
|
+ destoryComponent();
|
|
|
+ } else {
|
|
|
+ localStorage.setItem("sign", `${Date.now()}`);
|
|
|
+ signInHandle();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
+ }, [modalShow, keyName]);
|
|
|
+
|
|
|
const signInHandle = () => {
|
|
|
SignInRef.current?.onOpen();
|
|
|
};
|
|
@@ -361,14 +401,14 @@ const SignInSection: FC = () => {
|
|
|
>
|
|
|
Sign
|
|
|
</div> */}
|
|
|
- <SignInModal ref={SignInRef}></SignInModal>
|
|
|
+ <SignInModal ref={SignInRef} onDestory={destoryComponent}></SignInModal>
|
|
|
</>
|
|
|
);
|
|
|
};
|
|
|
|
|
|
const ServiceWidget: FC<Props> = (props) => {
|
|
|
const { services } = props;
|
|
|
- // const [isShowSign, setIsShowSign] = useState(false);
|
|
|
+ const [type, setType] = useState<number>(0);
|
|
|
|
|
|
const { eventView } = useEventPoint();
|
|
|
const newServices = services?.filter((item) => item.status === 1) || [];
|
|
@@ -389,15 +429,68 @@ const ServiceWidget: FC<Props> = (props) => {
|
|
|
|
|
|
const t = useTranslations("HomePage");
|
|
|
|
|
|
- // const wheelDestory = () => {
|
|
|
- // setIsShowSign(true);
|
|
|
+ // const servicesMap = new Map<number, any>([
|
|
|
+ // [
|
|
|
+ // 0,
|
|
|
+ // {
|
|
|
+ // components: <SlotSection />,
|
|
|
+ // },
|
|
|
+ // ],
|
|
|
+ // [
|
|
|
+ // 1,
|
|
|
+ // {
|
|
|
+ // components: <WheelSection />,
|
|
|
+ // },
|
|
|
+ // ],
|
|
|
+ // [
|
|
|
+ // 2,
|
|
|
+ // {
|
|
|
+ // components: <PaySection />,
|
|
|
+ // },
|
|
|
+ // ],
|
|
|
+ // [
|
|
|
+ // 3,
|
|
|
+ // {
|
|
|
+ // components: <RedPacketSection />,
|
|
|
+ // },
|
|
|
+ // ],
|
|
|
+ // [
|
|
|
+ // 4,
|
|
|
+ // {
|
|
|
+ // components: <MessageSection />,
|
|
|
+ // },
|
|
|
+ // ],
|
|
|
+ // [
|
|
|
+ // 5,
|
|
|
+ // {
|
|
|
+ // components: <CustomerSection services={services} />,
|
|
|
+ // },
|
|
|
+ // ],
|
|
|
+ // [
|
|
|
+ // 6,
|
|
|
+ // {
|
|
|
+ // components: <SignInSection />,
|
|
|
+ // },
|
|
|
+ // ],
|
|
|
+ // ]);
|
|
|
+
|
|
|
+ // const curComponents = useMemo(() => {
|
|
|
+ // return servicesMap.get(type)?.components;
|
|
|
+ // // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
+ // }, [type, services, servicesMap]);
|
|
|
+
|
|
|
+ // const modalDestory = () => {
|
|
|
+ // setType(type + 1);
|
|
|
// };
|
|
|
|
|
|
+ // console.log("type:", type);
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
<div
|
|
|
className={`absolute bottom-[0.84rem] right-[0.12rem] z-50 flex w-[0.6944rem] flex-col items-center justify-center`}
|
|
|
>
|
|
|
+ {/* {React.cloneElement(curComponents, { onDestory: modalDestory })} */}
|
|
|
<SlotSection />
|
|
|
{/*轮盘 */}
|
|
|
<WheelSection />
|