import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Modal } from 'antd'
|
import { ForkOutlined } from '@ant-design/icons'
|
|
import MenusForm from './menus'
|
import './index.scss'
|
|
class NodesWrap extends Component {
|
static propTpyes = {
|
card: PropTypes.object,
|
updateMenus: PropTypes.func
|
}
|
|
state = {
|
visible: false,
|
supNodes: [],
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
trigger = () => {
|
const { card } = this.props
|
|
this.setState({
|
visible: true,
|
supNodes: card.supNodes || []
|
})
|
}
|
|
submit = () => {
|
this.setState({
|
visible: false
|
})
|
this.props.updateMenus(this.state.supNodes)
|
}
|
|
update = (supNodes) => {
|
this.setState({supNodes})
|
}
|
|
render() {
|
const { card } = this.props
|
const { visible, supNodes } = this.state
|
|
return (
|
<>
|
<ForkOutlined title="上级组件" style={{color: 'orange'}} onClick={this.trigger}/>
|
<Modal
|
title="上级组件"
|
wrapClassName="menus-field-modal"
|
visible={visible}
|
width={700}
|
maskClosable={false}
|
onOk={this.submit}
|
onCancel={() => { this.setState({ visible: false })}}
|
destroyOnClose
|
>
|
<MenusForm supNodes={supNodes} card={card} update={this.update}/>
|
</Modal>
|
</>
|
)
|
}
|
}
|
|
export default NodesWrap
|