| | |
| | | } |
| | | |
| | | componentDidMount () { |
| | | sessionStorage.setItem('style-control', 'false') |
| | | MKEmitter.addListener('clickComponent', this.clickComponent) |
| | | MKEmitter.addListener('submitCombineStyle', this.submitCombineStyle) |
| | | } |
| | |
| | | } |
| | | |
| | | submitCombineStyle = (style) => { |
| | | const { components } = this.state |
| | | const { menu } = this.props |
| | | const { components, parent } = this.state |
| | | |
| | | components.forEach((item, i) => { |
| | | setTimeout(() => { |
| | | MKEmitter.emit('submitStyle', [item.uuid], {...item.style, ...style}) |
| | | }, i * 5) |
| | | let _parent = null |
| | | let getParents = (box) => { |
| | | box.components.forEach(item => { |
| | | if (item.type === 'tabs') { |
| | | item.subtabs.forEach(tab => { |
| | | if (tab.uuid === parent.uuid) { |
| | | _parent = tab |
| | | } else { |
| | | getParents(tab) |
| | | } |
| | | }) |
| | | } else if (item.type === 'group') { |
| | | if (item.uuid === parent.uuid) { |
| | | _parent = item |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | |
| | | if (menu.uuid === parent.uuid) { |
| | | _parent = menu |
| | | } else { |
| | | getParents(menu) |
| | | } |
| | | |
| | | let keys = components.map(item => item.uuid) |
| | | |
| | | _parent.components = _parent.components.map(item => { |
| | | if (keys.includes(item.uuid)) { |
| | | item.style = {...item.style, ...style} |
| | | } |
| | | return item |
| | | }) |
| | | |
| | | MKEmitter.emit('submitComponentStyle', _parent) |
| | | |
| | | setTimeout(() => { |
| | | keys.forEach(key => { |
| | | document.getElementById(key).classList.add('selected-control-element') |
| | | }) |
| | | }, 100) |
| | | } |
| | | |
| | | clickComponent = (card) => { |
| | |
| | | document.getElementById(card.uuid).classList.add('selected-control-element') |
| | | } |
| | | |
| | | if (components.length === 0) { |
| | | MKEmitter.emit('closeCombineStyle') |
| | | } |
| | | |
| | | this.setState({ |
| | | components: components, |
| | | parent: components.length ? parent : null |