king
2022-08-07 94f09287d3424f96a6d60ac67b9bf4ac58455e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React, {Component} from 'react'
import { Spin } 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})
    }
 
    render() {
      const C = this.state.component
 
      return C ?
        <C {...this.props} /> :
        <Spin style={{position: 'fixed', left: 'calc(50vw - 22px)', top: 'calc(50vh - 70px)', zIndex: 10}} size="large" />
    }
  }
}