import React, {Component} from 'react'
|
import { Button } from 'antd'
|
|
/**
|
* @description 异步加载模块
|
* @param {*} importComponent
|
*/
|
export default function asyncComponent(importComponent) {
|
return class extends Component {
|
constructor(props) {
|
super(props)
|
|
this.state = {
|
component: null
|
}
|
}
|
|
async componentDidMount() {
|
const {default: component} = await importComponent()
|
|
this.setState({component})
|
}
|
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
render() {
|
const C = this.state.component
|
const btn = this.props.btn || {}
|
let style = {}
|
|
if (!C && btn.style) {
|
style.marginRight = btn.style.marginRight || ''
|
style.marginLeft = btn.style.marginLeft || ''
|
style.marginTop = btn.style.marginTop || ''
|
style.marginBottom = btn.style.marginBottom || ''
|
}
|
|
return C ?
|
<C {...this.props} /> :
|
<Button className={'mk-btn mk-' + btn.class} style={style} icon={btn.icon} disabled={true} >{btn.label}</Button>
|
}
|
}
|
}
|