king
2021-06-24 95afd40fc2741ac0ce59c2091f6cfce1f98877d4
src/menu/components/card/cardcellcomponent/index.jsx
@@ -1,7 +1,6 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import {connect} from 'react-redux'
import { Modal, Button } from 'antd'
import zhCN from '@/locales/zh-CN/model.js'
@@ -11,7 +10,7 @@
import { getActionForm } from '@/menu/components/share/actioncomponent/formconfig'
import MKEmitter from '@/utils/events.js'
import MenuUtils from '@/menu/utils/menuUtils.js'
import MenuUtils from '@/utils/utils-custom.js'
import ElementForm from './elementform'
import DragElement from './dragaction'
import './index.scss'
@@ -34,7 +33,7 @@
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    card: null,          // 编辑中元素
    formlist: null,      // 表单信息
    elements: null,      // 按钮组
@@ -48,9 +47,18 @@
   */
  UNSAFE_componentWillMount () {
    const { elements } = this.props
    let _elements = fromJS(elements).toJS()
    this.setState({
      elements: fromJS(elements).toJS()
      elements: _elements.map(item => {
        if (item.btnstyle) { // 兼容
          item.style = item.style || {}
          item.style = {...item.style, ...item.btnstyle}
          delete item.btnstyle
        }
        return item
      })
    })
  }
@@ -130,9 +138,7 @@
    let options = ['font', 'border', 'padding', 'margin', 'backgroundColor']
    if (element.eleType === 'button') {
      if (element.btnstyle) {
        _style = {..._style, ...element.btnstyle}
      }
      options.push('width')
    } else if (element.eleType === 'picture') {
      options = ['border', 'margin']
    } else if (element.eleType === 'slider') {
@@ -152,7 +158,7 @@
    const { cards, cardCell } = this.props
    const { card, elements } = this.state
    if (comIds.length !== 3 || comIds[0] !== cards.uuid || comIds[1] !== cardCell.uuid) return
    if (comIds.length !== 3 || comIds[0] !== cards.uuid || comIds[1] !== cardCell.uuid || !card) return
    let _card = this.resetCardStyle(card, style)
@@ -176,7 +182,7 @@
      let fontSize = 14
      let lineHeight = 1.5
      let line = _card.height || 1
      let line = _card.height || null
      if (_card.style.fontSize) {
        fontSize = parseInt(_card.style.fontSize)
@@ -185,7 +191,20 @@
        lineHeight = parseFloat(_card.style.lineHeight)
      }
      _card.innerHeight = fontSize * lineHeight * line
      if (line) {
        _card.innerHeight = fontSize * lineHeight * line
      }
    } else if (_card.eleType === 'sequence') {
      _card.style = style
      let fontSize = 14
      let lineHeight = 1.5
      if (_card.style.fontSize) {
        fontSize = parseInt(_card.style.fontSize)
      }
      _card.innerHeight = fontSize * lineHeight
    } else if (_card.eleType === 'barcode') {
      _card.style = style
@@ -197,47 +216,7 @@
      _card.innerHeight = _card.barHeight + (_card.displayValue === 'true' ? fontSize + 2 : 0)
    } else if (_card.eleType === 'button') { // 拆分style
      let _style = fromJS(style).toJS()
      _card.style = {}
      if (_style.marginTop) {
        _card.style.marginTop = _style.marginTop
        delete _style.marginTop
      }
      if (_style.marginBottom) {
        _card.style.marginBottom = _style.marginBottom
        delete _style.marginBottom
      }
      if (_style.marginLeft) {
        _card.style.marginLeft = _style.marginLeft
        delete _style.marginLeft
      }
      if (_style.marginRight) {
        _card.style.marginRight = _style.marginRight
        delete _style.marginRight
      }
      if (_style.paddingTop) {
        _card.style.paddingTop = _style.paddingTop
        delete _style.paddingTop
      }
      if (_style.paddingBottom) {
        _card.style.paddingBottom = _style.paddingBottom
        delete _style.paddingBottom
      }
      if (_style.paddingLeft) {
        _card.style.paddingLeft = _style.paddingLeft
        delete _style.paddingLeft
      }
      if (_style.paddingRight) {
        _card.style.paddingRight = _style.paddingRight
        delete _style.paddingRight
      }
      if (_style.textAlign) {
        _card.style.textAlign = _style.textAlign
        delete _style.textAlign
      }
      _card.btnstyle = _style
      _card.style = style
    } else {
      _card.style = style
    }
@@ -258,7 +237,7 @@
   * @description 元素编辑,获取元素表单信息
   */
  handleElement = (card) => {
    const { cards } = this.props
    const { cards, cardCell } = this.props
    if (card.eleType === 'button') {
      this.handleAction(card)
@@ -266,7 +245,7 @@
      this.setState({
        visible: true,
        card: card,
        formlist: getCardCellForm(card, cards.type)
        formlist: getCardCellForm(card, cards.type, cards.subtype, cardCell)
      })
    }
  }
