king
2021-10-08 d6dfba48678e1107a9e7c6524e1dfa2d3fdff03c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Button, message } from 'antd'
import MKEmitter from '@/utils/events.js'
import mzhCN from '@/locales/zh-CN/main.js'
import menUS from '@/locales/en-US/main.js'
 
class Iframe extends Component {
  static propTypes = {
    title: PropTypes.string,
    MenuID: PropTypes.string,    // 菜单Id
    MenuNo: PropTypes.string,    // 菜单参数
    url: PropTypes.string
  }
 
  state = {
    visible: true,
    dict: sessionStorage.getItem('lang') !== 'en-US' ? mzhCN : menUS,
    debug: sessionStorage.getItem('debug') === '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})
    })
  }
 
  copyMenuNo = (e) => {
    const { MenuNo } = this.props
 
    e.stopPropagation()
    let oInput = document.createElement('input')
    oInput.value = MenuNo || ''
    document.body.appendChild(oInput)
    oInput.select()
    document.execCommand('Copy')
    oInput.className = 'oInput'
    oInput.style.display = 'none'
    message.success(this.state.dict['main.copy.success'])
  }
 
  render () {
    const { visible, debug } = this.state
    
    return (<div>
      {visible ? <iframe title={this.props.title} src={this.props.url} /> : null}
      {debug ? <Button
        icon="copy"
        shape="circle"
        className={'main-copy ifr-copy'}
        onClick={this.copyMenuNo}
      /> : null}
    </div>)
  }
}
 
export default Iframe