Commit 69a3aa26e12fc89eee8d65e15dc0e5ae6a46d659
1 parent
c080970d
1.完善企业公告弹窗功能
Showing
1 changed file
with
14 additions
and
15 deletions
src/components/Common/PersonCenter/PersonCenter.js
| @@ -217,7 +217,9 @@ class PersonCenter extends Component { | @@ -217,7 +217,9 @@ class PersonCenter extends Component { | ||
| 217 | // 1. 在调用接口前先检查是否已经显示过该公告 | 217 | // 1. 在调用接口前先检查是否已经显示过该公告 |
| 218 | const noticeKey = `${sMsgId}_${sMsgSlaveId}`; | 218 | const noticeKey = `${sMsgId}_${sMsgSlaveId}`; |
| 219 | 219 | ||
| 220 | - const shownNotices = JSON.parse(localStorage.getItem('shownNotices') || '[]'); | 220 | + const shownNotices = localStorage.getItem('shownNotices') || ''; |
| 221 | + | ||
| 222 | + console.log('shownNotices', shownNotices, noticeKey); | ||
| 221 | 223 | ||
| 222 | // 如果已经显示过,直接返回,不调用接口 | 224 | // 如果已经显示过,直接返回,不调用接口 |
| 223 | if (shownNotices.includes(noticeKey)) { | 225 | if (shownNotices.includes(noticeKey)) { |
| @@ -238,8 +240,8 @@ class PersonCenter extends Component { | @@ -238,8 +240,8 @@ class PersonCenter extends Component { | ||
| 238 | const noticeData = dataReturn[0]; | 240 | const noticeData = dataReturn[0]; |
| 239 | 241 | ||
| 240 | // 3. 再次确认是否已显示(防止并发请求) | 242 | // 3. 再次确认是否已显示(防止并发请求) |
| 241 | - const currentShownNotices = JSON.parse(localStorage.getItem('shownNotices') || '[]'); | ||
| 242 | - console.log('currentShownNotices1', currentShownNotices); | 243 | + const currentShownNotices = localStorage.getItem('shownNotices') || ''; |
| 244 | + console.log('currentShownNotices11', currentShownNotices); | ||
| 243 | if (!currentShownNotices.includes(noticeKey)) { | 245 | if (!currentShownNotices.includes(noticeKey)) { |
| 244 | this.setState({ | 246 | this.setState({ |
| 245 | noticeVisible: true, | 247 | noticeVisible: true, |
| @@ -273,16 +275,9 @@ class PersonCenter extends Component { | @@ -273,16 +275,9 @@ class PersonCenter extends Component { | ||
| 273 | message.success('公告已阅读'); | 275 | message.success('公告已阅读'); |
| 274 | // 在用户确认阅读后,才将公告记录存储到shownNotices中 | 276 | // 在用户确认阅读后,才将公告记录存储到shownNotices中 |
| 275 | const noticeKey = `${sMsgId}_${sMsgSlaveId}`; | 277 | const noticeKey = `${sMsgId}_${sMsgSlaveId}`; |
| 276 | - const currentShownNotices = JSON.parse(localStorage.getItem('shownNotices') || '[]'); | ||
| 277 | - | ||
| 278 | - if (!currentShownNotices.includes(noticeKey)) { | ||
| 279 | - currentShownNotices.push(noticeKey); | ||
| 280 | - // 限制存储最近100条记录,防止localStorage过大 | ||
| 281 | - if (currentShownNotices.length > 100) { | ||
| 282 | - currentShownNotices.shift(); | ||
| 283 | - } | ||
| 284 | - localStorage.setItem('shownNotices', JSON.stringify(currentShownNotices)); | ||
| 285 | - } | 278 | + const currentShownNotices = localStorage.getItem('shownNotices') || ''; |
| 279 | + console.log('noticeKe11111y', noticeKey); | ||
| 280 | + localStorage.setItem('shownNotices', JSON.stringify(noticeKey)); | ||
| 286 | } else { | 281 | } else { |
| 287 | message.error(configReturn?.msg); | 282 | message.error(configReturn?.msg); |
| 288 | } | 283 | } |
| @@ -1141,7 +1136,11 @@ const PersonCenterNotice = Form.create({ | @@ -1141,7 +1136,11 @@ const PersonCenterNotice = Form.create({ | ||
| 1141 | { | 1136 | { |
| 1142 | noticeVisible ? | 1137 | noticeVisible ? |
| 1143 | <AntdDraggableModal | 1138 | <AntdDraggableModal |
| 1144 | - title={NoticeTitle} | 1139 | + title={ |
| 1140 | + <div style={{ textAlign: 'center', width: '100%', fontSize: '18px' }}> | ||
| 1141 | + {NoticeTitle} | ||
| 1142 | + </div> | ||
| 1143 | + } | ||
| 1145 | width={1200} | 1144 | width={1200} |
| 1146 | visible={noticeVisible} | 1145 | visible={noticeVisible} |
| 1147 | onCancel={handleNoticeCancel} | 1146 | onCancel={handleNoticeCancel} |
| @@ -1153,7 +1152,7 @@ const PersonCenterNotice = Form.create({ | @@ -1153,7 +1152,7 @@ const PersonCenterNotice = Form.create({ | ||
| 1153 | display: 'flex', | 1152 | display: 'flex', |
| 1154 | alignItems: 'center', | 1153 | alignItems: 'center', |
| 1155 | width: '100%', | 1154 | width: '100%', |
| 1156 | - justifyContent: 'flex-start', | 1155 | + justifyContent: 'flex-end', |
| 1157 | padding: '0px 24px 16px 16px', | 1156 | padding: '0px 24px 16px 16px', |
| 1158 | margin: '0', // 清除外部默认边距 | 1157 | margin: '0', // 清除外部默认边距 |
| 1159 | }} | 1158 | }} |