@@ -275,7 +254,7 @@
   * @description 按钮编辑,获取按钮表单信息
   */
  handleAction = (card) => {
    const { menu, cards } = this.props
    const { cards } = this.props
    let usefulFields = sessionStorage.getItem('permFuncField')
    if (usefulFields) {
@@ -304,12 +283,12 @@
      menulist = []
    }
    let modules = MenuUtils.getSubModules(menu.components, cards.uuid)
    let modules = MenuUtils.getSubModules(window.GLOB.customMenu.components, cards.uuid)
    this.setState({
      actvisible: true,
      card: card,
      formlist: getActionForm(card, functip, cards.setting, usefulFields, 'card', menulist, modules)
      formlist: getActionForm(card, functip, cards.setting, usefulFields, 'card', menulist, modules, cards.columns)
    })
  }
@@ -351,7 +330,7 @@
          } else if (res.eleType === 'text' || res.eleType === 'number') {
            let fontSize = 14
            let lineHeight = 1.5
            let line = res.height || 1
            let line = res.height || null
      
            if (res.style && res.style.fontSize) {
              fontSize = parseInt(res.style.fontSize)
@@ -359,7 +338,10 @@
            if (res.style && res.style.lineHeight) {
              lineHeight = parseFloat(res.style.lineHeight)
            }
            res.innerHeight = fontSize * lineHeight * line
            if (line) {
              res.innerHeight = fontSize * lineHeight * line
            }
            if (res.eleType === 'text' && res.link && !res.style.color) {
              res.style.color = '#2440B3'
@@ -400,18 +382,18 @@
        if (cell.uuid === res.uuid) {
          res = {...cell, ...res}
          delete res.focus
          let btnstyle = {}
          let style = {}
          if (res.class !== cell.class || res.show !== cell.show || !res.btnstyle) {
          if (res.class !== cell.class || res.show !== cell.show || !res.style) {
            if (res.show === 'link' || res.show === 'icon') {
              btnstyle.color = color[res.class]
              btnstyle.backgroundColor = 'transparent'
              style.color = color[res.class]
              style.backgroundColor = 'transparent'
            } else {
              btnstyle.color = '#ffffff'
              btnstyle.backgroundColor = color[res.class]
              style.color = '#ffffff'
              style.backgroundColor = color[res.class]
            }
          }
          res.btnstyle = {...res.btnstyle, ...btnstyle}
          res.style = {...res.style, ...style}
          return res
        }
@@ -498,21 +480,33 @@
    const { cards } = this.props
    let btn = fromJS(item).toJS()
    if (btn.eleType !== 'button' || (sessionStorage.getItem('style-control') && sessionStorage.getItem('style-control') !== 'false')) return
    if ((sessionStorage.getItem('style-control') && sessionStorage.getItem('style-control') === 'true')) return
    if (btn.OpenType === 'pop') {
      if (!btn.modal) {
        btn.modal = {
          setting: { title: btn.label, width: 60, cols: '2', container: 'view', focus: '', finish: 'close', clickouter: 'unclose', display: 'modal' },
          tables: [],
          groups: [],
          fields: []
    if (btn.eleType === 'button') {
      if (btn.OpenType === 'pop') {
        if (!btn.modal) {
          btn.modal = {
            setting: { title: btn.label, width: 60, cols: '2', container: 'view', focus: '', finish: 'close', clickouter: 'unclose', display: 'modal' },
            tables: [],
            groups: [],
            fields: []
          }
        }
        MKEmitter.emit('changeModal', cards, btn)
      } else if (btn.OpenType === 'popview') {
        MKEmitter.emit('changePopview', cards, btn)
      } else if (btn.OpenType === 'innerpage' && btn.pageTemplate === 'page') {
        MKEmitter.emit('changeEditMenu', {MenuID: btn.uuid, copyMenuId: btn.copyMenuId})
      } else if (btn.OpenType === 'innerpage' && btn.pageTemplate === 'linkpage') {
        MKEmitter.emit('changeEditMenu', {MenuID: btn.linkmenu})
      }
      MKEmitter.emit('changeModal', cards, btn)
    } else if (btn.OpenType === 'popview') {
      MKEmitter.emit('changePopview', cards, btn)
    } else {
      if (btn.link === 'page') {
        MKEmitter.emit('changeEditMenu', {MenuID: btn.uuid, copyMenuId: btn.copyMenuId})
      } else if (btn.link === 'linkpage') {
        MKEmitter.emit('changeEditMenu', {MenuID: btn.linkmenu})
      }
    }
  }
@@ -558,6 +552,9 @@
  dropButton = (id) => {
    const { cards } = this.props
    if (!cards.action) return
    let index = cards.action.findIndex(item => item.uuid === id)
    if (index === -1) return
@@ -643,7 +640,6 @@
          visible={profVisible}
          width={'75vw'}
          maskClosable={false}
          style={{minWidth: '900px', maxWidth: '1200px'}}
          okText={dict['model.submit']}
          onOk={this.verifySubmit}
          onCancel={() => { this.setState({ profVisible: false }) }}
@@ -688,14 +684,4 @@
  }
}
const mapStateToProps = (state) => {
  return {
    menu: state.customMenu
  }
}
const mapDispatchToProps = () => {
  return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(CardCellComponent)
export default CardCellComponent