year преди 1 месец
родител
ревизия
98997e63b2

+ 19 - 0
src/api/home.ts

@@ -305,6 +305,24 @@ export const getFreeGamesApi = (props: SearchProps) => {
  *   接口ID:240731148
  *   接口地址:https://app.apifox.com/link/project/4790544/apis/api-240731148
  */
+
+export interface EmailAttachItem {
+    coin_type: Number;
+    amount: Number;
+}
+export interface EmailNoticeRep {
+    id: number;
+    title: string;
+    content: string;
+    mail_tips: string;
+    mail_type: number;
+    time_last: number;
+    display_type: number;
+    status: number;
+    attach: EmailAttachItem[];
+    create_at: number;
+}
+
 export const getReplayGamesApi = (props: SearchProps) => {
     return server.post<GameListRep[]>({
         url: "/v1/api/front/game_list_again",
@@ -317,6 +335,7 @@ export interface GlobalNoticeRep extends Omit<NoticeRep, "content"> {
     send_time: number;
     send_user_time: number;
 }
+
 export const getGlobalNoticeApi = () => {
     return server.post<NoticeRep[], { summery: { unread: number; promotion_count: number } }>({
         url: "/v1/api/front/notice_list",

+ 22 - 4
src/app/[locale]/(navbar)/notification/NotificationClient.tsx

@@ -1,5 +1,10 @@
 "use client";
-import { GlobalNoticeRep, updateGlobalNoticeApi, updateUserNoticeApi } from "@/api/home";
+import {
+    EmailNoticeRep,
+    GlobalNoticeRep,
+    updateGlobalNoticeApi,
+    updateUserNoticeApi,
+} from "@/api/home";
 import Tabs from "@/components/Tabs";
 import { useTranslations } from "next-intl";
 import { FC, useState } from "react";
@@ -10,6 +15,7 @@ import { default as Notices } from "./components/Notices";
 interface Props {
     systemNotices: GlobalNoticeRep[];
     userNotices: GlobalNoticeRep[];
+    emailNotices: EmailNoticeRep[];
 }
 const setReadData = (data: GlobalNoticeRep[], key: number) => {
     const newNotices = data.map((item) => {
@@ -24,6 +30,7 @@ const setReadData = (data: GlobalNoticeRep[], key: number) => {
 const NotificationClient: FC<Props> = (props) => {
     const [systemNotices, setSystemNotices] = useState(props.systemNotices);
     const [userNotices, setUserNotices] = useState(props.userNotices);
+    const [emailNotices, setEmailNotices] = useState(props.emailNotices || []);
     const t = useTranslations("ProfilePage");
     const handler = async (active: string, key: string) => {
         if (key === "system") {
@@ -31,15 +38,23 @@ const NotificationClient: FC<Props> = (props) => {
             if (isRead) return;
             updateGlobalNoticeApi(+active).then((r) => {});
             setSystemNotices(setReadData(systemNotices, +active));
-        } else {
+        }
+        if (key === "user") {
             const isRead = userNotices.find((item) => item.id === +active)?.is_read;
             if (isRead) return;
             setUserNotices(setReadData(userNotices, +active));
             updateUserNoticeApi(+active).then((r) => {});
         }
+        if (key === "email") {
+            // const isRead = userNotices.filter((item) => item.status === 0);
+            // if (!isRead) return;
+            // setUserNotices(setReadData(userNotices, +active));
+            // updateUserNoticeApi(+active).then((r) => {});
+        }
 
         await actions();
     };
+
     const defaultTabs = [
         {
             id: 1,
@@ -71,8 +86,11 @@ const NotificationClient: FC<Props> = (props) => {
                     <div>{t("email")}</div>
                 </div>
             ),
-            content: userNotices.reduce((count, notice) => count + (notice.is_read ? 0 : 1), 0),
-            render: <Email></Email>,
+            content: emailNotices.reduce(
+                (count, notice) => count + (notice.status === 0 ? 0 : 1),
+                0
+            ),
+            render: <Email data={emailNotices}></Email>,
         },
     ];
     return <Tabs items={defaultTabs} />;

+ 6 - 1
src/app/[locale]/(navbar)/notification/components/Email.tsx

@@ -1,5 +1,10 @@
+import { EmailNoticeRep } from "@/api/home";
 import styles from "./style.module.scss";
-const Email = () => {
+interface Props {
+    data: EmailNoticeRep[];
+}
+
+const Email: React.FC<Props> = ({ data }) => {
     return (
         <div className={styles.emailBox}>
             <div className={styles.content}>

+ 31 - 4
src/app/[locale]/(navbar)/notification/page.tsx

@@ -1,4 +1,4 @@
-import { GlobalNoticeRep } from "@/api/home";
+import { EmailNoticeRep, GlobalNoticeRep } from "@/api/home";
 import NotificationClient from "@/app/[locale]/(navbar)/notification/NotificationClient";
 import { server } from "@/utils/server";
 import clsx from "clsx";
@@ -18,12 +18,39 @@ const getUserNotices = () => {
         data: {},
     });
 };
+const getEmailNotices = () => {
+    return server.request<EmailNoticeRep[]>({
+        url: "/v1/api/user/mail/getMailList",
+        method: "POST",
+        data: {},
+    });
+};
 const Notification = async () => {
-    const systemNotices = await getSystemNotifications();
-    const userNotices = await getUserNotices();
+    const result = await Promise.allSettled([
+        getSystemNotifications(),
+        getUserNotices(),
+        getEmailNotices(),
+    ]);
+
+    let dataArr: [GlobalNoticeRep[], GlobalNoticeRep[], EmailNoticeRep[]] = [
+        [] as GlobalNoticeRep[],
+        [] as GlobalNoticeRep[],
+        [] as EmailNoticeRep[],
+    ];
+    result.forEach((item, idx) => {
+        if (item.status === "fulfilled") {
+            dataArr[idx] = item.value?.data || [];
+        }
+    });
+    const [systemNotices, userNotices, emailNotices] = dataArr;
+
     return (
         <div className={clsx("h-[100%] overflow-visible pt-[.12rem]", styles.notificationPage)}>
-            <NotificationClient systemNotices={systemNotices.data} userNotices={userNotices.data} />
+            <NotificationClient
+                systemNotices={systemNotices}
+                userNotices={userNotices}
+                emailNotices={emailNotices}
+            />
         </div>
     );
 };