修改小铃铛

This commit is contained in:
何童崇 2021-09-15 16:32:32 +08:00
parent 49fad4b8bc
commit 06314a51a6
1 changed files with 26 additions and 6 deletions

View File

@ -22,7 +22,6 @@ function NoticeContent({ visible, showNotification, resetUserInfo, current_user:
const [atUnreadCount, setAtUnreadCount] = useState();//@
const [atPage, setAtPage] = useState(0);
const [atUnreadList, setAtUnreadList] = useState([]);//@
const [reload, setReload] = useState(0);
useEffect(() => {
const params = {
@ -45,7 +44,7 @@ function NoticeContent({ visible, showNotification, resetUserInfo, current_user:
params.type = "atme"
}
visible && getMessageList(params);
}, [reload, visible]);
}, [visible]);
function getMessageList(params) {
@ -87,14 +86,33 @@ function NoticeContent({ visible, showNotification, resetUserInfo, current_user:
let data = response.data;
if (!data) return;
if (data.status === 0) {
setReload(Math.random());
resetUserInfo();
changeReadMarkAll(noticeType);
} else {
showNotification(data.message);
}
});
}
function changeReadMarkAll(noticeType) {
if (noticeType === "notification") {
let list = noticeUnreadList.slice();
list.forEach(item => {
item.status = 2;
})
setNoticeUnreadList(list);
setNoticeUnreadCount(0);
} else if (noticeType === "atme") {
let list = atUnreadList.slice();
list.forEach(item => {
item.status = 2;
})
setAtUnreadList(list);
setAtUnreadCount(0);
}
}
// const [letter_unread_list, setLetter_unread_list] = useState([
// {
// id: 122,
@ -123,6 +141,7 @@ function NoticeContent({ visible, showNotification, resetUserInfo, current_user:
});
}
function changeReadMark(item) {
if (item.type === "notification") {
let list = noticeUnreadList.slice();
@ -169,7 +188,7 @@ function NoticeContent({ visible, showNotification, resetUserInfo, current_user:
<span style={{ visibility: item.status === 1 ? 'visible' : 'hidden' }}>
<Badge color="#FA2020" />
</span>
<i className={"iconfont "+noticeSourceType[item.source]}></i>
<i className={"iconfont " + noticeSourceType[item.source]}></i>
<div className="noticeCont-text">
<span className="content-span notice-cont-span" dangerouslySetInnerHTML={{ __html: item.content }}></span>
<span className="timeSpan">{item.time_ago}</span>
@ -198,7 +217,7 @@ function NoticeContent({ visible, showNotification, resetUserInfo, current_user:
<Badge color="#FA2020" />
</span>
<div className="noticeCont-text">
<span className="content-span atme-cont-span" dangerouslySetInnerHTML={{ __html: "<b>" + item.sender.name +"</b>&nbsp;&nbsp;&nbsp;" + item.content +" 中@我"}}></span>
<span className="content-span atme-cont-span" dangerouslySetInnerHTML={{ __html: "<b>" + (item.sender ? item.sender.name : '') + "</b>&nbsp;&nbsp;&nbsp;" + item.content + " 中@我" }}></span>
<span className="timeSpan">{item.time_ago}</span>
</div>
</div>
@ -226,7 +245,8 @@ function NoticeContent({ visible, showNotification, resetUserInfo, current_user:
}) : "暂无数据" : ""} */}
<div className="hoverNotice-buttom">
<Link to="/settings/notice">全部消息</Link>
<a onClick={readAll}>所有{noticeType === "notification" ? "系统消息" : noticeType === "letter" ? "私信" : "@我"}一键已读</a>
{noticeUnreadCount > 0 && noticeType === "notification" && <a onClick={readAll}>所有系统消息一键已读</a>}
{atUnreadCount > 0 && noticeType === "atme" && <a onClick={readAll}>所有"@我"一键已读</a>}
</div>
</div>