import React, {Component} from 'react'
|
import { is, fromJS } from 'immutable'
|
|
import MKEmitter from '@/utils/events.js'
|
import SearchConfig from '@/mob/searchconfig'
|
|
class SearchController extends Component {
|
state = {
|
config: null,
|
visible: false
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('changeSearch', this.initConfig)
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('changeSearch', this.initConfig)
|
}
|
|
initConfig = (config) => {
|
this.setState({
|
visible: true,
|
config: fromJS(config).toJS()
|
})
|
}
|
|
handleBack = () => {
|
this.setState({
|
visible: false,
|
config: null
|
})
|
}
|
|
handleSave = (search) => {
|
const { config } = this.state
|
|
MKEmitter.emit('submitSearch', {...config, search})
|
}
|
|
render () {
|
const { config, visible } = this.state
|
|
if (!visible) return null
|
|
return (
|
<SearchConfig config={config.search} handleBack={this.handleBack} handleSave={this.handleSave}/>
|
)
|
}
|
}
|
|
export default SearchController
|