king
2025-02-12 ed698a4ef051a13fe22c9ccfe121232c753725c1
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Popover, Modal, Button, Switch, message } from 'antd'
import { PlusOutlined, SettingOutlined, EditOutlined, ToolOutlined, DeleteOutlined, SwapOutlined, FontColorsOutlined } from '@ant-design/icons'
 
import asyncComponent from '@/utils/asyncComponent'
import asyncIconComponent from '@/utils/asyncIconComponent'
import { getModalForm } from '@/templates/zshare/formconfig'
import { resetStyle, getTables, checkComponent, getInterfaces } from '@/utils/utils-custom.js'
import MKEmitter from '@/utils/events.js'
import Utils from '@/utils/utils.js'
import getWrapForm from './options'
import './index.scss'
 
const ModalForm = asyncComponent(() => import('@/templates/zshare/modalform'))
const SettingComponent = asyncIconComponent(() => import('@/menu/datasource'))
const NormalForm = asyncIconComponent(() => import('@/components/normalform'))
const CardComponent = asyncComponent(() => import('@/templates/modalconfig/dragelement'))
const MobCardComponent = asyncComponent(() => import('@/mob/components/formdragelement'))
const FormAction = asyncComponent(() => import('../formaction'))
const FormFork = asyncComponent(() => import('@/menu/modalconfig/formfork'))
const NormalHeader = asyncComponent(() => import('@/menu/components/share/normalheader'))
const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
const PasteForms = asyncIconComponent(() => import('@/menu/components/share/pasteforms'))
const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent'))
 
const { confirm } = Modal
 
class SimpleFormComponent extends Component {
  static propTpyes = {
    card: PropTypes.object,
    deletecomponent: PropTypes.func,
    updateConfig: PropTypes.func,
  }
 
  state = {
    appType: sessionStorage.getItem('appType'),
    card: null,
    back: false,
    showField: false,
    visible: false,
    editform: null,
    formlist: null,
    sqlVerifing: false
  }
 
  UNSAFE_componentWillMount () {
    const { card } = this.props
 
    if (card.isNew) {
      let _card = {
        uuid: card.uuid,
        type: card.type,
        format: 'object',   // 组件属性 - 数据格式
        pageable: false,    // 组件属性 - 是否可分页
        switchable: false,  // 组件属性 - 数据是否可切换
        width: card.width || 24,
        name: card.name,
        subtype: card.subtype,
        setting: { interType: 'system' },
        wrap: { name: card.name, width: card.width || 24, datatype: 'static' },
        style: { marginLeft: '0px', marginRight: '0px', marginTop: '8px', marginBottom: '8px' },
        headerStyle: { fontSize: '16px', borderBottomWidth: '1px', borderBottomColor: '#e8e8e8' },
        columns: [],
        scripts: [],
        subcards: [{
          uuid: Utils.getuuid(),
          setting: {title: '', align: 'left_right', enable: 'true'},
          style: {},
          fields: [],
          subButton: {label: '提交', type: 'submit', intertype: 'system', reload: 'false', sqlType: '', sql: '', Ot: 'notRequired', execSuccess: 'never', enable: 'true', style: {backgroundColor: '#1890ff', color: '#ffffff', paddingLeft: '25px', paddingRight: '25px', paddingTop: '5px', paddingBottom: '5px'}},
        }]
      }
 
      this.updateComponent(_card)
    } else {
      let _card = fromJS(card).toJS()
      this.setState({
        card: _card
      })
    }
  }
 
