zhejiushizhuce il y a 2 ans
Parent
commit
df4b7d52c0

+ 1 - 1
src/features/protectSlice.js

@@ -22,7 +22,7 @@ const reducerProtectGet=(state,action,arg)=>{
     let msg=getHttpMsg(payload);
     if (payload&&payload.code===200){
         let CurProtectTimes=state.protectInfo.CurProtectTimes!=null?Number(state.protectInfo.CurProtectTimes):0;
-        CurProtectTimes=CurProtectTimes-1;
+        CurProtectTimes=CurProtectTimes+1;
         state.protectInfo.CurProtectTimes=CurProtectTimes;
         if (msg!=null&&msg!="")toast.success(msg);
     }

+ 17 - 4
src/widgets/WProtect/index.jsx

@@ -8,9 +8,10 @@ import {useDispatch, useSelector} from "react-redux";
 import {getProtectGetStatus, getProtectInfo} from "@features/protectSlice";
 import {formatCash, stringFormat} from "@utils/helpers";
 import {REQ_STATUS} from "@api/config";
-import {reqProtectGet} from "@features/api";
+import {reqProtectCheck, reqProtectGet} from "@features/api";
 import {APP_WELFARE} from "@constants/app";
 import {useThemeProvider} from "@contexts/themeContext";
+import {getUserInfo} from "@features/mainSlice";
 const i18n=global.i18n;
 const WProtect = () => {
     const [isShow, setIsShow] = useState(false);
@@ -18,9 +19,11 @@ const WProtect = () => {
     const status=useSelector(getProtectGetStatus);
     const dispatch = useDispatch();
     const {setWelfTabState}=useThemeProvider();
+    const user=useSelector(getUserInfo);
     const show=()=>{
         setIsShow(true);
         setWelfTabState(APP_WELFARE.PROTECT);
+        dispatch(reqProtectCheck());
     }
     const hide=()=>{
         setIsShow(false);
@@ -31,10 +34,19 @@ const WProtect = () => {
             hide();
         }
     }
+    const checkCanProtect=()=>{
+        if (user!=null&&protectInfo!=null){
+            let Score=Number(user.Score)*global.CASH_BASE;
+            let ProtectLimit=protectInfo.ProtectLimit!=null?parseInt(protectInfo.ProtectLimit):0;
+            let CurProtectTimes=protectInfo.CurProtectTimes!=null?parseInt(protectInfo.CurProtectTimes):0;
+            let ProtectTimes=protectInfo.ProtectTimes!=null?parseInt(protectInfo.ProtectTimes):0;
+            return (Score<ProtectLimit)&&(CurProtectTimes<ProtectTimes);
+        }
+        return false;
+    }
     const onGetProtect=()=>{
         if (status===REQ_STATUS.LOADING)return;
-        let CurProtectTimes=protectInfo.CurProtectTimes!=null?parseInt(protectInfo.CurProtectTimes):0;
-        if (CurProtectTimes<=0)return;
+        if (!checkCanProtect())return;
         let ProtectNum=protectInfo.ProtectNum!=null?parseInt(protectInfo.ProtectNum):0;
         dispatch(reqProtectGet({callback:callback,ProtectNum:ProtectNum}));
     }
@@ -64,8 +76,9 @@ const WProtect = () => {
         )
     }
     const renderGetBtn=()=>{
+        let isDisabled=!checkCanProtect();
         return (
-            <button className={styles.p_get_btn} onClick={onGetProtect}>
+            <button className={`${styles.p_get_btn} ${isDisabled?styles.p_get_btn_disabled:''}`} onClick={onGetProtect} disabled={isDisabled}>
                 {
                     status===REQ_STATUS.LOADING?(<SmallLoading fill={"#fff"}/>): (
                         <span className={styles.text}>

+ 3 - 0
src/widgets/WProtect/styles.module.scss

@@ -88,6 +88,9 @@ $btn_bg:"./../../assets/protect/p_btn.png";
   & .text{
     margin-top: -0.3rem;
   }
+  &_disabled{
+    filter: brightness(60%);
+  }
 }
 .p_close{
   position: absolute;