1- import { Button , ConfigProvider , Modal , notification , } from 'antd' ;
2- import React from 'react'
1+ import React , { useCallback , useEffect , useState } from 'react'
2+ import { Button , ConfigProvider , Modal , notification , Space } from 'antd' ;
33import styles from './index.less'
44import i18n from '@/i18n' ;
55import { IconType } from 'antd/es/notification/interface' ;
6- // import { staticNotification } from '@/layouts'
6+ import Iconfont from '../Iconfont' ;
77
88interface IProps {
99 type ?: IconType ;
@@ -18,33 +18,68 @@ interface IProps {
1818 solutionLink : string ;
1919}
2020
21- function MyNotification ( props : IProps ) {
22- const { errorCode, errorMessage, errorDetail, solutionLink } = props ;
21+ function MyNotification ( ) {
22+ const [ notificationApi , notificationDom ] = notification . useNotification ( {
23+ maxCount : 2
24+ } ) ;
25+ const [ open , setOpen ] = useState ( false ) ;
26+ const [ props , setProps ] = useState < IProps > ( )
2327
24- const type = props . type || 'warning' ;
25- const title = `${ errorCode } :${ errorMessage } ` ;
26- const message = props . message || < div className = { styles . message } > { errorCode } :{ errorMessage || 'Error' } </ div >
28+ window . _notificationApi = useCallback ( ( props : IProps ) => {
29+ const { errorCode, errorMessage, errorDetail, solutionLink } = props ;
30+ setProps ( props ) ;
31+ const btn = (
32+ < Space >
33+ < Button type = "link" size = "small" onClick = { ( ) => {
34+ setOpen ( true ) ;
35+ } } >
36+ { i18n ( 'common.notification.detial' ) }
37+ </ Button >
38+ < Button type = "link" size = "small" target = '_blank' href = { solutionLink } >
39+ { i18n ( 'common.notification.solution' ) }
40+ </ Button >
41+ </ Space >
42+ ) ;
2743
28- const description = < div className = { styles . description } >
29- < Button style = { { 'marginRight' : '8px' } } type = 'link' onClick = { ( ) => {
30- Modal . info ( {
31- width : 620 ,
32- title,
33- content : errorDetail
34- } )
35- } } > { i18n ( 'common.notification.detial' ) } </ Button >
36- < Button type = 'link' target = '_blank' href = { solutionLink } > { i18n ( 'common.notification.solution' ) } </ Button >
37- </ div >
44+ const renderDescription = ( ) => {
45+ return < div className = { styles . description } >
46+ { props . errorCode } { props . errorCode } { props . errorCode } { props . errorCode }
47+ </ div >
48+ }
3849
50+ const renderMessage = ( ) => {
51+ return < div className = { styles . message } >
52+ < Iconfont code = '' />
53+ Error
54+ </ div >
55+ }
3956
40- return notification . open ( {
41- ...props ,
42- type,
43- message,
44- description,
45- } )
57+ notificationApi . open ( {
58+ className : styles . notification ,
59+ message : renderMessage ( ) ,
60+ description : renderDescription ( ) ,
61+ placement : 'bottomRight' ,
62+ btn,
63+ duration : null ,
64+ } )
65+ } , [ ] )
4666
4767
68+ return < >
69+ { notificationDom }
70+ < Modal
71+ className = { styles . modal }
72+ open = { open }
73+ title = { props ?. errorCode }
74+ width = '70vw'
75+ footer = { [ ] }
76+ onCancel = { ( ) => {
77+ setOpen ( false )
78+ } }
79+ >
80+ { props ?. errorDetail }
81+ </ Modal >
82+ </ >
4883}
4984
5085export default MyNotification ;
0 commit comments