Explorar o código

feat: 修改按钮

year hai 1 mes
pai
achega
63d9bc3f94

+ 1 - 0
messages/br.json

@@ -355,6 +355,7 @@
         "beforeTips": "Periodo",
         "cashbackStatus": "VIP cashback statuses",
         "receiveButton": "Reivindicar Agora",
+        "goGame": "Vai jogar jogos",
         "rules": "TERMOS E REGRAS",
         "rulesFirst": "O cashback semanal é dado como recompensa todas as semanas",
         "rulesSecond": "O período sobre o qual é calculado o cashback semanal vai de segunda-feira às 00:00 a domingo às 23:59.",

+ 2 - 1
src/api/cashback.ts

@@ -1,3 +1,4 @@
+import { CashbackStatusEnum } from "@/enums";
 import { server } from "@/utils/client";
 
 export interface CashbackTypes {
@@ -24,7 +25,7 @@ export interface CashbackTypes {
     /**
      * 领取状态: 进行中running、待领取pending、已领取received、已过期expired
      */
-    status: string;
+    status: CashbackStatusEnum;
 
     max_amount: number;
 }

+ 8 - 2
src/app/[locale]/(navbar)/cashback/components/Extract.tsx

@@ -1,5 +1,7 @@
 "use client";
 import { CashbackTypes } from "@/api/cashback";
+import { CashbackStatusEnum, CashbackStatusMap } from "@/enums";
+import { useRouter } from "@/i18n/routing";
 import { server } from "@/utils/client";
 import { brTimeFormat } from "@/utils/methods";
 import { Toast } from "antd-mobile";
@@ -12,11 +14,12 @@ interface Props {
 }
 const Extract = (props: Props) => {
     const { local, cashbackInfo } = props;
+    const router = useRouter();
     const [scope, animate] = useAnimate();
 
     const t = useTranslations();
     const getCashbackGiveApi = () => {
-        if (cashbackInfo.status !== "pending") {
+        if (cashbackInfo.status !== CashbackStatusEnum.PENDING) {
             animate(
                 scope.current,
                 { color: ["#000", "#ffaa30", "#000"] },
@@ -26,6 +29,9 @@ const Extract = (props: Props) => {
                     repeatType: "loop",
                 }
             );
+            setTimeout(() => {
+                router.push("/");
+            }, 2000);
             return;
         }
         if (cashbackInfo.amount === 0) {
@@ -73,7 +79,7 @@ const Extract = (props: Props) => {
                 }
                 onClick={getCashbackGiveApi}
             >
-                <span>{t("cashback.receiveButton")}</span>
+                <span>{t(CashbackStatusMap.get(cashbackInfo.status))}</span>
             </div>
         </>
     );

+ 4 - 2
src/app/[locale]/(navbar)/cashback/page.tsx

@@ -27,7 +27,7 @@ const getVipInfoApi = async () => {
         });
 };
 
-const getCashBackApi = async () => {
+const getCashBackApi = async (): Promise<CashbackTypes> => {
     return server
         .request<CashbackTypes>({
             url: "/v1/api/front/activity_cash",
@@ -48,12 +48,14 @@ const getCashBackApi = async () => {
                 bet: 0,
                 status: "expired",
                 max_amount: 0,
-            };
+            } as CashbackTypes;
         });
 };
 const CashbackInfo = async () => {
     const vipInfo = await getVipInfoApi();
     const cashbackInfo = await getCashBackApi();
+
+    console.log(112233, cashbackInfo);
     const currentGrade = cashbackInfo.rules?.find(
         (item) => item.level === (vipInfo.vip_level || 1)
     );

+ 16 - 0
src/enums/index.tsx

@@ -10,3 +10,19 @@ export const BtnTypeMap = new Map<BtnTypeEnum, string>([
     [BtnTypeEnum.DEPOSITE, "Recarregar"],
     [BtnTypeEnum.CANCLAIM, "Receber Recompensa"],
 ]);
+
+// 进行中running、待领取pending、已领取received、已过期expired
+
+export enum CashbackStatusEnum {
+    "RUNNING" = "running",
+    "PENDING" = "pending",
+    "RECEIVED" = "received",
+    "EXPIRED" = "expired",
+}
+
+export const CashbackStatusMap = new Map<CashbackStatusEnum, string>([
+    [CashbackStatusEnum.RUNNING, "cashback.goGame"],
+    [CashbackStatusEnum.PENDING, "cashback.receiveButton"],
+    [CashbackStatusEnum.RECEIVED, "cashback.goGame"],
+    [CashbackStatusEnum.EXPIRED, "cashback.goGame"],
+]);