king
2021-01-07 0da0262bc236cfce928429fc4c48e1666eab3402
src/menu/stylecombcontrolbutton/index.jsx
@@ -14,6 +14,7 @@
  state = {
    label: '调整',
    parent: null,
    type: '',
    components: []
  }
@@ -35,44 +36,11 @@
  }
  submitCombineStyle = (style) => {
    const { menu } = this.props
    const { components, parent } = this.state
    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)
    MKEmitter.emit('submitComponentStyle', parent.uuid, keys, style)
    setTimeout(() => {
      keys.forEach(key => {
@@ -81,41 +49,54 @@
    }, 100)
  }
  clickComponent = (card) => {
  clickComponent = (card, _p, _type) => {
    const { menu } = this.props
    const { parent } = this.state
    const { parent, type } = this.state
    let components = fromJS(this.state.components).toJS()
    if (!parent) {
      let _parent = null
      let getParents = (box) => {
        box.components.forEach(item => {
          if (item.type === 'tabs') {
            item.subtabs.forEach(tab => {
              if (tab.components.findIndex(cell => cell.uuid === card.uuid) > -1) {
                _parent = tab
              } else {
                getParents(tab)
              }
            })
          } else if (item.type === 'group') {
            if (item.components.findIndex(cell => cell.uuid === card.uuid) > -1) {
              _parent = item
            }
          }
        })
      }
      if (menu.components.findIndex(cell => cell.uuid === card.uuid) > -1) {
        _parent = menu
      if (_type === 'propcard') {
        _parent = _p
        MKEmitter.emit('changeCombineStyle', ['margin', 'padding', 'border', 'background', 'shadow'])
      } else if (_type === 'cardcell') {
        _parent = _p
        MKEmitter.emit('changeCombineStyle', ['margin', 'padding', 'border', 'background', 'font'])
      } else {
        getParents(menu)
        let getParents = (box) => {
          box.components.forEach(item => {
            if (item.type === 'tabs') {
              item.subtabs.forEach(tab => {
                if (tab.components.findIndex(cell => cell.uuid === card.uuid) > -1) {
                  _parent = tab
                } else {
                  getParents(tab)
                }
              })
            } else if (item.type === 'group') {
              if (item.components.findIndex(cell => cell.uuid === card.uuid) > -1) {
                _parent = item
              }
            }
          })
        }
        if (menu.components.findIndex(cell => cell.uuid === card.uuid) > -1) {
          _parent = menu
        } else {
          getParents(menu)
        }
        MKEmitter.emit('changeCombineStyle', ['margin', 'padding', 'border', 'background'])
      }
      document.getElementById(card.uuid).classList.add('selected-control-element')
      MKEmitter.emit('changeCombineStyle', ['margin', 'padding', 'border', 'background'])
      sessionStorage.setItem('style-control', (_type ? _type : 'component'))
      this.setState({
        type: _type ? _type : 'component',
        parent: _parent,
        components: [card]
      })
@@ -123,13 +104,17 @@
      if (components.findIndex(cell => cell.uuid === card.uuid) > -1) {
        components = components.filter(cell => cell.uuid !== card.uuid)
        document.getElementById(card.uuid).classList.remove('selected-control-element')
      } else if (parent.components.findIndex(cell => cell.uuid === card.uuid) > -1) {
      } else if (type !== 'propcard' && parent.components.findIndex(cell => cell.uuid === card.uuid) > -1) {
        components.push(card)
        document.getElementById(card.uuid).classList.add('selected-control-element')
      } else if (type === 'propcard' && parent.subcards.findIndex(cell => cell.uuid === card.uuid) > -1) {
        components.push(card)
        document.getElementById(card.uuid).classList.add('selected-control-element')
      }
      if (components.length === 0) {
        MKEmitter.emit('closeCombineStyle')
        sessionStorage.setItem('style-control', 'true')
      }
      this.setState({
@@ -140,7 +125,7 @@
  }
  triggerStyleChange = () => {
    const { label } = this.state
    const { label, components } = this.state
    if (label === '调整') {
      document.body.className = 'style-control'
@@ -150,10 +135,9 @@
      document.body.className = ''
      sessionStorage.setItem('style-control', 'false')
      let eles = document.getElementsByClassName('selected-control-element')
      for (let i = 0; i < eles.length; i++) {
        eles[i].classList.remove('selected-control-element')
      }
      components.forEach(item => {
        document.getElementById(item.uuid).classList.remove('selected-control-element')
      })
      MKEmitter.emit('closeCombineStyle')