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()
|
})
|
}
|
|
handleBack = () => {
|
this.setState({
|
visible: false,
|
config: null,
|
btn: null
|
})
|
}
|
|
handleSave = (modal) => {
|
const { config, btn } = this.state
|
MKEmitter.emit('submitModal', config, btn, modal)
|
|
this.setState({
|
visible: false,
|
config: null,
|
btn: null
|
})
|
}
|
|
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
|