From 69a3aa26e12fc89eee8d65e15dc0e5ae6a46d659 Mon Sep 17 00:00:00 2001 From: pengm <674192343@qq.com> Date: Mon, 20 Oct 2025 10:47:05 +0800 Subject: [PATCH] 1.完善企业公告弹窗功能 --- src/components/Common/PersonCenter/PersonCenter.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/components/Common/PersonCenter/PersonCenter.js b/src/components/Common/PersonCenter/PersonCenter.js index 682f59e..86e0a46 100644 --- a/src/components/Common/PersonCenter/PersonCenter.js +++ b/src/components/Common/PersonCenter/PersonCenter.js @@ -217,7 +217,9 @@ class PersonCenter extends Component { // 1. 在调用接口前先检查是否已经显示过该公告 const noticeKey = `${sMsgId}_${sMsgSlaveId}`; - const shownNotices = JSON.parse(localStorage.getItem('shownNotices') || '[]'); + const shownNotices = localStorage.getItem('shownNotices') || ''; + + console.log('shownNotices', shownNotices, noticeKey); // 如果已经显示过,直接返回,不调用接口 if (shownNotices.includes(noticeKey)) { @@ -238,8 +240,8 @@ class PersonCenter extends Component { const noticeData = dataReturn[0]; // 3. 再次确认是否已显示(防止并发请求) - const currentShownNotices = JSON.parse(localStorage.getItem('shownNotices') || '[]'); - console.log('currentShownNotices1', currentShownNotices); + const currentShownNotices = localStorage.getItem('shownNotices') || ''; + console.log('currentShownNotices11', currentShownNotices); if (!currentShownNotices.includes(noticeKey)) { this.setState({ noticeVisible: true, @@ -273,16 +275,9 @@ class PersonCenter extends Component { message.success('公告已阅读'); // 在用户确认阅读后,才将公告记录存储到shownNotices中 const noticeKey = `${sMsgId}_${sMsgSlaveId}`; - const currentShownNotices = JSON.parse(localStorage.getItem('shownNotices') || '[]'); - - if (!currentShownNotices.includes(noticeKey)) { - currentShownNotices.push(noticeKey); - // 限制存储最近100条记录,防止localStorage过大 - if (currentShownNotices.length > 100) { - currentShownNotices.shift(); - } - localStorage.setItem('shownNotices', JSON.stringify(currentShownNotices)); - } + const currentShownNotices = localStorage.getItem('shownNotices') || ''; + console.log('noticeKe11111y', noticeKey); + localStorage.setItem('shownNotices', JSON.stringify(noticeKey)); } else { message.error(configReturn?.msg); } @@ -1141,7 +1136,11 @@ const PersonCenterNotice = Form.create({ { noticeVisible ? + {NoticeTitle} + + } width={1200} visible={noticeVisible} onCancel={handleNoticeCancel} @@ -1153,7 +1152,7 @@ const PersonCenterNotice = Form.create({ display: 'flex', alignItems: 'center', width: '100%', - justifyContent: 'flex-start', + justifyContent: 'flex-end', padding: '0px 24px 16px 16px', margin: '0', // 清除外部默认边距 }} -- libgit2 0.22.2