king
2024-06-05 49fabbaab6ad5ab8ab6d8da3954384e0281f6134
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal, Button, Popover } from 'antd'
import { FontColorsOutlined, EditOutlined, ProfileOutlined } from '@ant-design/icons'
 
import asyncComponent from '@/utils/asyncComponent'
import { getActionForm } from './formconfig'
import { resetStyle } from '@/utils/utils-custom.js'
 
import MKEmitter from '@/utils/events.js'
import MenuUtils from '@/utils/utils-custom.js'
import './index.scss'
 
const ActionForm = asyncComponent(() => import('./actionform'))
const VerifyCard = asyncComponent(() => import('@/templates/zshare/verifycard'))
 
class CardCellComponent extends Component {
  static propTpyes = {
    group: PropTypes.object,         // 分组信息
    updateconfig: PropTypes.func     // 菜单配置更新
  }
 
  state = {
    appType: sessionStorage.getItem('appType'),
    card: null,          // 编辑中元素
    formlist: null,      // 表单信息
    visible: false,      // 模态框控制
    profVisible: false,  // 验证信息编辑
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props.group), fromJS(nextProps.group)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  handleStyle = (element) => {
    let _style = element.style ? fromJS(element.style).toJS() : {}
    let options = ['font', 'border', 'padding', 'margin', 'backgroundColor', 'width']
 
    this.setState({
      card: element
    })
 
    MKEmitter.emit('changeStyle', options, _style, this.getStyle)
  }
 
  getStyle = (style) => {
    const { card } = this.state
    let group = fromJS(this.props.group).toJS()
 
    if (card.type === 'prev') {
      group.prevButton.style = style
    } else if (card.type === 'submit') {
      group.subButton.style = style
    } else if (card.type === 'next') {
      group.nextButton.style = style
    } else if (card.type === 'close') {
      group.closeButton.style = style
    } else if (card.type === 'reset') {
      group.resetButton.style = style
    }
 
    this.props.updateconfig(group)
  }
 
  /**
   * @description 按钮编辑,获取按钮表单信息
   */
  handleAction = (card) => {
    const { config, group } = this.props
 
    let usefulFields = sessionStorage.getItem('permFuncField')
    if (usefulFields) {
      try {
        usefulFields = JSON.parse(usefulFields)
      } catch (e) {
        usefulFields = []
      }
    } else {
      usefulFields = []
    }
 
    let ableField = usefulFields.join(', ')
    let msg = `函数名称需以${ableField}等字符开始;`
    let functip = <div>
      <p style={{marginBottom: '5px'}}>{msg}</p>
    </div>
 
    let supId = ''
    if (config.wrap.linkType === 'sup') {
      supId = config.wrap.supModule[config.wrap.supModule.length - 1]
    }
 
    let menu = window.GLOB.customMenu
 
    let modules = MenuUtils.getSubModules(menu.components, config.uuid, supId, menu.interfaces || null)
    let anchors = MenuUtils.getAnchors(menu.components, config.uuid) || []
 
    if (card.type === 'submit' && !card.Ot) {
      card.Ot = config.wrap.datatype === 'static' ? 'notRequired' : 'requiredSgl'
    }
 
    this.setState({
      visible: true,
      card: card,
      formlist: getActionForm(card, functip, config.setting.tableName, usefulFields, modules, anchors, group.uuid, group.fields)
    })
  }
 
  /**
   * @description 取消保存,如果元素为新添元素,则从序列中删除
   */
  editModalCancel = () => {
    this.setState({
      card: null,
      visible: false
    })
  }
 
  /**
   * @description 元素修改后提交保存
   */
  handleActionSubmit = () => {
    const { card } = this.state
 
    this.actionFormRef.handleConfirm().then(res => {
      res.type = card.type
      res.style = card.style || null
      if (card.verify) {
        res.verify = card.verify
      }
 
      let group = fromJS(this.props.group).toJS()
 
      if (res.type === 'prev') {
        res.enable = group.prevButton.enable || 'true'
        group.prevButton = res
      } else if (res.type === 'submit') {
        res.enable = group.subButton.enable || 'true'
        group.subButton = res
      } else if (res.type === 'next') {
        res.enable = group.nextButton.enable || 'true'
        group.nextButton = res
      } else if (res.type === 'close') {
        res.enable = group.closeButton.enable || 'true'
        group.closeButton = res
      } else if (res.type === 'reset') {
        res.enable = group.resetButton.enable || 'true'
        group.resetButton = res
      }
 
      this.setState({
        visible: false
      })
      this.props.updateconfig(group)
    })
  }
 
  /**
   * @description 验证信息配置
   */
  profileAction = () => {
    this.setState({
      profVisible: true
    })
  }
 