  componentDidMount () {
    MKEmitter.addListener('mkUpdateInter', this.mkUpdateInter)
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    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)
    }
  }
 
  /**
   * @description 卡片行外层信息更新(数据源,样式等)
   */
  updateComponent = (card) => {
    card.width = card.wrap.width
    card.name = card.wrap.name
    card.errors = []
 
    card.$c_fc = true
    if (card.wrap.datatype === 'dynamic') {
      card.$c_ds = true
    } else {
      delete card.$c_ds
    }
 
    card.errors = checkComponent(card)
    card.$tables = getTables(card)
 
    delete card.$c_ds
    delete card.$c_fc
 
    this.setState({
      card: card
    })
 
    this.props.updateConfig(card)
  }
 
  /**
   * @description 单个卡片信息更新
   */
  updateCard = (cell) => {
    let card = fromJS(this.state.card).toJS()
 
    card.subcards = card.subcards.map(item => {
      if (item.uuid === cell.uuid) return cell
      return item
    })
 
    this.updateComponent(card)
  }
 
  changeStyle = () => {
    const { card } = this.state
 
    MKEmitter.emit('changeStyle', ['height', 'background', 'border', 'padding', 'margin', 'shadow', 'clear', 'minHeight'], card.style, this.getStyle)
  }
 
  getStyle = (style) => {
    let _card = {...this.state.card, style}
 
    this.updateComponent(_card)
  }
 
  updateGroup = (res) => {
    let card = fromJS(this.state.card).toJS()
 
    card.subcards[0] = res
 
    this.updateComponent(card)
  }
 
  plusFields = (items) => {
    const { card } = this.state
 
    let _card = fromJS(card).toJS()
 
    _card.subcards[0].fields.push(...items)
 
    this.updateComponent(_card)
  }
  
  changecols = (type) => {
    let card = fromJS(this.state.card).toJS()
    let that = this
 
    card.subcards[0].fields = card.subcards[0].fields.map(item => {
      item.labelwidth = 33.3
      item.span = 24
      if (['textarea','split','hint','checkcard','brafteditor'].includes(item.type)) {
        if (type === 2) {
          item.labelwidth = 16.3
        } else if (type === 3) {
          item.labelwidth = 10.5
        } else if (type === 4) {
          item.labelwidth = 8.3
        }
      } else if (type === 2) {
        item.span = 12
      } else if (type === 3) {
        item.span = 8
      } else if (type === 4) {
        item.span = 6
      }
      return item
    })
    
    confirm({
      content: `确定切换为${type}列吗?`,
      onOk() {
        that.updateComponent(card)
      },
      onCancel() {}
    })
  }
 
  handleList = (list, newcard) => {
    let card = fromJS(this.state.card).toJS()
 
    card.subcards[0].fields = list
 
    this.setState({}, () => {
      if (newcard) {
        this.handleForm(newcard)
      }
    })
    this.updateComponent(card)
  }
 
  closeForm = (cell) => {
    let card = fromJS(this.state.card).toJS()
    let that = this
 
    card.subcards[0].fields = card.subcards[0].fields.filter(item => item.uuid !== cell.uuid)
 
    confirm({
      content: `确定删除<<${cell.label}>>吗?`,
      onOk() {
        that.updateComponent(card)
      },
      onCancel() {}
    })
  }
 
  addForm = () => {
    const { appType } = this.state
    let card = fromJS(this.state.card).toJS()
    let lastItem = card.subcards[0].fields[card.subcards[0].fields.length - 1]
    let span = appType === 'mob' ? 24 : 12
    if (lastItem && lastItem.span) {
      span = lastItem.span
    }
 
    let newcard = {
      uuid: Utils.getuuid(),
      label: '',
      field: '',
      initval: '',
      type: 'text',
      resourceType: '0',
      span: span,
      labelwidth: 33.3,
      options: [],
      dataSource: '',
      decimal: 0,
      orderType: 'asc',
      readonly: 'false',
      required: 'true',
      readin: 'top',
      focus: true
    }
 
    card.subcards[0].fields.push(newcard)
 
    this.setState({card}, () => {
      this.handleForm(newcard)
    })
  }
 
  editModalCancel = () => {
    let card = fromJS(this.state.card).toJS()
    card.subcards[0].fields = card.subcards[0].fields.filter(item => !item.focus)
 
    this.setState({card, visible: false, editform: null})
 
    this.updateComponent(card)
  }
 
  /**
   * @description 表单编辑
   */
  handleForm = (_item) => {
    const { card } = this.state
 
    let _form = fromJS(_item).toJS()
 
    this.setState({
      visible: true,
      editform: _form,
      formlist: getModalForm(_form, card.subcards[0].fields, card.columns)
    })
  }
 
  /**
   * @description 编辑后提交
   * 1、获取编辑后的表单信息
   * 2、去除可能存在的示例表单
   * 3、通过loading刷新
   */
  handleSubmit = () => {
    let _config = fromJS(this.state.card).toJS()
 
    this.formRef.handleConfirm().then(res => {
      _config.subcards[0].fields = _config.subcards[0].fields.map(item => {
        delete item.focus
 
        if (item.uuid === res.values.uuid) {
          return res.values
        } else {
          return item
        }
      })
 
      if (res.loading) {
        this.setState({
          sqlVerifing: true
        })
 
        res.promise().then(() => {
          this.setState({
            sqlVerifing: false,
            editform: null,
            visible: false
          })
          this.updateComponent(_config)
        }, () => {
          this.setState({sqlVerifing: false})
        })
      } else {
        this.setState({
          editform: null,
          visible: false
        })
        this.updateComponent(_config)
      }
    })
  }
 
  pasteForm = (forms, res) => {
    let _config = fromJS(this.state.card).toJS()
 
    forms.forEach(item => {
      delete item.focus
    })
 
    _config.subcards[0].fields = forms
 
    if (res.subButton) {
      let that = this
 
      // _config.subcards[0].setting.focus = res.focus
      // _config.subcards[0].setting.cache = res.cache
      // _config.subcards[0].setting.align = res.align
      // _config.subcards[0].setting.enable = res.enable
      // _config.subcards[0].setting.verticalSpace = res.verticalSpace || ''
      // _config.wrap.focus = res.focus
      // _config.wrap.cache = res.cache
      // _config.wrap.align = res.align
      // _config.wrap.enable = res.enable
      // _config.wrap.verticalSpace = res.verticalSpace || ''
      
      confirm({
        content: '是否替换按钮配置?',
        okText: '是',
        cancelText: '否',
        onOk() {
          _config.subcards[0].subButton = res.subButton
          
          that.updateComponent(_config)
        },
        onCancel() {
          that.updateComponent(_config)
        }
      })
    } else {
      this.updateComponent(_config)
    }
  }
 
  getWrapForms = () => {
    return getWrapForm(this.state.card)
  }
 
  updateWrap = (res) => {
    let _card = fromJS(this.state.card).toJS()
    let buttons = res.buttons
 
    delete res.buttons
 
    res.enable = buttons.includes('enable') ? 'true' : 'false'
    res.closeEnable = buttons.includes('closeEnable') ? 'true' : 'false'
    res.resetEnable = buttons.includes('resetEnable') ? 'true' : 'false'
 
    _card.wrap = res
 
    if (res.datatype === 'static') {
      if (res.supModule && res.supModule.length > 0) {
        _card.setting.supModule = res.supModule
      } else {
        _card.setting.supModule = ''
      }
    } else if (res.datatype === 'public') {
      let interfaces = getInterfaces()
 
      let d = interfaces.filter(m => m.value === res.publicId)[0]
 
      if (d) {
        _card.columns = fromJS(d.columns).toJS()
 
        _card.setting = { interType: 'system' }
        _card.scripts = []
      }
    }
 
    _card.subcards[0].setting.focus = _card.wrap.focus
    _card.subcards[0].setting.cache = _card.wrap.cache
    _card.subcards[0].setting.align = _card.wrap.align
    _card.subcards[0].setting.enable = _card.wrap.enable
    _card.subcards[0].setting.verticalSpace = _card.wrap.verticalSpace
    _card.subcards[0].subButton.enable = _card.wrap.enable
 
    if (_card.wrap.closeEnable === 'true' && !_card.subcards[0].closeButton) {
      _card.subcards[0].closeButton = {label: '关闭', enable: 'true', type: 'close', style: {backgroundColor: '#ffffff', color: 'rgba(0,0,0,0.65)', borderColor: '#d9d9d9', borderWidth: '1px', paddingLeft: '25px', paddingRight: '25px', paddingTop: '5px', paddingBottom: '5px', marginLeft: '10px'}}
    } else if (_card.subcards[0].closeButton) {
      _card.subcards[0].closeButton.enable = _card.wrap.closeEnable
    }
    if (_card.wrap.resetEnable === 'true' && !_card.subcards[0].resetButton) {
      _card.subcards[0].resetButton = {label: '重置', enable: 'true', type: 'reset', style: {backgroundColor: '#ffffff', color: 'rgba(0,0,0,0.65)', borderColor: '#d9d9d9', borderWidth: '1px', paddingLeft: '25px', paddingRight: '25px', paddingTop: '5px', paddingBottom: '5px', marginLeft: '10px'}}
    } else if (_card.subcards[0].resetButton) {
      _card.subcards[0].resetButton.enable = _card.wrap.resetEnable
    }
 
    this.updateComponent(_card)
  }
 
  clearGroup = () => {
    let card = fromJS(this.state.card).toJS()
    let that = this
 
    card.subcards[0].fields = []
 
    confirm({
      content: `确定清空表单吗?`,
      onOk() {
        that.updateComponent(card)
      },
      onCancel() {}
    })
  }
 
  clickComponent = (e) => {
    if (sessionStorage.getItem('style-control') === 'true' || sessionStorage.getItem('style-control') === 'component') {
      e.stopPropagation()
      MKEmitter.emit('clickComponent', this.state.card.uuid, null, (style) => {
        let _card = {...this.state.card}
        _card.style = {..._card.style, ...style}
 
        this.setState({ card: _card })
        this.props.updateConfig(_card)
      })
    }
  }
 
  render() {
    const { card, appType } = this.state
 
    return (
      <div className="menu-simple-form-edit-box" style={resetStyle(card.style)} onClick={this.clickComponent} id={card.uuid}>
        <NormalHeader config={card} updateComponent={this.updateComponent}/>
        <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
          <div className="mk-popover-control">
            <NormalForm title="表单设置" width={800} update={this.updateWrap} getForms={this.getWrapForms}>
              <EditOutlined style={{color: '#1890ff'}} title="编辑"/>
            </NormalForm>
            <CopyComponent type="simpleform" card={card}/>
            <PasteForms config={card.subcards[0]} update={this.pasteForm} />
            <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/>
            <DeleteOutlined className="close" title="删除组件" onClick={() => this.props.deletecomponent(card.uuid)} />
            {card.wrap.datatype === 'dynamic' ? <SettingComponent config={card} updateConfig={this.updateComponent} /> : <SettingOutlined style={{color: '#eeeeee', cursor: 'not-allowed'}}/>}
          </div>
        } trigger="hover">
          <ToolOutlined />
        </Popover>
        <div className={`form-area mk-${card.wrap.formStyle || ''}`}>
          <PlusOutlined className="plus" title="添加表单" onClick={this.addForm}/>
          <FieldsComponent config={card.subcards[0]} type="form" plusFields={this.plusFields} />
          <div className="mk-form-tool">
            <DeleteOutlined title="清空" onClick={this.clearGroup} />
            {appType !== 'mob' ? <Popover title="切换布局" overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
              <>
                <Button style={{marginRight: '10px'}} onClick={() => this.changecols(1)}>1列</Button>
                <Button style={{marginRight: '10px'}} onClick={() => this.changecols(2)}>2列</Button>
                <Button style={{marginRight: '10px'}} onClick={() => this.changecols(3)}>3列</Button>
                <Button onClick={() => this.changecols(4)}>4列</Button>
              </>
            } trigger="hover">
              <SwapOutlined />
            </Popover> : null}
            <FormFork forms={card.subcards[0].fields}/>
            {/* <CopyOutlined title="复制" onClick={this.triggerCopy} /> */}
            <Switch checkedChildren="开" unCheckedChildren="关" defaultChecked={this.state.showField} onChange={(val) => this.setState({showField: val})} />
          </div>
          <div style={{clear: 'both'}}></div>
          {appType !== 'mob' ? <CardComponent
            list={card.subcards[0].fields}
            setting={card.subcards[0].setting}
            showField={this.state.showField}
            handleList={this.handleList}
            handleForm={this.handleForm}
            closeForm={this.closeForm}
          /> : <MobCardComponent
            list={card.subcards[0].fields}
            setting={card.subcards[0].setting}
            showField={this.state.showField}
            handleList={this.handleList}
            handleForm={this.handleForm}
            closeForm={this.closeForm}
          />}
          <FormAction config={card} group={card.subcards[0]} updateconfig={this.updateGroup}/>
        </div>
        <div className="component-name">
          <div className="center">
            <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) {
                  return <span key={index} className="error">{err.detail}</span>
                } else {
                  return <span key={index} className="waring">{err.detail};</span>
                }
              })}
            </div>
          </div>
        </div>
        <Modal
          title="编辑"
          wrapClassName="mk-scroll-modal"
          visible={this.state.visible}
          width={950}
          maskClosable={false}
          onCancel={this.editModalCancel}
          onOk={this.handleSubmit}
          confirmLoading={this.state.sqlVerifing}
          destroyOnClose
        >
          <ModalForm
            card={this.state.editform}
            formlist={this.state.formlist}
            inputSubmit={this.handleSubmit}
            fields={card.subcards[0].fields}
            wrappedComponentRef={(inst) => this.formRef = inst}
          />
        </Modal>
      </div>
    )
  }
}
 
export default SimpleFormComponent