import consts from '@/consts'
import { queryNoticeList, queryUnreadNotice, updateNotice } from '@/services/login'
import { BellOutlined } from '@ant-design/icons'
import { Badge, Tabs, List, Typography, Popover } from 'antd'
import { useState, useCallback, useEffect } from 'react'
import styles from './index.less'
const DropdownContent = ({ noticeCount }) => {
const [state, setState] = useState({
noticesTotal: 0,
notices: []
})
const getNotices = useCallback(async () => {
const {
code = -1,
data: { message, total }
} = await queryNoticeList()
if (code === consts.RET_CODE.SUCCESS) {
setState({ ...state, noticesTotal: total, notices: message })
}
}, [])
useEffect(() => {
getNotices()
}, [])
const toggleNotice = id => {
const nNotices = state.notices.map(item => {
if (item.id === id) {
return { ...item, isRead: 1 }
}
return item
})
setState({ ...state, notices: nNotices })
}
const handleTitleClick = async item => {
// 未读
if (!item.isRead) {
const { code = -1 } = await updateNotice({ id: item.id })
if (code === consts.RET_CODE.SUCCESS) {
toggleNotice(item.id)
}
}
}
return (
通知
{noticeCount ? ({noticeCount}) : null}
}
>
(
handleTitleClick(item)}
ellipsis={{ rows: 1, tooltip: true }}
delete={!!item.isRead}
style={{
cursor: !item.isRead ? 'pointer' : '',
width: '100%',
marginBottom: 0
}}
>
{item.content}
}
/>
)}
/>
)
}
const NotifyDropdown = () => {
const [count, setCount] = useState(0)
useEffect(() => {
async function getCount() {
const { code = -1, data = 0 } = await queryUnreadNotice()
if (code === consts.RET_CODE.SUCCESS) {
setCount(data)
}
}
getCount()
}, [])
return (
}
>
)
}
export default NotifyDropdown