king
2023-12-22 c39fc1db18c6d754312ccbc187f11076c203392b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Popover, Modal } from 'antd'
import { EditOutlined, ToolOutlined, DeleteOutlined, FontColorsOutlined, 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 './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('@/menu/components/tabs/paste'))
const GroupComponents = asyncComponent(() => import('../groupcomponents'))
 
class NormalGroup extends Component {
  static propTpyes = {
    group: PropTypes.object,
    deletecomponent: PropTypes.func,
    unGroup: PropTypes.func,
    updateConfig: PropTypes.func,
  }
 
  state = {
    group: null,
    editab: null,
  }
 
  UNSAFE_componentWillMount () {
    const { group } = this.props
 
    if (group.isNew) {
      let _group = {
        uuid: group.uuid,
        type: group.type,
        subtype: group.subtype,
        width: 24,
        name: group.name,
        setting: { width: 24, name: group.name },
        style: { marginLeft: '8px', marginRight: '8px', marginTop: '8px', marginBottom: '8px' },
        components: []
      }
      this.setState({
        group: _group
      })
      this.props.updateConfig(_group)
    } else {
      this.setState({
        group: fromJS(group).toJS()
      })
    }
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  changeStyle = () => {
    const { group } = this.state
 
    MKEmitter.emit('changeStyle', ['background', 'border', 'padding', 'margin', 'shadow', 'clear', 'minHeight'], group.style, this.getStyle)
  }
 
  getStyle = (style) => {
    let _card = {...this.state.group, style}
 
    this.setState({
      group: _card
    })
    
    this.props.updateConfig(_card)
  }
 
  updateComponent = (component) => {
    const { group } = this.state
 
    if (!is(fromJS(group.setting), fromJS(component.setting)) || !is(fromJS(group.style), fromJS(component.style))) {
      // 注册事件-标签变化,通知组内元素
      let ids = []
      group.components.forEach(item => {
        ids.push(item.uuid)
      })
      MKEmitter.emit('tabsChange', ids.join(','))
    }
 
    component.width = component.setting.width
    component.name = component.setting.name
 
    this.setState({
      group: component
    })
    this.props.updateConfig(component)
  }
 
  insert = (item) => {
    let group = fromJS(this.state.group).toJS()
 
    group.components.push(item)
 
    this.setState({group})
    this.props.updateConfig(group)
  }
 
  getWrapForms = () => {
    const { setting } = this.state.group
 
    return getSettingForm(setting)
  }
 
  updateWrap = (res) => {
    let group = {...this.state.group, setting: res}
 
    if (res.title && !group.headerStyle) {
      group.headerStyle = { fontSize: '16px', borderBottomWidth: '1px', borderBottomColor: '#e8e8e8' }
    }
 
    this.updateComponent(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()
      })
    }
  }
 
  render() {
    const { group } = this.state
    let _style = resetStyle(group.style)
 
    let paddingTop = true
    if (group.style.paddingTop && parseInt(group.style.paddingTop) >= 28) {
      paddingTop = false
    }
 
    return (
      <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}>
              <EditOutlined style={{color: '#1890ff'}} title="编辑"/>
            </NormalForm>
            <CopyComponent type="group" card={group}/>
            <UngroupOutlined title="释放" style={group.components.length > 0 ? {color: '#32c5d2'} : {color: '#eeeeee', cursor: 'not-allowed'}} onClick={this.unGroup}/>
            <PasteComponent type="group" insert={this.insert} />
            <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/>
            <DeleteOutlined className="close" title="delete" onClick={() => this.props.deletecomponent(group.uuid)} />
          </div>
        } trigger="hover">
          <ToolOutlined />
        </Popover>
        <GroupComponents config={group} handleList={this.updateComponent} deleteCard={this.deleteCard} />
      </div>
    )
  }
}
 
export default NormalGroup