king
2024-05-16 b69b5f6329ca5f87932436b7a6c1ddfc3377e10f
src/menu/components/card/balcony/index.jsx
@@ -1,12 +1,12 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Popover, Checkbox } from 'antd'
import { PlusOutlined, PlusSquareOutlined, EditOutlined, FontColorsOutlined, DeleteOutlined, SettingOutlined, ToolOutlined } from '@ant-design/icons'
import { Popover, Checkbox, message } from 'antd'
import { PlusOutlined, PlusSquareOutlined, EditOutlined, FontColorsOutlined, DeleteOutlined, SettingOutlined, ToolOutlined, ClockCircleOutlined, ColumnHeightOutlined } from '@ant-design/icons'
import asyncComponent from '@/utils/asyncComponent'
import asyncIconComponent from '@/utils/asyncIconComponent'
import { resetStyle } from '@/utils/utils-custom.js'
import { resetStyle, getTables, checkComponent } from '@/utils/utils-custom.js'
import MKEmitter from '@/utils/events.js'
import Utils from '@/utils/utils.js'
import getWrapForm from './options'
@@ -17,7 +17,6 @@
const CardCellComponent = asyncComponent(() => import('../cardcellcomponent'))
const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
const PasteComponent = asyncIconComponent(() => import('@/components/paste'))
const UserComponent = asyncIconComponent(() => import('@/menu/components/share/usercomponent'))
const ClockComponent = asyncIconComponent(() => import('@/menu/components/share/clockcomponent'))
class BalconyEditComponent extends Component {
@@ -39,50 +38,58 @@
      let _card = {
        uuid: card.uuid,
        type: card.type,
        tabId: card.tabId || '',
        parentId: card.parentId || '',
        format: 'object',   // 组件属性 - 数据格式
        pageable: false,    // 组件属性 - 是否可分页
        switchable: false,  // 组件属性 - 数据是否可切换
        dataName: card.dataName || '',
        width: card.width || 24,
        name: card.name,
        subtype: card.subtype,
        setting: { interType: 'system' },
        wrap: { name: card.name, width: card.width || 24, linkType: 'static', position: 'relative', datatype: 'static' },
        style: { marginLeft: '0px', marginRight: '0px', marginTop: '0px', marginBottom: '0px' },
        wrap: { name: card.name, width: card.width || 24, linkType: 'static', datatype: 'static' },
        style: { marginLeft: '0px', marginRight: '0px', marginTop: '0px', marginBottom: '0px', position: 'unset' },
        columns: [],
        scripts: [],
        elements: [],
      }
      if (card.config) {
        let config = fromJS(card.config).toJS()
        _card.wrap = config.wrap
        _card.wrap.name = card.name
        _card.style = config.style
        _card.setting = config.setting
        _card.columns = config.columns
        _card.scripts = config.scripts
        _card.elements = _card.elements.map(elem => {
          elem.uuid = Utils.getuuid()
          return elem
        })
      }
      this.updateComponent(_card)
    } else {
      let _card = fromJS(card).toJS()
      if (!_card.style.position) { // 兼容
        if (_card.wrap.position === 'fixed' || _card.wrap.position === 'absolute') {
          _card.style.position = _card.wrap.position
          _card.style.zIndex = _card.wrap.position === 'fixed' ? 3 : 2
          _card.style.left = _card.wrap.left || ''
          _card.style.right = _card.wrap.right || ''
          _card.style.top = _card.wrap.top || ''
          _card.style.bottom = _card.wrap.bottom || ''
          _card.style.transform = _card.wrap.transform || ''
          _card.style.width = _card.wrap.realwidth || ''
        } else if (_card.wrap.left || _card.wrap.right || _card.wrap.top || _card.wrap.bottom) {
          _card.style.position = 'relative'
          _card.style.zIndex = 1
          _card.style.left = _card.wrap.left || ''
          _card.style.right = _card.wrap.right || ''
          _card.style.top = _card.wrap.top || ''
          _card.style.bottom = _card.wrap.bottom || ''
        } else {
          _card.style.position = 'unset'
        }
      }
      this.setState({
        card: fromJS(card).toJS()
        card: _card
      })
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount () {
    MKEmitter.addListener('mkUpdateInter', this.mkUpdateInter)
  }
  /**
@@ -92,6 +99,21 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('mkUpdateInter', this.mkUpdateInter)
  }
  mkUpdateInter = (inter, split) => {
    const { card } = this.state
    if (card.wrap.datatype === 'public' && card.wrap.publicId === inter.uuid) {
      let _card = {...card, columns: fromJS(inter.columns).toJS()}
      split.delay = split.delay + 10
      setTimeout(() => {
        this.updateComponent(_card)
      }, split.delay)
    }
  }
  /**
@@ -100,7 +122,6 @@
  updateComponent = (card) => {
    card.width = card.wrap.width
    card.name = card.wrap.name
    card.btnlog = []
    if (window.GLOB.styling && card.errors) { // 样式修改时不做筛查
      this.setState({
@@ -111,63 +132,15 @@
      return
    }
    card.errors = []
    card.$c_ds = card.wrap.datatype === 'dynamic'
    card.$c_ac = false
    card.$c_sc = false
    card.$c_el = true
    card.errors = checkComponent(card)
    if (card.wrap.datatype === 'static') {
      // let supModule = card.wrap.linkType === 'static' ? '' : 'has'
      card.elements.forEach(cell => {
        if (cell.eleType === 'button') {
          if (cell.OpenType === 'pop' || (cell.OpenType === 'funcbutton' && cell.execMode === 'pop')) {
            if (!cell.modal || cell.modal.fields.length === 0) {
              card.errors.push({ level: 1, detail: `按钮“${cell.label}”中表单尚未添加`})
            // } else if (!supModule) {
            //   cell.modal.fields.forEach(m => {
            //     if (m.type === 'linkMain') {
            //       card.errors.push({ level: 1, detail: `按钮“${cell.label}”中关联主表表单“${m.label}”无效`})
            //     }
            //   })
            }
          }
        } else if (cell.datatype === 'dynamic' && cell.field) {
          card.errors.push({ level: 1, detail: `卡片中动态字段“${cell.field}”无效`})
        }
      })
    } else {
      // let supModule = card.wrap.linkType === 'static' ? '' : 'has'
      let columns = card.columns.map(c => c.field)
      // let lowcols = card.columns.map(c => c.field.toLowerCase())
      if (card.setting.interType === 'system' && card.setting.execute !== 'false' && !card.setting.dataresource) {
        card.errors.push({ level: 0, detail: '未设置数据源!'})
      } else if (card.setting.interType === 'system' && card.setting.execute === 'false' && card.scripts.filter(script => script.status !== 'false').length === 0) {
        card.errors.push({ level: 0, detail: '数据源中无可用脚本!'})
      } else if (!card.setting.primaryKey) {
        card.errors.push({ level: 0, detail: '未设置主键!'})
      } else if (!columns.includes(card.setting.primaryKey)) {
        card.errors.push({ level: 0, detail: '主键已失效!'})
      }
      card.elements.forEach(cell => {
        if (cell.eleType === 'button') {
          if (cell.OpenType === 'pop' || (cell.OpenType === 'funcbutton' && cell.execMode === 'pop')) {
            if (!cell.modal || cell.modal.fields.length === 0) {
              card.errors.push({ level: 1, detail: `按钮“${cell.label}”中表单尚未添加`})
            // } else {
            //   cell.modal.fields.forEach(m => {
            //     if (m.type === 'linkMain' && !supModule) {
            //       card.errors.push({ level: 1, detail: `按钮“${cell.label}”中关联主表表单“${m.label}”无效`})
            //     } else if (m.field && card.wrap.linkType !== 'sync' && !columns.includes(m.field) && lowcols.includes(m.field.toLowerCase())) {
            //       card.errors.push({ level: 1, detail: `按钮“${cell.label}”中表单“${m.label}”大小写与字段集不一致`})
            //     }
            //   })
            }
          }
        } else if (cell.datatype === 'dynamic' && cell.field && !columns.includes(cell.field)) {
          card.errors.push({ level: 1, detail: `卡片中动态字段“${cell.field}”无效`})
        }
      })
    if (card.errors.length === 0) {
      card.$tables = getTables(card)
    }
    this.setState({
@@ -188,7 +161,7 @@
  changeStyle = () => {
    const { card } = this.state
    MKEmitter.emit('changeStyle', ['height', 'background', 'border', 'padding', 'margin', 'shadow'], card.style, this.getStyle)
    MKEmitter.emit('changeStyle', ['width', 'height', 'background', 'border', 'padding', 'margin', 'shadow', 'clear', 'minHeight', 'position', 'transform'], card.style, this.getStyle)
  }
  getStyle = (style) => {
@@ -208,8 +181,12 @@
    newcard.datatype = 'dynamic'
    newcard.height = 1
    if (card.wrap.datatype === 'static') {
      newcard.datatype = 'static'
    }
    // 注册事件-添加元素
    MKEmitter.emit('cardAddElement', [card.uuid, card.uuid], newcard)
    MKEmitter.emit('cardAddElement', card.uuid, newcard)
  }
  addButton = () => {
@@ -220,7 +197,7 @@
    newcard.focus = true
    // 注册事件-添加元素
    MKEmitter.emit('cardAddElement', [card.uuid, card.uuid], newcard)
    MKEmitter.emit('cardAddElement', card.uuid, newcard)
  }
  pasteComponent = (res, resolve) => {
@@ -233,23 +210,65 @@
    res.focus = true
    if (type === 'customCardElement') {
      MKEmitter.emit('cardAddElement', [card.uuid, card.uuid], res)
      MKEmitter.emit('cardAddElement', card.uuid, res)
    } else {
      res.eleType = 'button'
      MKEmitter.emit('cardAddElement', [card.uuid, card.uuid], res)
      res.width = res.width || 12
      MKEmitter.emit('cardAddElement', card.uuid, res)
    }
    resolve({status: true})
  }
  getWrapForms = () => {
    const { wrap } = this.state.card
    const { card } = this.state
    return getWrapForm(wrap)
    let buttons = []
    card.elements && card.elements.forEach(item => {
      if (item.eleType === 'button') {
        buttons.push({
          value: item.uuid,
          label: item.label
        })
      }
    })
    return getWrapForm(card.wrap, buttons, card.columns)
  }
  updateWrap = (res) => {
    delete res.quick
    this.updateComponent({...this.state.card, wrap: res})
    res.linkType = res.linkType || 'static'
    let _card = {...this.state.card, wrap: res}
    if (res.datatype === 'public') {
      let interfaces = window.GLOB.customMenu.interfaces || []
      let d = interfaces.filter(m => m.uuid === res.publicId && m.status === 'true')[0]
      if (d) {
        _card.columns = fromJS(d.columns).toJS()
        _card.setting = { interType: 'system' }
        _card.scripts = []
      }
    }
    if (_card.wrap.position === 'fixed') {
      if (_card.wrap.top && _card.wrap.bottom && _card.wrap.top.indexOf('vh') > -1 && _card.wrap.bottom.indexOf('vh') > -1) {
        if (parseFloat(_card.wrap.top) + parseFloat(_card.wrap.bottom) >= 100) {
          message.warning('元素距上距下之和超出100%,可能导致元素无法显示。')
        }
      }
      if (_card.wrap.left && _card.wrap.right && _card.wrap.left.indexOf('vw') > -1 && _card.wrap.right.indexOf('vw') > -1) {
        if (parseFloat(_card.wrap.left) + parseFloat(_card.wrap.right) >= 100) {
          message.warning('元素距左距右之和超出100%,可能导致元素无法显示。')
        }
      }
    }
    this.updateComponent(_card)
  }
  render() {
@@ -259,21 +278,20 @@
    return (
      <div className="menu-balcony-edit-box" style={_style} id={card.uuid}>
        {card.style.height ? <ColumnHeightOutlined className="fixed-height" title="定高" /> : null}
        <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={850} update={this.updateWrap} getForms={this.getWrapForms}>
            <NormalForm title="浮动卡设置" width={900} update={this.updateWrap} getForms={this.getWrapForms}>
              <EditOutlined style={{color: '#1890ff'}} title="编辑"/>
            </NormalForm>
            <CopyComponent type="balcony" card={card}/>
            <PasteComponent options={['action', 'customCardElement']} updateConfig={this.pasteComponent} />
            <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle} />
            <ClockComponent config={card} updateConfig={this.updateComponent}/>
            <UserComponent config={card}/>
            {card.wrap.datatype === 'dynamic' ? <ClockComponent config={card} updateConfig={this.updateComponent}/> : <ClockCircleOutlined style={{color: '#eeeeee', cursor: 'not-allowed'}}/>}
            <DeleteOutlined className="close" title="删除组件" onClick={() => this.props.deletecomponent(card.uuid)} />
            {card.wrap.datatype !== 'static' ? <SettingComponent config={card} updateConfig={this.updateComponent} /> : null}
            {card.wrap.datatype === 'static' ? <SettingOutlined style={{color: '#eeeeee', cursor: 'not-allowed'}}/> : null}
            {card.wrap.datatype === 'dynamic' ? <SettingComponent config={card} updateConfig={this.updateComponent} /> : <SettingOutlined style={{color: '#eeeeee', cursor: 'not-allowed'}}/>}
          </div>
        } trigger="hover">
          <ToolOutlined />
@@ -282,7 +300,15 @@
        <CardCellComponent cards={card} cardCell={card} elements={card.elements} updateElement={this.updateCard}/>
        <div className="component-name">
          <div className="center">
            <div className="title">{card.name}</div>
            <div className="title" onDoubleClick={() => {
              let oInput = document.createElement('input')
              oInput.value = 'anchor' + card.uuid
              document.body.appendChild(oInput)
              oInput.select()
              document.execCommand('Copy')
              document.body.removeChild(oInput)
              message.success('复制成功。')
            }}>{card.name}</div>
            <div className="content">
              {card.errors && card.errors.map((err, index) => {
                if (err.level === 0) {