"use client"; import { getWheelRunApi, WheelsType } from "@/api/cashWheel"; import { useRouter } from "@/i18n/routing"; import useWheelStore from "@/stores/useWheelStore"; import { percentage, timeFormat } from "@/utils/methods"; import { LuckyWheel } from "@lucky-canvas/react"; import NumberFlow from "@number-flow/react"; import { Mask, ProgressBar } from "antd-mobile"; import Image from "next/image"; import { FC, forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from "react"; import animation from "../animations.module.scss"; import styles from "./style.module.scss"; type Props = { onAfterHandler?: () => void; }; export type WheelModalProps = { onClose: () => void; onOpen: (value: WheelsType) => void; }; /** * 轮盘组件 */ const blocks = [ { padding: "0", imgs: [ { src: "/wheels/wheel.png", width: "100%", height: "100%", rotate: true, }, ], }, ]; const prizes = [ { fonts: [ { text: "5000", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "bonus", fontSize: "0.1528rem", }, ], }, { fonts: [{ text: "", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "empty" }], imgs: [ { src: "/wheels/prizes-empty.png", top: "20%", width: "0.2778rem", }, ], }, { fonts: [ { text: "50", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "bonus", fontSize: "0.1528rem", }, ], }, { fonts: [ { text: "", top: "30%", fontColor: "#a47716", fontWeight: "bold", type: "balance" }, ], imgs: [ { src: "/wheels/prizes-money.png", top: "20%", width: "0.3472rem", }, ], }, { fonts: [ { text: "1000", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "bonus", fontSize: "0.1528rem", }, ], }, { imgs: [ { src: "/wheels/prizes-empty.png", top: "20%", width: "0.2778rem", height: "0.2778rem", }, ], }, { fonts: [ { text: "1", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "bonus", fontSize: "0.1528rem", }, ], }, { fonts: [ { text: "", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "balance", fontSize: "0.1528rem", }, ], imgs: [ { src: "/wheels/prizes-money.png", top: "20%", width: "0.3472rem", }, ], }, ]; const defaultConfig = { offsetDegree: 20, }; /** * type: isRotate 是否可旋转, 分享页面不需要旋转, 而是跳转 */ export interface WheelProps { isRotate: boolean; onRotateEnd?: () => void; onRotateBefore?: () => void; onRotateDisable?: () => void; } const noop = () => {}; export const WheelClient: FC = (props) => { const { isRotate, onRotateEnd = noop, onRotateBefore = noop, onRotateDisable = noop } = props; const { statusWheel, currentWheel, setWheel } = useWheelStore((state) => ({ statusWheel: state.status, currentWheel: state.currentWheel, setWheel: state.setWheel, })); // 选中 dom const activeRef = useRef(null); const wheelRef = useRef(); /*是否旋转*/ const rotating = useRef(false); const router = useRouter(); const [isWin, setIsWin] = useState(false); const [buttonText, setButtonText] = useState(0); // 0 -> false 1:true // 当前中奖 const currentWin = useRef({}); const startRotate = (key: string) => { if (!isRotate) { router.push("/register"); return; } // 正在旋转中 if (rotating.current) return; // 如果是没有旋转次数 if (currentWheel.can === 0) { onRotateDisable(); } if (statusWheel !== 1) return; // 开始旋转中 wheelRef.current?.play(); // 点击抽奖按钮会触发star回调 rotating.current = true; // 开始旋转前回调 onRotateBefore(); getWheelRunApi({ activity_id: currentWheel.id! }) .then((res) => { setTimeout(() => { wheelRef.current?.stop(res.data.index); currentWin.current = res.data; }, 2000); }) .catch(() => { wheelRef.current?.init(); }); }; const endRotate = (prize: any) => { activeRef.current!.style.display = "block"; if (currentWin.current.amount > 0) { setIsWin(true); setButtonText(currentWin.current.amount); } else { setButtonText(currentWheel.can || 0); setIsWin(false); } setTimeout(() => { setWheel().then((data) => { rotating.current = false; if (activeRef.current) { activeRef.current.style.display = "none"; } onRotateEnd && onRotateEnd(); setButtonText(data?.activate.can || 0); }); // 重置状态 setIsWin(false); }, 2000); }; useEffect(() => { setButtonText(currentWheel.can || 0); }, [currentWheel.can]); return (
{/*定位到中心圆*/}
{/**/}
endRotate(prize)} />
startRotate("desktop")} > {"start"}

{buttonText > 0 && isWin ? "+" : ""}

); }; export const LeftListClient = () => { const allHistory: any[] = Array.from({ length: 100 }).map((item) => ({ phone_number: `55****${Math.floor(Math.random() * 10000) .toString() .padStart(4, "0")}`, receive_time: Date.now(), })); return ( <>
{allHistory && allHistory.length > 0 && allHistory?.map((item, index) => { return (
{item.phone_number} {timeFormat(item.receive_time, "br", undefined, true)}
+100 R$
); })}
); }; const DetailClient = (props: { onUnload: () => void }) => { const { onUnload } = props; const router = useRouter(); const { totalCount, currentWheel, setWheel } = useWheelStore((state) => ({ statusWheel: state.status, currentWheel: state.currentWheel, setWheel: state.setWheel, totalCount: state.totalCount, })); const [count, setCount] = useState(0); const goPage = () => { router.push("/cashWheel"); onUnload(); }; useEffect(() => { setCount(currentWheel.amount || 0); }, [currentWheel.amount]); return (
SACAR{" "}
{percentage(count, 100)}%
{/*
*/} {/* */} {/*
*/}
Ainda e necessário{" "} {" "} {" "} para realizar do saque{" "}
Reivindique mais para sacar
); }; const WheelModal = forwardRef(function RedPacketModal(props, ref) { const [visible, setVisible] = useState(false); const [detailsVisible, setDetailsVisible] = useState(false); useImperativeHandle(ref, () => { return { onClose: () => setVisible(false), onOpen: () => { setVisible(true); }, }; }); const onRotateEnd = () => { setVisible(false); setDetailsVisible(true); }; const onUnload = () => { setDetailsVisible(false); }; return ( <>
{"moeny"} Receba R$ 100 de graca
setDetailsVisible(false)} >
setVisible(false)} >
); }); export default memo(WheelModal);