|
|
@@ -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}
|