diff --git a/web/src/components/layout/NoticeModal.js b/web/src/components/layout/NoticeModal.js index 626d8d17..9bb062a1 100644 --- a/web/src/components/layout/NoticeModal.js +++ b/web/src/components/layout/NoticeModal.js @@ -6,89 +6,89 @@ import { marked } from 'marked'; import { IllustrationNoContent, IllustrationNoContentDark } from '@douyinfe/semi-illustrations'; const NoticeModal = ({ visible, onClose, isMobile }) => { - const { t } = useTranslation(); - const [noticeContent, setNoticeContent] = useState(''); - const [loading, setLoading] = useState(false); + const { t } = useTranslation(); + const [noticeContent, setNoticeContent] = useState(''); + const [loading, setLoading] = useState(false); - const handleCloseTodayNotice = () => { - const today = new Date().toDateString(); - localStorage.setItem('notice_close_date', today); - onClose(); - }; + const handleCloseTodayNotice = () => { + const today = new Date().toDateString(); + localStorage.setItem('notice_close_date', today); + onClose(); + }; - const displayNotice = async () => { - setLoading(true); - try { - const res = await API.get('/api/notice'); - const { success, message, data } = res.data; - if (success) { - if (data !== '') { - const htmlNotice = marked.parse(data); - setNoticeContent(htmlNotice); - } else { - setNoticeContent(''); - } - } else { - showError(message); - } - } catch (error) { - showError(error.message); - } finally { - setLoading(false); + const displayNotice = async () => { + setLoading(true); + try { + const res = await API.get('/api/notice'); + const { success, message, data } = res.data; + if (success) { + if (data !== '') { + const htmlNotice = marked.parse(data); + setNoticeContent(htmlNotice); + } else { + setNoticeContent(''); } - }; + } else { + showError(message); + } + } catch (error) { + showError(error.message); + } finally { + setLoading(false); + } + }; - useEffect(() => { - if (visible) { - displayNotice(); - } - }, [visible]); + useEffect(() => { + if (visible) { + displayNotice(); + } + }, [visible]); - const renderContent = () => { - if (loading) { - return
; - } + const renderContent = () => { + if (loading) { + return
; + } - if (!noticeContent) { - return ( -
- } - darkModeImage={} - description={t('暂无公告')} - /> -
- ); - } - - return ( -
- ); - }; + if (!noticeContent) { + return ( +
+ } + darkModeImage={} + description={t('暂无公告')} + /> +
+ ); + } return ( - - - -
- )} - size={isMobile ? 'full-width' : 'large'} - > - {renderContent()} - +
); + }; + + return ( + + + +
+ )} + size={isMobile ? 'full-width' : 'large'} + > + {renderContent()} + + ); }; export default NoticeModal; \ No newline at end of file diff --git a/web/src/pages/Home/index.js b/web/src/pages/Home/index.js index 4df3120c..36fb8213 100644 --- a/web/src/pages/Home/index.js +++ b/web/src/pages/Home/index.js @@ -22,11 +22,23 @@ const Home = () => { const isDemoSiteMode = statusState?.status?.demo_site_enabled || false; useEffect(() => { - const lastCloseDate = localStorage.getItem('notice_close_date'); - const today = new Date().toDateString(); - if (lastCloseDate !== today) { - setNoticeVisible(true); - } + const checkNoticeAndShow = async () => { + const lastCloseDate = localStorage.getItem('notice_close_date'); + const today = new Date().toDateString(); + if (lastCloseDate !== today) { + try { + const res = await API.get('/api/notice'); + const { success, data } = res.data; + if (success && data && data.trim() !== '') { + setNoticeVisible(true); + } + } catch (error) { + console.error('获取公告失败:', error); + } + } + }; + + checkNoticeAndShow(); }, []); const displayHomePageContent = async () => {