  /**
   * @description 验证信息保存
   */
  verifySubmit = () => {
    this.verifyRef.handleConfirm().then(res => {
      let group = fromJS(this.props.group).toJS()
 
      group.subButton.verify = res
 
      this.setState({
        profVisible: false
      })
      this.props.updateconfig(group)
    })
  }
 
  changeMenu = () => {
    const { appType } = this.state
    const { group } = this.props
 
    if (appType !== 'pc' && appType !== 'mob') return
    if (!group.subButton.linkmenu) return
 
    MKEmitter.emit('changeEditMenu', {
      MenuID: group.subButton.linkmenu,
      copyMenuId: '',
      MenuNo: '',
      MenuName: '',
    })
  }
 
  render() {
    const { group, config } = this.props
    const { visible, profVisible, card } = this.state
 
    return (
      <div className="mk-form-action">
        {group.prevButton && group.prevButton.enable === 'true' ? <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
          <div className="mk-popover-control">
            <EditOutlined className="edit" title="编辑" onClick={() => this.handleAction(group.prevButton)} />
            <FontColorsOutlined className="style" title="调整样式" onClick={() => this.handleStyle(group.prevButton)}/>
          </div>
        } trigger="hover">
          <Button type="link" className="prev" style={resetStyle(group.prevButton.style)}>{group.prevButton.label}</Button>
        </Popover> : null}
        <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
          <div className="mk-popover-control">
            <EditOutlined className="edit" title="编辑" onClick={() => this.handleAction(group.subButton)} />
            <FontColorsOutlined className="style" title="调整样式" onClick={() => this.handleStyle(group.subButton)}/>
            <ProfileOutlined className="profile" title="setting" onClick={() => this.profileAction()} />
          </div>
        } trigger="hover">
          <Button type="link" className="submit" onDoubleClick={this.changeMenu} style={resetStyle(group.subButton.style)}>{group.subButton.label}</Button>
        </Popover>
        {group.resetButton && group.resetButton.enable === 'true' ? <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
          <div className="mk-popover-control">
            <EditOutlined className="edit" title="编辑" onClick={() => this.handleAction(group.resetButton)} />
            <FontColorsOutlined className="style" title="调整样式" onClick={() => this.handleStyle(group.resetButton)}/>
          </div>
        } trigger="hover">
          <Button type="link" className="reset" style={resetStyle(group.resetButton.style)}>{group.resetButton.label}</Button>
        </Popover> : null}
        {group.closeButton && group.closeButton.enable === 'true' ? <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
          <div className="mk-popover-control">
            <EditOutlined className="edit" title="编辑" onClick={() => this.handleAction(group.closeButton)} />
            <FontColorsOutlined className="style" title="调整样式" onClick={() => this.handleStyle(group.closeButton)}/>
          </div>
        } trigger="hover">
          <Button type="link" className="reset" style={resetStyle(group.closeButton.style)}>{group.closeButton.label}</Button>
        </Popover> : null}
        {group.nextButton && group.nextButton.enable === 'true' ? <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
          <div className="mk-popover-control">
            <EditOutlined className="edit" title="编辑" onClick={() => this.handleAction(group.nextButton)} />
            <FontColorsOutlined className="style" title="调整样式" onClick={() => this.handleStyle(group.nextButton)}/>
          </div>
        } trigger="hover">
          <Button type="link" className="skip" style={resetStyle(group.nextButton.style)}>{group.nextButton.label}</Button>
        </Popover> : null}
        {/* 编辑按钮:复制、编辑 */}
        <Modal
          title="编辑"
          visible={visible}
          width={920}
          maskClosable={false}
          onCancel={this.editModalCancel}
          footer={[
            <Button key="cancel" onClick={this.editModalCancel}>取消</Button>,
            <Button key="confirm" type="primary" onClick={this.handleActionSubmit}>确定</Button>
          ]}
          destroyOnClose
        >
          <ActionForm
            card={card}
            setting={config.setting}
            formlist={this.state.formlist}
            inputSubmit={this.handleActionSubmit}
            wrappedComponentRef={(inst) => this.actionFormRef = inst}
          />
        </Modal>
        {/* 按钮使用系统存储过程时,验证信息模态框 */}
        <Modal
          wrapClassName="mk-pop-modal"
          visible={profVisible}
          width={'90vw'}
          maskClosable={false}
          okText="提交"
          onOk={this.verifySubmit}
          onCancel={() => {
            if (this.verifyRef.handleCancel) {
              this.verifyRef.handleCancel().then(() => {
                this.setState({ profVisible: false })
              })
            } else {
              this.setState({ profVisible: false })
            }
          }}
          destroyOnClose
        >
          <VerifyCard
            card={{...group.subButton, modal: {fields: group.fields}}}
            config={config}
            columns={config.columns}
            wrappedComponentRef={(inst) => this.verifyRef = inst}
          />
        </Modal>
      </div>
    )
  }
}
 
export default CardCellComponent