king
2023-07-16 1f5c6ac307a134dfa45b64c5723f2481ead9f213
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
import React, {Component} from 'react'
import { is, fromJS } from 'immutable'
 
import MKEmitter from '@/utils/events.js'
import ModalConfig from '@/menu/modalconfig'
 
class ModalController extends Component {
  state = {
    btn: null,
    config: null,
    visible: false
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  componentDidMount () {
    MKEmitter.addListener('changeModal', this.initConfig)
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('changeModal', this.initConfig)
  }
 
  initConfig = (config, btn) => {
    this.setState({
      visible: true,
      config: fromJS(config).toJS(),
      btn: fromJS(btn).toJS()
    })
 
    window.GLOB.formId = ''
  }
 
  handleBack = () => {
    this.setState({
      visible: false,
      config: null,
      btn: null
    })
  }
  
  handleSave = (modal) => {
    const { config, btn } = this.state
    MKEmitter.emit('submitModal', config.uuid, btn.uuid, modal)
  }
 
  render () {
    const { config, btn, visible } = this.state
 
    if (!visible) return null
 
    return (
      <ModalConfig btn={btn} componentConfig={config} handleBack={this.handleBack} handleSave={this.handleSave}/>
    )
  }
}
 
export default ModalController