king
2023-01-29 99c9aed75c0bf5356e3170b7070ed00d7ba653ca
src/menu/components/group/normal-group/index.jsx
@@ -1,19 +1,20 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Icon, Popover, Button } from 'antd'
import { Popover, Button, Modal } from 'antd'
import { EditOutlined, ToolOutlined, DeleteOutlined, FontColorsOutlined, PrinterOutlined, UngroupOutlined } from '@ant-design/icons'
import MKEmitter from '@/utils/events.js'
import asyncComponent from '@/utils/asyncComponent'
import asyncIconComponent from '@/utils/asyncIconComponent'
import { resetStyle } from '@/utils/utils-custom.js'
import getSettingForm from './options'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import './index.scss'
const { confirm } = Modal
const NormalForm = asyncIconComponent(() => import('@/components/normalform'))
const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
const NormalHeader = asyncComponent(() => import('@/menu/components/share/normalheader'))
const PasteComponent = asyncIconComponent(() => import('../paste'))
const GroupComponents = asyncComponent(() => import('../groupcomponents'))
@@ -21,11 +22,11 @@
  static propTpyes = {
    group: PropTypes.object,
    deletecomponent: PropTypes.func,
    unGroup: PropTypes.func,
    updateConfig: PropTypes.func,
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    group: null,
    editab: null,
  }
@@ -37,9 +38,6 @@
      let _group = {
        uuid: group.uuid,
        type: group.type,
        floor: group.floor,
        tabId: group.tabId || '',
        parentId: group.parentId || '',
        subtype: group.subtype,
        width: 24,
        name: group.name,
@@ -62,12 +60,6 @@
    return !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount () {
    MKEmitter.addListener('submitStyle', this.getStyle)
    MKEmitter.addListener('tabsChange', this.handleTabsChange)
    MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle)
  }
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
@@ -75,42 +67,16 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('submitStyle', this.getStyle)
    MKEmitter.removeListener('tabsChange', this.handleTabsChange)
    MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle)
  }
  updateComponentStyle = (parentId, keys, style) => {
    const { group } = this.state
    if (group.uuid !== parentId) return
    let components = group.components.map(item => {
      if (keys.includes(item.uuid)) {
        item.style = {...item.style, ...style}
      }
      return item
    })
    this.setState({
      group: {...group, components: []}
    }, () => {
      this.updateComponent({...group, components: components})
    })
  }
  changeStyle = () => {
    const { group } = this.state
    MKEmitter.emit('changeStyle', [group.uuid], ['background', 'border', 'padding', 'margin', 'shadow'], group.style)
    MKEmitter.emit('changeStyle', ['background', 'border', 'padding', 'margin', 'shadow', 'clear'], group.style, this.getStyle)
  }
  getStyle = (comIds, style) => {
    const { group } = this.state
    if (comIds.length !== 1 || comIds[0] !== group.uuid) return
    let _card = {...group, style}
  getStyle = (style) => {
    let _card = {...this.state.group, style}
    this.setState({
      group: _card
@@ -119,20 +85,16 @@
    this.props.updateConfig(_card)
  }
  handleTabsChange = (parentId) => {
    const { group } = this.state
    if (parentId === group.parentId) {
      MKEmitter.emit('tabsChange', group.uuid)
    }
  }
  updateComponent = (component) => {
    const { group } = this.state
    if (!is(fromJS(group.setting), fromJS(component.setting)) || !is(fromJS(group.style), fromJS(component.style))) {
      // 注册事件-标签变化,通知组内元素
      MKEmitter.emit('tabsChange', group.uuid)
      let ids = []
      group.components.forEach(item => {
        ids.push(item.uuid)
      })
      MKEmitter.emit('tabsChange', ids.join(','))
    }
    component.width = component.setting.width
@@ -147,9 +109,6 @@
  insert = (item) => {
    let group = fromJS(this.state.group).toJS()
    item.floor = group.floor || 1
    item.parentId = group.parentId
    group.components.push(item)
    this.setState({group})
@@ -163,13 +122,42 @@
  }
  updateWrap = (res) => {
    this.updateComponent({...this.state.group, setting: res})
    let group = {...this.state.group, setting: res}
    if (res.title && !group.headerStyle) {
      group.headerStyle = { fontSize: '16px', borderBottomWidth: '1px', borderBottomColor: '#e8e8e8' }
    }
    this.updateComponent(group)
  }
  clickComponent = (e) => {
    if (sessionStorage.getItem('style-control') === 'true' || sessionStorage.getItem('style-control') === 'component') {
      e.stopPropagation()
      MKEmitter.emit('clickComponent', this.state.group)
  unGroup = () => {
    const { group } = this.state
    if (group.components.length === 0) return
    const _this = this
    confirm({
      title: '确定释放分组元素吗?',
      content: '',
      onOk() {
        _this.props.unGroup(group.uuid)
        setTimeout(() => {
          _this.updataGroup()
        }, 10)
      },
      onCancel() {}
    })
  }
  updataGroup = () => {
    const { group } = this.props
    if (group.components.length === 0) {
      this.setState({
        group: fromJS(group).toJS()
      })
    }
  }
@@ -183,21 +171,23 @@
    }
    return (
      <div className={'menu-group-edit-box' + (paddingTop ? ' padding' : '')} style={_style} onClick={this.clickComponent} id={group.uuid}>
      <div className={'menu-group-edit-box ' + (paddingTop ? 'padding ' : '') + (group.setting.layout || '')} style={_style} id={group.uuid}>
        <NormalHeader hideSearch="true" config={group} updateComponent={this.updateComponent}/>
        <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
          <div className="mk-popover-control">
            <NormalForm title="分组设置" width={700} update={this.updateWrap} getForms={this.getWrapForms}>
              <Icon type="edit" style={{color: '#1890ff'}} title="编辑"/>
              <EditOutlined style={{color: '#1890ff'}} title="编辑"/>
            </NormalForm>
            <CopyComponent type="tabs" card={group}/>
            <UngroupOutlined title="释放" style={group.components.length > 0 ? {color: '#32c5d2'} : {color: '#eeeeee', cursor: 'not-allowed'}} onClick={this.unGroup}/>
            <PasteComponent insert={this.insert} />
            <Icon className="style" title="调整样式" onClick={this.changeStyle} type="font-colors" />
            <Icon className="close" title="delete" type="delete" onClick={() => this.props.deletecomponent(group.uuid)} />
            <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/>
            <DeleteOutlined className="close" title="delete" onClick={() => this.props.deletecomponent(group.uuid)} />
          </div>
        } trigger="hover">
          <Icon type="tool" />
          <ToolOutlined />
        </Popover>
        {group.setting && group.setting.print === 'true' ? <Button className="print-button" icon="printer" onClick={this.print}></Button> : null}
        {group.setting && group.setting.print === 'true' ? <Button className="print-button" onClick={this.print}><PrinterOutlined /></Button> : null}
        <GroupComponents config={group} handleList={this.updateComponent} deleteCard={this.deleteCard} />
      </div>
    )