import { message } from 'antd' ; import './styles.css' ; type ITypes = 'error' | 'success' | 'fail' | 'warning' ; type NotiInstance = { [ x in ITypes ] ? : ( arg : Props ) => void ; } ; const Notification = { } ; const setInstance = ( ) => { [ 'error' , 'fail' , 'warning' , 'success' ] . forEach ( ( _type_ ) => { const key = _type_ ; Notification [ _type_ ] = ( args ) => Component ( args , key ) ; } ) ; } ; setInstance ( ) ; interface Props { position ? : string ; msg ? : string ; duration ? : number ; } message . config ( { top : window . innerHeight / 3 , } ) ; const Component = ( props , _type_ ) => { const { msg = '通知' } = props ; message . destroy ( ) ; message [ _type_ === 'fail' ? 'error' : _type_ ] ( msg ) ; } ; export default Notification ;