|
|
@@ -1,7 +1,7 @@
|
|
|
import { useCallback, useEffect, useState } from 'react'
|
|
|
import { Tag, message } from 'antd'
|
|
|
import { groupBy } from 'lodash-es'
|
|
|
-import { useModel } from 'umi'
|
|
|
+import { useModel, history } from 'umi'
|
|
|
|
|
|
import NoticeIcon from './NoticeIcon'
|
|
|
import styles from './index.less'
|
|
|
@@ -72,7 +72,7 @@ const getUnreadData = (noticeData: Record<string, API.NoticeIconItem[]>) => {
|
|
|
}
|
|
|
|
|
|
const NoticeIconView = () => {
|
|
|
- const { initialState } = useModel('@@initialState')
|
|
|
+ const { initialState, setInitialState } = useModel('@@initialState')
|
|
|
const { currentUser } = initialState || {}
|
|
|
const [notices, setNotices] = useState([])
|
|
|
const getNotices = useCallback(async () => {
|
|
|
@@ -89,7 +89,7 @@ const NoticeIconView = () => {
|
|
|
const unreadMsg = getUnreadData(noticeData || {})
|
|
|
|
|
|
const changeReadState = async (id: string) => {
|
|
|
- const { code = -1 } = await updateNotice({ id })
|
|
|
+ const { code = -1 } = await updateNotice({ ids: [id] })
|
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
|
setNotices(
|
|
|
notices.map(item => {
|
|
|
@@ -100,20 +100,33 @@ const NoticeIconView = () => {
|
|
|
return notice
|
|
|
})
|
|
|
)
|
|
|
+ setInitialState({
|
|
|
+ ...initialState,
|
|
|
+ currentUser: { ...currentUser, unreadCount: currentUser.unreadCount - 1 }
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const clearReadState = (title: string, key: string) => {
|
|
|
+ const clearReadState = async (title: string, key: string) => {
|
|
|
+ const ids = []
|
|
|
setNotices(
|
|
|
notices.map(item => {
|
|
|
const notice = { ...item }
|
|
|
if (notice.msgType === key) {
|
|
|
notice.isRead = true
|
|
|
+ ids.push(item.id)
|
|
|
}
|
|
|
return notice
|
|
|
})
|
|
|
)
|
|
|
- message.success(`${'清空了'} ${title}`)
|
|
|
+ const { code = -1 } = await updateNotice({ ids })
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ message.success(`${'清空了'} ${title}`)
|
|
|
+ setInitialState({
|
|
|
+ ...initialState,
|
|
|
+ currentUser: { ...currentUser, unreadCount: currentUser.unreadCount - notices.length }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
@@ -127,7 +140,7 @@ const NoticeIconView = () => {
|
|
|
loading={false}
|
|
|
clearText="清空"
|
|
|
viewMoreText="查看更多"
|
|
|
- onViewMore={() => message.info('Click on view more')}
|
|
|
+ onViewMore={() => history.push('/hr/notification')}
|
|
|
clearClose
|
|
|
>
|
|
|
<NoticeIcon.Tab
|