ith5 4 månader sedan
förälder
incheckning
656902bc96

+ 13 - 0
src/api/notifications/index.ts

@@ -24,3 +24,16 @@ export const getNotificationListApi = (params) => {
     data: params,
   });
 };
+
+/**
+ * 标记消息类型通知为已读
+ * @param params {id: number}
+ * @returns
+ */
+export const markAsReadByTypeApi = (params) => {
+  return request({
+    url: `/notifications/mark-as-read-by-type`,
+    method: "POST",
+    data: params,
+  });
+};

+ 0 - 0
src/pages/message/detail


+ 6 - 3
src/pages/message/index.tsx

@@ -3,7 +3,7 @@ import { ArrowRight } from "@nutui/icons-react-taro";
 import { View } from "@tarojs/components";
 import { useEffect, useState } from "react";
 import { getUnreadCountApi } from "../../api/notifications";
-import { navigateTo } from "@tarojs/taro";
+import { navigateTo, useDidShow } from "@tarojs/taro";
 
 const Message = () => {
   const [unreadCount, setUnreadCount] = useState({
@@ -20,9 +20,12 @@ const Message = () => {
       setUnreadCount(res.data[0]);
     }
   };
-  useEffect(() => {
+  // useEffect(() => {
+  //   getUnreadCount();
+  // }, []);
+  useDidShow(() => {
     getUnreadCount();
-  }, []);
+  });
   return (
     <>
       <Cell

+ 13 - 1
src/pages/message/list/index.tsx

@@ -5,7 +5,10 @@ import { Image } from "@nutui/nutui-react-taro";
 import { Message } from "@nutui/icons-react-taro";
 import { useEffect, useState } from "react";
 import CommentInput from "../../../components/comment-list/comment-input";
-import { getNotificationListApi } from "../../../api/notifications";
+import {
+  getNotificationListApi,
+  markAsReadByTypeApi,
+} from "../../../api/notifications";
 const MessageList = () => {
   const [showCommentInput, setShowCommentInput] = useState(false);
   const [notificationList, setNotificationList] = useState<any[]>([]);
@@ -18,18 +21,21 @@ const MessageList = () => {
     switch (options.type) {
       case "like":
         setTypeId("4,5");
+        handleReadNotification("4,5");
         setNavigationBarTitle({
           title: "收到的点赞",
         });
         break;
       case "comment":
         setTypeId("1,2,3");
+        handleReadNotification("1,2,3");
         setNavigationBarTitle({
           title: "评论和@",
         });
         break;
       case "follow":
         setTypeId("6,7");
+        handleReadNotification("6,7");
         setNavigationBarTitle({
           title: "关注和分享",
         });
@@ -39,6 +45,12 @@ const MessageList = () => {
         break;
     }
   });
+
+  // 标记消息类型通知为已读
+  const handleReadNotification = async (type_id) => {
+    markAsReadByTypeApi({ type_id });
+  };
+
   const getNotificationList = async () => {
     const res: any = await getNotificationListApi({
       type_id: typeId,

+ 3 - 4
src/pages/self/index.tsx

@@ -14,7 +14,7 @@ import {
   ImagePreview,
   Tabs,
 } from "@nutui/nutui-react-taro";
-import { navigateTo, getSystemInfoSync } from "@tarojs/taro";
+import { navigateTo, getSystemInfoSync, useDidShow } from "@tarojs/taro";
 import "./index.scss";
 import { useState, useEffect, useCallback } from "react";
 import { strSlice } from "../../utils";
@@ -135,11 +135,10 @@ const Self = () => {
     }
   };
 
-  // 初始加载
-  useEffect(() => {
+  useDidShow(() => {
     getPostList();
     getUserInfo();
-  }, []);
+  });
 
   // 加载更多
   const loadMore = useCallback(() => {