import { BaseModel , dvaModel , reducer , subscription } from 'utils/dva' ; import { IBreadCrumbItem } from 'config/interface' ; import { SubscriptionAPI } from 'dva' ; import PageHeaderExtra from 'components/PageHeaderExtra' ; import React from 'react' ; interface IPageHeaderState { breadcrumbItems ? : IBreadCrumbItem [ ] ; breadcrumbExtra ? : React . ReactNode ; headerExtra ? : React . ReactNode ; title ? : string | React . ReactNode ; subTitle ? : string | React . ReactNode ; hasBackArrow ? : boolean ; showHeader ? : boolean ; } @ dvaModel ( 'pageHeader' ) class PageHeader extends BaseModel { state : IPageHeaderState = { breadcrumbExtra : PageHeaderExtra , } ; @ subscription whenLocationChange ( { dispatch , history } ) { history . listen ( ( ) => { dispatch ( this . showBackArrow ( false ) ) ; dispatch ( this . setHeaderExtra ( false ) ) ; } ) ; } @ reducer showBackArrow ( hasBackArrow ) { return { ... this . state , hasBackArrow , } ; } @ reducer setBreadCrumbItems ( breadcrumbItems ) { return { ... this . state , breadcrumbItems , } ; } @ reducer setBreadCrumbExtra ( breadcrumbExtra ) { return { ... this . state , breadcrumbExtra , } ; } @ reducer setTitle ( title ) { return { ... this . state , title , } ; } @ reducer setSubTitle ( subTitle ) { return { ... this . state , subTitle , } ; } @ reducer setHeaderExtra ( headerExtra ) { return { ... this . state , headerExtra , } ; } } export default new PageHeader ( ) . model ; declare global { interface Actions { pageHeader : PageHeader ; } }