import React , { Component } from 'react' ; import { Button } from 'antd' ; import { MenuButtonAsyncAPI } from '@/services/menu' ; import { history } from 'umi' ; let button = [ ] ; interface IButtonBar { getFun : ( ) => void ; } class ButtonBar extends Component < IButtonBar > { constructor ( props ) { super ( props ) ; const menustr = window . localStorage . getItem ( 'menulist' ) ; const menu = menustr ? JSON . parse ( menustr ) : [ ] ; this . temp ( menu ) ; } private temp = async ( menu ) => { if ( menu . length > 0 ) { let index = menu . findIndex ( ( x ) => x . routerPath == history . location . pathname . substr ( 1 ) ) ; if ( index >= 0 ) { let model = menu [ index ] ; let buttonss = await MenuButtonAsyncAPI ( { menuid : model . id } ) ; const { data } = buttonss ; button = data ; } } } ; itemclick : any ; btnClick = ( record ) => { this . itemclick = record ; this . props . getFun ( ) ; } ; render ( ) { return ( < div style = { { margin : 10 } } > { button . map ( item => { return ( < Button style = { { marginRight : 10 , marginBottom : 5 } } key = { item . path } type = { item . icon } onClick = { ( ) => { this . btnClick ( item . path ) ; } } > { item . name } < /Button>); } ) } < /div>); } } export default ButtonBar ;