king
2023-12-12 49f09cc6f8ff8c30a75ed1a9d6f510b69b73962a
src/menu/components/card/doublecardcomponent/index.jsx
@@ -2,7 +2,7 @@
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Popover, Col } from 'antd'
import { PlusOutlined, PlusSquareOutlined, EditOutlined, ToolOutlined, FontColorsOutlined } from '@ant-design/icons'
import { UpOutlined, PlusOutlined, PlusSquareOutlined, EditOutlined, ToolOutlined, FontColorsOutlined } from '@ant-design/icons'
import asyncComponent from '@/utils/asyncComponent'
import asyncIconComponent from '@/utils/asyncIconComponent'
@@ -27,7 +27,8 @@
  state = {
    card: null,            // 卡片信息,包括正反面
    appType: sessionStorage.getItem('appType'),
    visible: false
    visible: false,
    side: ''
  }
  /**
@@ -60,7 +61,7 @@
    const { card, side } = this.state
    let _card = fromJS(card).toJS()
    if (side === 'back') {
    if (side === 'sub') {
      _card.backStyle = style
    } else {
      _card.style = style
@@ -73,12 +74,12 @@
    this.props.updateElement(_card)
  }
  updateCard = (elements, btn) => {
    const { card, side } = this.state
  updateCard = (elements, btn, type) => {
    const { card } = this.state
    let _card = {}
    if (side === 'back') {
    if (type === 'sub') {
      _card = {...card, backElements: elements}
    } else {
      _card = {...card, elements: elements}
@@ -90,29 +91,8 @@
    this.props.updateElement(_card, btn)
  }
  changeSide = () => {
    const { card } = this.props
    const { side } = this.state
    let _side = ''
    let _elements = null
    if (side === 'front') {
      _side = 'back'
    } else {
      _side = 'front'
    }
    if (_side === 'front') {
      _elements = fromJS(card.elements).toJS()
    } else {
      _elements = fromJS(card.backElements).toJS()
    }
    this.setState({side: _side, elements: _elements})
  }
  
  addElement = () => {
  addElement = (type) => {
    const { card } = this.state
    let newcard = {}
@@ -124,10 +104,10 @@
    newcard.height = 1
    // 注册事件-添加元素
    MKEmitter.emit('cardAddElement', card.uuid, newcard)
    MKEmitter.emit('cardAddElement', card.uuid, newcard, type)
  }
  addButton = () => {
  addButton = (type) => {
    const { card } = this.state
    let newcard = {eleType: 'button', label: 'button', verify: null, show: 'link', sqlType: '', Ot: 'requiredSgl', OpenType: 'prompt', icon: '', class: 'primary', intertype: 'system', execSuccess: 'grid', execError: 'never', popClose: 'never'}
@@ -135,30 +115,33 @@
    newcard.focus = true
    // 注册事件-添加元素
    MKEmitter.emit('cardAddElement', card.uuid, newcard)
    MKEmitter.emit('cardAddElement', card.uuid, newcard, type)
  }
  changeStyle = () => {
    const { card, side } = this.state
  changeStyle = (type) => {
    const { card } = this.state
    let _style = null
    let options = ['height', 'background', 'border', 'padding', 'margin', 'shadow']
    if (side === 'front') {
      _style = card.style ? fromJS(card.style).toJS() : {}
    } else if (side === 'back') {
      _style = card.backStyle ? fromJS(card.backStyle).toJS() : {}
      options = ['background', 'padding']
    let options = ['height', 'background', 'border', 'padding', 'margin', 'shadow', 'overflow']
    if (type === 'sub') {
      _style = fromJS(card.backStyle).toJS()
    } else {
      options.push('clear')
      _style = fromJS(card.style).toJS()
    }
    this.setState({side: type})
    MKEmitter.emit('changeStyle', options, _style, this.getStyle)
  }
  getSettingForms = () => {
    const { cards } = this.props
    const { card, appType } = this.state
    const { card } = this.state
    let buttons = []
    card.elements && card.elements.forEach(item => {
    card.elements.forEach(item => {
      if (item.eleType === 'button') {
        buttons.push({
          value: item.uuid,
@@ -166,21 +149,29 @@
        })
      }
    })
    if (appType !== 'mob' && card.backElements) {
      card.backElements.forEach(item => {
        if (item.eleType === 'button') {
          buttons.push({
            value: item.uuid,
            label: item.label
          })
        }
      })
    }
    return getSettingForm(card.setting, cards.subtype, buttons, card.$cardType, cards.columns)
    return getSettingForm(card.setting, buttons, cards.columns, 'main')
  }
  updateSetting = (res) => {
    const { card, side, appType } = this.state
  getBackSettingForms = () => {
    const { cards } = this.props
    const { card } = this.state
    let buttons = []
    card.backElements.forEach(item => {
      if (item.eleType === 'button') {
        buttons.push({
          value: item.uuid,
          label: item.label
        })
      }
    })
    return getSettingForm(card.backSetting, buttons, cards.subColumns)
  }
  updateSetting = (res, type) => {
    const { card, appType } = this.state
    if (appType === '' && res.menu) {
      let list = null
@@ -202,23 +193,22 @@
      })
    }
    let _card = {...card, setting: res}
    let _card = {...card}
    if (type === 'sub') {
      _card.backSetting = res
    } else {
      _card.setting = res
    }
    this.setState({
      card: _card
    })
    if (side === 'back' && res.type === 'simple') {
      this.setState({
        side: 'front',
        elements: fromJS(_card.elements).toJS()
      })
    }
    this.props.updateElement(_card)
  }
  paste = (element, resolve) => {
  paste = (element, resolve, type) => {
    const { card } = this.state
    let _uuid = Utils.getuuid()
@@ -233,14 +223,16 @@
    resolve({status: true})
    // 注册事件-添加元素
    MKEmitter.emit('cardAddElement', card.uuid, element)
    MKEmitter.emit('cardAddElement', card.uuid, element, type)
  }
  doubleClickCard = () => {
  doubleClickCard = (type) => {
    const { card } = this.state
    if (card.setting.click === 'menu' && card.setting.menu) {
    if (type !== 'sub' && card.setting.click === 'menu' && card.setting.menu) {
      MKEmitter.emit('changeEditMenu', {MenuID: card.setting.menu})
    } else if (type === 'sub' && card.backSetting.click === 'menu' && card.backSetting.menu) {
      MKEmitter.emit('changeEditMenu', {MenuID: card.backSetting.menu})
    }
  }
@@ -250,55 +242,82 @@
    let _style = {...card.style}
    let _backStyle = {...card.backStyle}
    _backStyle.marginLeft = _style.marginLeft
    _backStyle.marginRight = _style.marginRight
    _backStyle.marginBottom = _style.marginBottom
    delete _style.marginBottom
    let _wrapStyle = {}
    _style = resetStyle(_style)
    _backStyle = resetStyle(_backStyle)
    if (card.setting.position === 'inner') {
      Object.keys(_style).forEach(key => {
        if (!/^(margin|border|box)/.test(key)) return
        _wrapStyle[key] = _style[key]
        delete _style[key]
      })
    }
    let checkAll = ''
    let mainBox = ''
    if (cards.wrap.selStyle === 'check') {
      checkAll = 'mk-checkable'
    } else if (cards.wrap.selStyle === 'check square') {
      checkAll = 'mk-checkable square'
    } else if (card.setting.display !== 'default' && card.setting.controlIcon === 'left') {
      mainBox = 'flex-card '
    }
    let _style_ = null
    if (card.style.clear === 'left') {
      _style_ = {clear: 'left'}
    } else if (card.style.clear === 'right') {
      _style_ = {float: 'right'}
    }
    return (
      <Col span={card.setting.width || 24}>
        <div className={'card-item ' + (card.setting.btnControl || '')} style={_style} onDoubleClick={(e) => {e.stopPropagation(); this.doubleClickCard()}} id={card.uuid}>
          <div className="card-control" onDoubleClick={(e) => e.stopPropagation()}>
            <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
              <div className="mk-popover-control">
                <PlusOutlined className="plus" title="添加元素" onClick={this.addElement} />
                <PlusSquareOutlined className="plus" title="添加按钮" onClick={this.addButton} />
                <NormalForm title={'循环卡片设置'} width={950} update={this.updateSetting} getForms={this.getSettingForms}>
                  <EditOutlined className="edit" title="编辑"/>
                </NormalForm>
                <CopyComponent type="cardcell" card={card}/>
                <PasteController options={['action', 'customCardElement']} updateConfig={this.paste} />
                <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle} />
              </div>
            } trigger="hover">
              <ToolOutlined />
            </Popover>
      <Col span={card.setting.width || 24} style={_style_}>
        <div className="card-item-wrap" style={_wrapStyle}>
          <div className={`card-item ${card.setting.btnControl || ''} ${checkAll} mk-${card.setting.display} ${mainBox}`} style={_style} onDoubleClick={(e) => {e.stopPropagation(); this.doubleClickCard()}} id={card.uuid}>
            <span className="circle-select"></span>
            {card.setting.controlIcon === 'left' ? <PlusSquareOutlined /> : <UpOutlined />}
            <div className="card-control" onDoubleClick={(e) => e.stopPropagation()}>
              <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
                <div className="mk-popover-control">
                  <PlusOutlined className="plus" title="添加元素" onClick={() => this.addElement('main')} />
                  <PlusSquareOutlined className="plus" title="添加按钮" onClick={() => this.addButton('main')} />
                  <NormalForm title={'循环卡片设置'} width={950} update={(res) => this.updateSetting(res)} getForms={this.getSettingForms}>
                    <EditOutlined className="edit" title="编辑"/>
                  </NormalForm>
                  <CopyComponent type="cardcell" card={{...card, backElements: []}}/>
                  <PasteController options={['action', 'customCardElement']} updateConfig={(element, resolve) => this.paste(element, resolve, 'main')} />
                  <FontColorsOutlined className="style" title="调整样式" onClick={() => this.changeStyle()} />
                </div>
              } trigger="hover">
                <ToolOutlined />
              </Popover>
            </div>
            <CardCellComponent cards={cards} cardCell={card} side="main" elements={card.elements} updateElement={(elements, btn) => this.updateCard(elements, btn)}/>
          </div>
          <CardCellComponent cards={cards} cardCell={card} side="" elements={card.elements} updateElement={this.updateCard}/>
        </div>
        <div className={'card-item ' + (card.setting.btnControl || '')} style={_backStyle} onDoubleClick={(e) => {e.stopPropagation(); this.doubleClickCard()}} id={card.uuid}>
          <div className="card-control" onDoubleClick={(e) => e.stopPropagation()}>
            <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
              <div className="mk-popover-control">
                <PlusOutlined className="plus" title="添加元素" onClick={this.addElement} />
                <PlusSquareOutlined className="plus" title="添加按钮" onClick={this.addButton} />
                <NormalForm title={'循环子卡片设置'} width={950} update={this.updateSetting} getForms={this.getSettingForms}>
                  <EditOutlined className="edit" title="编辑"/>
                </NormalForm>
                <CopyComponent type="cardcell" card={card}/>
                <PasteController options={['action', 'customCardElement']} updateConfig={this.paste} />
                <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle} />
          <Col span={card.backSetting.width || 24}>
            <div className={'card-item ' + (card.backSetting.btnControl || '')} style={_backStyle} onDoubleClick={(e) => {e.stopPropagation(); this.doubleClickCard('sub')}} id={card.uuid}>
              <div className="card-control" onDoubleClick={(e) => e.stopPropagation()}>
                <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
                  <div className="mk-popover-control">
                    <PlusOutlined className="plus" title="添加元素" onClick={() => this.addElement('sub')} />
                    <PlusSquareOutlined className="plus" title="添加按钮" onClick={() => this.addButton('sub')} />
                    <NormalForm title={'循环子卡片设置'} width={950} update={(res) => this.updateSetting(res, 'sub')} getForms={this.getBackSettingForms}>
                      <EditOutlined className="edit" title="编辑"/>
                    </NormalForm>
                    <CopyComponent type="cardcell" card={{...card, elements: card.backElements, backElements: []}}/>
                    <PasteController options={['action', 'customCardElement']} updateConfig={(element, resolve) => this.paste(element, resolve, 'sub')} />
                    <FontColorsOutlined className="style" title="调整样式" onClick={() => this.changeStyle('sub')} />
                  </div>
                } trigger="hover">
                  <ToolOutlined />
                </Popover>
              </div>
            } trigger="hover">
              <ToolOutlined />
            </Popover>
          </div>
          <CardCellComponent cards={cards} cardCell={card} side="" elements={card.backElements} updateElement={this.updateCard}/>
              <CardCellComponent cards={cards} cardCell={card} side="sub" elements={card.backElements} updateElement={(elements, btn) => this.updateCard(elements, btn, 'sub')}/>
            </div>
          </Col>
        </div>
      </Col>
    )