king
2024-10-30 c96108bd84050feb01b47db3f5cae96670fda435
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Modal, notification, Button } from 'antd'
import { SnippetsOutlined } from '@ant-design/icons'
 
import Utils from '@/utils/utils.js'
import PasteForm from '@/templates/zshare/pasteform'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
class editComponent extends Component {
  static propTpyes = {
    options: PropTypes.array,
    config: PropTypes.object,
    refresh: PropTypes.func
  }
 
  state = {
    visible: false
  }
 
  pasteSubmit = () => {
    const { options, config, type } = this.props
    let _config = fromJS(this.props.config).toJS()
 
    this.pasteFormRef.handleConfirm().then(res => {
      if (type === 'formboard' && res.copyType === 'search' && ['text', 'select', 'multiselect', 'link', 'checkcard', 'date', 'datemonth'].includes(res.type)) {
        res.copyType = 'form'
      }
      if (!options.includes(res.copyType)) {
        notification.warning({
          top: 92,
          message: '配置信息格式错误!',
          duration: 5
        })
        return
      } else if (res.copyType === 'action') {
        res.uuid = Utils.getuuid()
        MKEmitter.emit('pasteButton', config.uuid, res)
      } else if (res.copyType === 'search' || (type === 'table' && res.copyType === 'form')) {
        res.uuid = Utils.getuuid()
        let keys = _config.search.map(item => item.field ? item.field.toLowerCase() : '')
 
        if (type === 'table') {
          if (['number', 'switch', 'textarea', 'fileupload', 'hint', 'color', 'funcvar'].includes(res.type)) {
            res.type = 'text'
          } else if (res.type === 'radio') {
            res.type = 'select'
          } else if (res.type === 'checkbox') {
            res.type = 'multiselect'
          } else if (res.type === 'datetime') {
            res.type = 'date'
          }
        }
 
        if (res.field && keys.includes(res.field.toLowerCase())) {
          notification.warning({
            top: 92,
            message: '搜索字段已存在!',
            duration: 5
          })
          return
        }
        MKEmitter.emit('plusSearch', config.uuid, res, 'simple')
      } else if (res.copyType === 'columns') {
        let keys = _config.columns.map(item => item.field ? item.field.toLowerCase() : '')
        let items = res.columns.filter(col => col.field && !keys.includes(col.field.toLowerCase()))
        
        MKEmitter.emit('plusColumns', config.uuid, items)
      } else if (res.copyType === 'form') {
        let keys = _config.fields.map(item => item.field ? item.field.toLowerCase() : '')
        res.uuid = Utils.getuuid()
 
        if (res.field && keys.includes(res.field.toLowerCase())) {
          notification.warning({
            top: 92,
            message: '字段已存在!',
            duration: 10
          })
          return
        }
        
        this.props.plusFields([res])
      } else if (res.copyType === 'forms') {
        this.props.plusFields(res, 'forms')
      } else {
        notification.warning({
          top: 92,
          message: '配置信息格式错误!',
          duration: 5
        })
        return
      }
      this.setState({
        visible: false
      })
    })
  }
 
  render() {
    return (
      <div style={{display: 'inline-block'}}>
        <Button style={{borderColor: '#40a9ff', color: '#40a9ff'}} onClick={() => this.setState({visible: true})}><SnippetsOutlined /> 粘贴</Button>
        {/* 按钮配置信息粘贴复制 */}
        <Modal
          title="粘贴"
          visible={this.state.visible}
          width={600}
          maskClosable={false}
          onOk={this.pasteSubmit}
          onCancel={() => {this.setState({visible: false})}}
          destroyOnClose
        >
          <PasteForm wrappedComponentRef={(inst) => this.pasteFormRef = inst} inputSubmit={this.pasteSubmit}/>
        </Modal>
      </div>
    )
  }
}
 
export default editComponent