king
2021-07-23 c7414c3cc93649479119d51b230c4b8e36884ca7
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal, Popover, Icon, Col } from 'antd'
 
import asyncIconComponent from '@/utils/asyncIconComponent'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import SettingForm from './settingform'
import { resetStyle } from '@/utils/utils-custom.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
 
class MenuBoxComponent extends Component {
  static propTpyes = {
    offset: PropTypes.any,           // 偏移量
    cards: PropTypes.object,         // 卡片行配置信息
    card: PropTypes.object,          // 卡片配置信息
    move: PropTypes.func,            // 卡片移动
    deleteElement: PropTypes.func,   // 卡片删除
    updateElement: PropTypes.func    // 菜单配置更新
  }
 
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    card: null,            // 卡片信息,包括正反面
    formlist: null,        // 设置表单信息
    visible: false,        // 模态框控制
  }
 
  /**
   * @description 搜索条件初始化
   */
  UNSAFE_componentWillMount () {
    const { card } = this.props
 
    this.setState({
      card: fromJS(card).toJS()
    })
  }
 
  componentDidMount () {
    MKEmitter.addListener('submitStyle', this.getStyle)
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    const { cards } = this.props
    
    return !is(fromJS(cards.wrap), fromJS(nextProps.cards.wrap)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('submitStyle', this.getStyle)
  }
 
  getStyle = (comIds, style) => {
    const { cards } = this.props
    const { card } = this.state
 
    if (comIds.length !== 2 || comIds[0] !== cards.uuid || comIds[1] !== card.uuid) return
 
    let _card = fromJS(card).toJS()
    _card.style = style
 
    this.setState({
      card: _card
    })
 
    this.props.updateElement(_card)
  }
 
  changeStyle = () => {
    const { cards } = this.props
    const { card } = this.state
 
    let _style = card.style ? fromJS(card.style).toJS() : {}
    let options = ['font', 'border', 'padding']
 
    MKEmitter.emit('changeStyle', [cards.uuid, card.uuid], options, _style)
  }
 
  settingSubmit = () => {
    const { card } = this.state
 
    this.settingRef.handleConfirm().then(res => {
      this.setState({
        visible: false,
        card: {...card, setting: res}
      })
 
      this.props.updateElement({...card, setting: res})
    })
  }
 
  changeMenu = () => {
    const { card } = this.state
 
    if (card.setting.type === 'link') {
      window.open(card.setting.linkurl)
    } else {
      MKEmitter.emit('changeEditMenu', {
        MenuID: card.setting.type === 'linkmenu' ? card.setting.linkMenuId : card.uuid,
        copyMenuId: card.setting.type === 'menu' ? card.setting.copyMenuId : '',
        MenuNo: card.setting.MenuNo || '',
        MenuName: card.setting.name,
      })
    }
  }
 
  render() {
    const { cards, offset } = this.props
    const { card, visible, dict } = this.state
 
    let _style = {...card.style}
 
    if (_style.shadow) {
      _style.boxShadow = '0 0 4px ' + _style.shadow
    }
 
    _style = resetStyle(_style)
 
    return (
      <Col span={card.setting.width || 6} offset={offset || 0}>
        <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
          <div className="mk-popover-control">
            <Icon className="edit" title="编辑" type="edit" onClick={() => this.setState({visible: true})} />
            <CopyComponent type="menucell" card={card}/>
            <Icon className="style" title="调整样式" onClick={this.changeStyle} type="font-colors" />
            <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
              <div className="mk-popover-control">
                <Icon className="plus" title="左移" type="arrow-left" onClick={() => this.props.move(card, 'left')} />
                <Icon className="close" title="右移" type="arrow-right" onClick={() => this.props.move(card, 'right')} />
              </div>
            } trigger="hover" getPopupContainer={() => document.getElementById(card.uuid + 'swap')}>
              <Icon type="swap" id={card.uuid + 'swap'}/>
            </Popover>
            <Icon className="close" title="删除菜单" type="delete" onClick={() => this.props.deleteElement(card)} />
          </div>
        } trigger="hover">
          <div className="menu-item" onDoubleClick={() => this.changeMenu()} style={_style}>
            {card.setting.sign === 'icon' ? <div className="menu-sign">
              <Icon style={{
                fontSize: card.setting.iconFont || 20,
                padding: card.setting.padding,
                background: card.setting.background,
                color: card.setting.color
              }} type={card.setting.icon}/>
            </div> : <div className="menu-sign">
              <img style={{width: card.setting.imgWidth, height: card.setting.imgWidth}} src={card.setting.url} alt=""/>
            </div>}
            <div className="menu-name">{card.setting.name}</div>
          </div>
        </Popover>
        <Modal
          wrapClassName="popview-modal"
          title={'菜单设置'}
          visible={visible}
          width={800}
          maskClosable={false}
          okText={dict['model.submit']}
          onOk={this.settingSubmit}
          onCancel={() => { this.setState({ visible: false }) }}
          destroyOnClose
        >
          <SettingForm
            dict={dict}
            cards={cards}
            setting={card.setting}
            inputSubmit={this.settingSubmit}
            wrappedComponentRef={(inst) => this.settingRef = inst}
          />
        </Modal>
      </Col>
    )
  }
}
 
export default MenuBoxComponent