|
@@ -6,17 +6,23 @@ import light2 from "@assets/wheel/light2.png";
|
|
|
import spinBg from "@assets/wheel/spinBg.png";
|
|
import spinBg from "@assets/wheel/spinBg.png";
|
|
|
import pointer from "@assets/wheel/pointer.png"
|
|
import pointer from "@assets/wheel/pointer.png"
|
|
|
import styled from 'styled-components/macro';
|
|
import styled from 'styled-components/macro';
|
|
|
-import {useEffect, useRef, useState} from "react";
|
|
|
|
|
|
|
+import React, {useEffect, useRef, useState} from "react";
|
|
|
import spin_1 from "@assets/wheel/spin-1.png";
|
|
import spin_1 from "@assets/wheel/spin-1.png";
|
|
|
import spin_2 from "@assets/wheel/spin-2.png";
|
|
import spin_2 from "@assets/wheel/spin-2.png";
|
|
|
import spin_4 from "@assets/wheel/spin-4.png";
|
|
import spin_4 from "@assets/wheel/spin-4.png";
|
|
|
import spin_5 from "@assets/wheel/spin-5.png";
|
|
import spin_5 from "@assets/wheel/spin-5.png";
|
|
|
import draw from "@assets/wheel/draw.png";
|
|
import draw from "@assets/wheel/draw.png";
|
|
|
-import {useSelector} from "react-redux";
|
|
|
|
|
-import {getTurnplate} from "@features/turnplateSlice";
|
|
|
|
|
-import {formatTime} from "@utils/helpers";
|
|
|
|
|
|
|
+import {useDispatch, useSelector} from "react-redux";
|
|
|
|
|
+import {getTurnplate, updateCollect, updateTimes} from "@features/turnplateSlice";
|
|
|
|
|
+import {formatCash, formatTime} from "@utils/helpers";
|
|
|
import SvgIcon from "@components/SvgIcon";
|
|
import SvgIcon from "@components/SvgIcon";
|
|
|
import {ReactComponent as ShareIcon} from '@assets/singlesvg/share.svg';
|
|
import {ReactComponent as ShareIcon} from '@assets/singlesvg/share.svg';
|
|
|
|
|
+import {isLogined} from "@features/mainSlice";
|
|
|
|
|
+import {useNavigate} from "react-router";
|
|
|
|
|
+import {ROUTE_PATH} from "@constants/routes";
|
|
|
|
|
+import {reqTurnplateKan} from "@features/api";
|
|
|
|
|
+import CountUp from "react-countup";
|
|
|
|
|
+import WPopInfo from "@widgets/WCashWheel/WPopInfo/WPopInfo";
|
|
|
const i18n=global.i18n;
|
|
const i18n=global.i18n;
|
|
|
const spinImgSrc=[
|
|
const spinImgSrc=[
|
|
|
null,
|
|
null,
|
|
@@ -33,9 +39,13 @@ const StyledCanvas=styled.canvas`
|
|
|
const turnObj={
|
|
const turnObj={
|
|
|
timer:null,
|
|
timer:null,
|
|
|
cdTimer:null,
|
|
cdTimer:null,
|
|
|
- count:0
|
|
|
|
|
|
|
+ count:0,
|
|
|
|
|
+ result:null,
|
|
|
|
|
+ resTimer:null,
|
|
|
|
|
+ flashTimer:null,
|
|
|
|
|
+ resetTimer:null
|
|
|
};
|
|
};
|
|
|
-const WWheel=()=>{
|
|
|
|
|
|
|
+const WWheel=({openShare,showShare=true,onClose=null})=>{
|
|
|
let turnplate=useSelector(getTurnplate);
|
|
let turnplate=useSelector(getTurnplate);
|
|
|
if(turnplate==null)turnplate={times:0};
|
|
if(turnplate==null)turnplate={times:0};
|
|
|
const data=[
|
|
const data=[
|
|
@@ -55,6 +65,14 @@ const WWheel=()=>{
|
|
|
const startRotateDegreeDynamic=3240;
|
|
const startRotateDegreeDynamic=3240;
|
|
|
const [drawStyle,setDrawStyle]=useState({});
|
|
const [drawStyle,setDrawStyle]=useState({});
|
|
|
const [countdown,setCountdown]=useState(turnplate?turnplate.countdown:0);
|
|
const [countdown,setCountdown]=useState(turnplate?turnplate.countdown:0);
|
|
|
|
|
+ const isLogin=useSelector(isLogined);
|
|
|
|
|
+ const navigate=useNavigate();
|
|
|
|
|
+ const dispatch = useDispatch();
|
|
|
|
|
+ const stopduring=5.5;
|
|
|
|
|
+ const resetduring=2;
|
|
|
|
|
+ const [collect,setCollect]=useState(0);
|
|
|
|
|
+ const [isLock,setIsLock]=useState(false);
|
|
|
|
|
+ const [openPopInfo,setOpenPopInfo]=useState(false);
|
|
|
const loadImgs=()=>{
|
|
const loadImgs=()=>{
|
|
|
let totalCount=spinImgSrc.length;
|
|
let totalCount=spinImgSrc.length;
|
|
|
let loadedCount=0;
|
|
let loadedCount=0;
|
|
@@ -87,13 +105,6 @@ const WWheel=()=>{
|
|
|
turnObj.cdTimer=null;
|
|
turnObj.cdTimer=null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- const updateCD=()=>{
|
|
|
|
|
- if (countdown<=0){
|
|
|
|
|
- clearCDTimer();
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- setCountdown(countdown-1);
|
|
|
|
|
- }
|
|
|
|
|
const checkCountdown=()=>{
|
|
const checkCountdown=()=>{
|
|
|
if (countdown>0){
|
|
if (countdown>0){
|
|
|
clearCDTimer();
|
|
clearCDTimer();
|
|
@@ -109,9 +120,28 @@ const WWheel=()=>{
|
|
|
},1000);
|
|
},1000);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ const onTurnResult=(data)=>{
|
|
|
|
|
+ let collect_amount=data.collect_amount;
|
|
|
|
|
+ let ids=[0,4];
|
|
|
|
|
+ let index=Math.floor(Math.random()*ids.length);
|
|
|
|
|
+ let id=ids[index];
|
|
|
|
|
+ turnObj.result={
|
|
|
|
|
+ reward:id,
|
|
|
|
|
+ amount:collect_amount
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
const startSpin=()=>{
|
|
const startSpin=()=>{
|
|
|
- // drawAnimation();
|
|
|
|
|
|
|
+ if (!isLogin){
|
|
|
|
|
+ if (onClose)onClose();
|
|
|
|
|
+ navigate(ROUTE_PATH.SIGN_IN);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isLock)return;
|
|
|
|
|
+ if (turnplate.times<=0)return;
|
|
|
startTurn();
|
|
startTurn();
|
|
|
|
|
+ dispatch(reqTurnplateKan(onTurnResult));
|
|
|
|
|
+ dispatch(updateTimes({times:(turnplate.times-1)}))
|
|
|
|
|
+ setIsLock(true);
|
|
|
}
|
|
}
|
|
|
const clearTurnTimer=()=>{
|
|
const clearTurnTimer=()=>{
|
|
|
if (turnObj.timer!=null){
|
|
if (turnObj.timer!=null){
|
|
@@ -137,9 +167,10 @@ const WWheel=()=>{
|
|
|
transition:`transform ${during}s cubic-bezier(1.00, 1.00, 0.00, 0.00)`,
|
|
transition:`transform ${during}s cubic-bezier(1.00, 1.00, 0.00, 0.00)`,
|
|
|
}
|
|
}
|
|
|
setDrawStyle(roteStyle);
|
|
setDrawStyle(roteStyle);
|
|
|
- if(turnCount>3){
|
|
|
|
|
- // drawAnimation(turnCount*360+startRotateDegreeDynamic);
|
|
|
|
|
- stopTurn(1);
|
|
|
|
|
|
|
+ if(turnCount>2){
|
|
|
|
|
+ if (turnObj.result){
|
|
|
|
|
+ stopTurn(turnObj.result.reward);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
},during*1000);
|
|
},during*1000);
|
|
|
turnObj.timer=timer;
|
|
turnObj.timer=timer;
|
|
@@ -161,11 +192,66 @@ const WWheel=()=>{
|
|
|
clearTurnTimer();
|
|
clearTurnTimer();
|
|
|
let roteStyle={
|
|
let roteStyle={
|
|
|
transform:"rotate(".concat(angle, "deg)"),
|
|
transform:"rotate(".concat(angle, "deg)"),
|
|
|
- transition:"transform 5.5s cubic-bezier(0.250, 0.460, 0.455, 0.995)",
|
|
|
|
|
|
|
+ transition:`transform ${stopduring}s cubic-bezier(0.250, 0.460, 0.455, 0.995)`,
|
|
|
};
|
|
};
|
|
|
setDrawStyle(roteStyle);
|
|
setDrawStyle(roteStyle);
|
|
|
|
|
+ playRes();
|
|
|
|
|
+ }
|
|
|
|
|
+ const flashDraw=()=>{
|
|
|
|
|
+ let show=false;
|
|
|
|
|
+ turnObj.flashTimer=setInterval(()=>{
|
|
|
|
|
+ show=!show;
|
|
|
|
|
+ let result=show?turnObj.result:null;
|
|
|
|
|
+ drawWheel(result)
|
|
|
|
|
+ },260)
|
|
|
|
|
+ }
|
|
|
|
|
+ const playRes=()=>{
|
|
|
|
|
+ clearResTimer();
|
|
|
|
|
+ let during=(stopduring+0.5)*1000;
|
|
|
|
|
+ turnObj.resTimer=setTimeout(()=>{
|
|
|
|
|
+ flashDraw();
|
|
|
|
|
+ setCollect(turnObj.result.amount);
|
|
|
|
|
+ startReset();
|
|
|
|
|
+ dispatch(updateCollect({collect_amount:turnObj.result.amount}))
|
|
|
|
|
+ },during)
|
|
|
|
|
+ }
|
|
|
|
|
+ // const
|
|
|
|
|
+ const clearResTimer=()=>{
|
|
|
|
|
+ if (turnObj.resTimer){
|
|
|
|
|
+ clearTimeout(turnObj.resTimer);
|
|
|
|
|
+ turnObj.resTimer=null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (turnObj.flashTimer){
|
|
|
|
|
+ clearInterval(turnObj.flashTimer);
|
|
|
|
|
+ turnObj.flashTimer=null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- const drawWheel=()=>{
|
|
|
|
|
|
|
+ const startReset=()=>{
|
|
|
|
|
+ turnObj.resetTimer=setTimeout(()=>{
|
|
|
|
|
+ resetWheel();
|
|
|
|
|
+ },resetduring*1000)
|
|
|
|
|
+ }
|
|
|
|
|
+ const resetWheel=()=>{
|
|
|
|
|
+ turnObj.result=null;
|
|
|
|
|
+ turnObj.count=0;
|
|
|
|
|
+ let roteStyle={
|
|
|
|
|
+ transform:"rotate(0deg)",
|
|
|
|
|
+ transition:``,
|
|
|
|
|
+ };
|
|
|
|
|
+ setDrawStyle(roteStyle);
|
|
|
|
|
+ drawWheel(null);
|
|
|
|
|
+ setCollect(0);
|
|
|
|
|
+ setIsLock(false);
|
|
|
|
|
+ setOpenPopInfo(true);
|
|
|
|
|
+ clearResTimer();
|
|
|
|
|
+ }
|
|
|
|
|
+ const clearResetTimer=()=>{
|
|
|
|
|
+ if (turnObj.resetTimer){
|
|
|
|
|
+ clearTimeout(turnObj.resetTimer);
|
|
|
|
|
+ turnObj.resetTimer=null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ const drawWheel=(result)=>{
|
|
|
let draw=drawRef.current;
|
|
let draw=drawRef.current;
|
|
|
if (draw==null)return;
|
|
if (draw==null)return;
|
|
|
let colors=["#B90615","#FFD760"];
|
|
let colors=["#B90615","#FFD760"];
|
|
@@ -190,6 +276,19 @@ const WWheel=()=>{
|
|
|
let item=rdat[i];
|
|
let item=rdat[i];
|
|
|
if (item==null)continue;
|
|
if (item==null)continue;
|
|
|
let color=colors[i%color_len];
|
|
let color=colors[i%color_len];
|
|
|
|
|
+ if (result){
|
|
|
|
|
+ if(result.reward===item.id){
|
|
|
|
|
+ c.beginPath();
|
|
|
|
|
+ c.moveTo(0, 0);
|
|
|
|
|
+ c.arc(0, 0, s.width / 2 - 6, -l / 2, l / 2.08);
|
|
|
|
|
+ c.strokeStyle = "#fff";
|
|
|
|
|
+ c.fillStyle = "#fff";
|
|
|
|
|
+ c.lineWidth = 10;
|
|
|
|
|
+ c.lineTo(0, -5);
|
|
|
|
|
+ c.stroke();
|
|
|
|
|
+ c.closePath();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
c.rotate(l);
|
|
c.rotate(l);
|
|
|
c.save();
|
|
c.save();
|
|
|
c.beginPath();
|
|
c.beginPath();
|
|
@@ -216,6 +315,9 @@ const WWheel=()=>{
|
|
|
return ()=>{
|
|
return ()=>{
|
|
|
clearTurnTimer();
|
|
clearTurnTimer();
|
|
|
clearCDTimer();
|
|
clearCDTimer();
|
|
|
|
|
+ clearResTimer();
|
|
|
|
|
+ turnObj.result=null;
|
|
|
|
|
+ clearResetTimer();
|
|
|
}
|
|
}
|
|
|
},[]);
|
|
},[]);
|
|
|
useEffect(()=>{
|
|
useEffect(()=>{
|
|
@@ -236,8 +338,35 @@ const WWheel=()=>{
|
|
|
}}>
|
|
}}>
|
|
|
<img src={draw} className={styles.spin_img}/>
|
|
<img src={draw} className={styles.spin_img}/>
|
|
|
<div className={styles.spin_content}>
|
|
<div className={styles.spin_content}>
|
|
|
- <div className={styles.spin_num}>{times}</div>
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ collect>0?(
|
|
|
|
|
+ <CountUp
|
|
|
|
|
+ start={0}
|
|
|
|
|
+ end={Number(formatCash(collect))}
|
|
|
|
|
+ duration={1}
|
|
|
|
|
+ separator=" "
|
|
|
|
|
+ decimals={2}
|
|
|
|
|
+ prefix={"+"}
|
|
|
|
|
+ >
|
|
|
|
|
+ {({ countUpRef, start }) => {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div ref={(ref)=>{
|
|
|
|
|
+ countUpRef.current=ref;
|
|
|
|
|
+ if (countUpRef.collect!==collect){
|
|
|
|
|
+ countUpRef.collect=collect;
|
|
|
|
|
+ start();
|
|
|
|
|
+ }
|
|
|
|
|
+ }} className={styles.collect_num}/>
|
|
|
|
|
+ )
|
|
|
|
|
+ }}
|
|
|
|
|
+ </CountUp>
|
|
|
|
|
+ ):(
|
|
|
|
|
+
|
|
|
|
|
+ <div className={styles.spin_num}>{times}</div>
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
|
</>
|
|
</>
|
|
@@ -256,13 +385,27 @@ const WWheel=()=>{
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
const renderShareBar=()=>{
|
|
const renderShareBar=()=>{
|
|
|
|
|
+ if (showShare){
|
|
|
|
|
+ return (
|
|
|
|
|
+ <button className={styles.share_con} onClick={()=>{
|
|
|
|
|
+ if (openShare)openShare();
|
|
|
|
|
+ }}>
|
|
|
|
|
+ <div className={styles.share_bar}>
|
|
|
|
|
+ <div className={styles.text}>{i18n.t("turnplate.invite_tips")}</div>
|
|
|
|
|
+ <ShareIcon className={styles.icon}/>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </button>
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return (<></>);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ const renderPopInfo=()=>{
|
|
|
return (
|
|
return (
|
|
|
- <button className={styles.share_con}>
|
|
|
|
|
- <div className={styles.share_bar}>
|
|
|
|
|
- <div className={styles.text}>{i18n.t("turnplate.invite_tips")}</div>
|
|
|
|
|
- <ShareIcon className={styles.icon}/>
|
|
|
|
|
- </div>
|
|
|
|
|
- </button>
|
|
|
|
|
|
|
+ <WPopInfo open={openPopInfo} onClose={()=>{
|
|
|
|
|
+ setOpenPopInfo(false);
|
|
|
|
|
+ }} openShare={openShare}></WPopInfo>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
return (
|
|
return (
|
|
@@ -282,6 +425,7 @@ const WWheel=()=>{
|
|
|
</div>
|
|
</div>
|
|
|
{renderCountDown()}
|
|
{renderCountDown()}
|
|
|
{renderShareBar()}
|
|
{renderShareBar()}
|
|
|
|
|
+ {renderPopInfo()}
|
|
|
</div>
|
|
</div>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|