Sfoglia il codice sorgente

feat: 顶部栏消息中心设置消息/全部消息 已读加入防重复点击功能

lanjianrong 4 anni fa
parent
commit
64770f9d64
1 ha cambiato i file con 14 aggiunte e 7 eliminazioni
  1. 14 7
      src/components/RightContent/NoticeIcon/index.tsx

+ 14 - 7
src/components/RightContent/NoticeIcon/index.tsx

@@ -88,13 +88,14 @@ const NoticeIconView = () => {
   const noticeData = getNoticeData(notices)
   const unreadMsg = getUnreadData(noticeData || {})
 
-  const changeReadState = async (id: string) => {
-    const { code = -1 } = await updateNotice({ ids: [id] })
+  const changeReadState = async item => {
+    if (item.isRead) return
+    const { code = -1 } = await updateNotice({ ids: [item.id] })
     if (code === consts.RET_CODE.SUCCESS) {
       setNotices(
-        notices.map(item => {
-          const notice = { ...item }
-          if (notice.id === id) {
+        notices.map(i => {
+          const notice = { ...i }
+          if (notice.id === item.id) {
             notice.isRead = true
           }
           return notice
@@ -108,6 +109,8 @@ const NoticeIconView = () => {
   }
 
   const clearReadState = async (title: string, key: string) => {
+    if (initialState?.currentUser?.[`${title}HasClear`]) return
+
     const ids = []
     setNotices(
       notices.map(item => {
@@ -124,7 +127,11 @@ const NoticeIconView = () => {
       message.success(`${'清空了'} ${title}`)
       setInitialState({
         ...initialState,
-        currentUser: { ...currentUser, unreadCount: currentUser.unreadCount - notices.length }
+        currentUser: {
+          ...currentUser,
+          unreadCount: currentUser.unreadCount - ids.length,
+          [`${title}HasClear`]: true
+        }
       })
     }
   }
@@ -134,7 +141,7 @@ const NoticeIconView = () => {
       className={styles.action}
       count={currentUser && currentUser.unreadCount}
       onItemClick={item => {
-        changeReadState(item.id!)
+        changeReadState(item)
       }}
       onClear={(title: string, key: string) => clearReadState(title, key)}
       loading={false}