king
2021-01-07 0a0372f158b7a4c786c67be6a6e3c84ff7608904
src/menu/stylecombcontrolbutton/index.jsx
@@ -18,6 +18,7 @@
  }
  componentDidMount () {
    sessionStorage.setItem('style-control', 'false')
    MKEmitter.addListener('clickComponent', this.clickComponent)
    MKEmitter.addListener('submitCombineStyle', this.submitCombineStyle)
  }
@@ -34,13 +35,50 @@
  }
  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) => {
@@ -90,6 +128,10 @@
        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