king
8 天以前 a1e9b18a4dbfd21e1bf4d5cb60974ac2f0115efd
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import MKEmitter from '@/utils/events.js'
 
class Iframe extends Component {
  static propTypes = {
    title: PropTypes.string,
    MenuID: PropTypes.string,    // 菜单Id
    url: PropTypes.string
  }
 
  state = {
    visible: true
  }
 
  componentDidMount () {
    MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
  }
 
  reloadMenuView = (menuId) => {
    const { MenuID } = this.props
 
    if (MenuID !== menuId) return
 
    this.setState({visible: false}, () => {
      this.setState({visible: true})
    })
  }
 
  render () {
    const { visible } = this.state
    
    return (<div>
      {visible ? <iframe title={this.props.title} src={this.props.url} /> : null}
    </div>)
  }
}
 
export default Iframe