@@ -6,89 +6,89 @@ import { marked } from 'marked';
66import { IllustrationNoContent , IllustrationNoContentDark } from '@douyinfe/semi-illustrations' ;
77
88const NoticeModal = ( { visible, onClose, isMobile } ) => {
9- const { t } = useTranslation ( ) ;
10- const [ noticeContent , setNoticeContent ] = useState ( '' ) ;
11- const [ loading , setLoading ] = useState ( false ) ;
9+ const { t } = useTranslation ( ) ;
10+ const [ noticeContent , setNoticeContent ] = useState ( '' ) ;
11+ const [ loading , setLoading ] = useState ( false ) ;
1212
13- const handleCloseTodayNotice = ( ) => {
14- const today = new Date ( ) . toDateString ( ) ;
15- localStorage . setItem ( 'notice_close_date' , today ) ;
16- onClose ( ) ;
17- } ;
13+ const handleCloseTodayNotice = ( ) => {
14+ const today = new Date ( ) . toDateString ( ) ;
15+ localStorage . setItem ( 'notice_close_date' , today ) ;
16+ onClose ( ) ;
17+ } ;
1818
19- const displayNotice = async ( ) => {
20- setLoading ( true ) ;
21- try {
22- const res = await API . get ( '/api/notice' ) ;
23- const { success, message, data } = res . data ;
24- if ( success ) {
25- if ( data !== '' ) {
26- const htmlNotice = marked . parse ( data ) ;
27- setNoticeContent ( htmlNotice ) ;
28- } else {
29- setNoticeContent ( '' ) ;
30- }
31- } else {
32- showError ( message ) ;
33- }
34- } catch ( error ) {
35- showError ( error . message ) ;
36- } finally {
37- setLoading ( false ) ;
19+ const displayNotice = async ( ) => {
20+ setLoading ( true ) ;
21+ try {
22+ const res = await API . get ( '/api/notice' ) ;
23+ const { success, message, data } = res . data ;
24+ if ( success ) {
25+ if ( data !== '' ) {
26+ const htmlNotice = marked . parse ( data ) ;
27+ setNoticeContent ( htmlNotice ) ;
28+ } else {
29+ setNoticeContent ( '' ) ;
3830 }
39- } ;
31+ } else {
32+ showError ( message ) ;
33+ }
34+ } catch ( error ) {
35+ showError ( error . message ) ;
36+ } finally {
37+ setLoading ( false ) ;
38+ }
39+ } ;
4040
41- useEffect ( ( ) => {
42- if ( visible ) {
43- displayNotice ( ) ;
44- }
45- } , [ visible ] ) ;
41+ useEffect ( ( ) => {
42+ if ( visible ) {
43+ displayNotice ( ) ;
44+ }
45+ } , [ visible ] ) ;
4646
47- const renderContent = ( ) => {
48- if ( loading ) {
49- return < div className = "py-12" > < Empty description = { t ( '加载中...' ) } /> </ div > ;
50- }
47+ const renderContent = ( ) => {
48+ if ( loading ) {
49+ return < div className = "py-12" > < Empty description = { t ( '加载中...' ) } /> </ div > ;
50+ }
5151
52- if ( ! noticeContent ) {
53- return (
54- < div className = "py-12" >
55- < Empty
56- image = { < IllustrationNoContent style = { { width : 150 , height : 150 } } /> }
57- darkModeImage = { < IllustrationNoContentDark style = { { width : 150 , height : 150 } } /> }
58- description = { t ( '暂无公告' ) }
59- />
60- </ div >
61- ) ;
62- }
63-
64- return (
65- < div
66- dangerouslySetInnerHTML = { { __html : noticeContent } }
67- className = "max-h-[60vh] overflow-y-auto pr-2"
68- style = { {
69- scrollbarWidth : 'thin' ,
70- scrollbarColor : 'var(--semi-color-tertiary) transparent'
71- } }
72- />
73- ) ;
74- } ;
52+ if ( ! noticeContent ) {
53+ return (
54+ < div className = "py-12" >
55+ < Empty
56+ image = { < IllustrationNoContent style = { { width : 150 , height : 150 } } /> }
57+ darkModeImage = { < IllustrationNoContentDark style = { { width : 150 , height : 150 } } /> }
58+ description = { t ( '暂无公告' ) }
59+ />
60+ </ div >
61+ ) ;
62+ }
7563
7664 return (
77- < Modal
78- title = { t ( '系统公告' ) }
79- visible = { visible }
80- onCancel = { onClose }
81- footer = { (
82- < div className = "flex justify-end" >
83- < Button type = 'secondary' className = '!rounded-full' onClick = { handleCloseTodayNotice } > { t ( '今日关闭' ) } </ Button >
84- < Button type = "primary" className = '!rounded-full' onClick = { onClose } > { t ( '关闭公告' ) } </ Button >
85- </ div >
86- ) }
87- size = { isMobile ? 'full-width' : 'large' }
88- >
89- { renderContent ( ) }
90- </ Modal >
65+ < div
66+ dangerouslySetInnerHTML = { { __html : noticeContent } }
67+ className = "max-h-[60vh] overflow-y-auto pr-2"
68+ style = { {
69+ scrollbarWidth : 'thin' ,
70+ scrollbarColor : 'var(--semi-color-tertiary) transparent'
71+ } }
72+ />
9173 ) ;
74+ } ;
75+
76+ return (
77+ < Modal
78+ title = { t ( '系统公告' ) }
79+ visible = { visible }
80+ onCancel = { onClose }
81+ footer = { (
82+ < div className = "flex justify-end" >
83+ < Button type = 'secondary' className = '!rounded-full' onClick = { handleCloseTodayNotice } > { t ( '今日关闭' ) } </ Button >
84+ < Button type = "primary" className = '!rounded-full' onClick = { onClose } > { t ( '关闭公告' ) } </ Button >
85+ </ div >
86+ ) }
87+ size = { isMobile ? 'full-width' : 'large' }
88+ >
89+ { renderContent ( ) }
90+ </ Modal >
91+ ) ;
9292} ;
9393
9494export default NoticeModal ;
0 commit comments