king
2021-12-18 b223552a0c4bc787ad251add025a93d77527ffbe
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Modal, Spin, notification, Button } from 'antd'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import PasteForm from '@/templates/zshare/pasteform'
import TransferForm from '@/templates/zshare/basetransferform'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
class editComponent extends Component {
  static propTpyes = {
    options: PropTypes.array,
    MenuID: PropTypes.any,
    config: PropTypes.object,
    thawButtons: PropTypes.any,
    refresh: PropTypes.func
  }
 
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    thawVisible: false,
    thawbtnlist: null,
    pasteVisible: false,
    targetKeys: []
  }
 
  /**
   * @description 解冻按钮
   */
  handleThaw = () => {
    const { MenuID } = this.props
 
    this.setState({
      thawVisible: true,
      targetKeys: []
    })
 
    Api.getSystemConfig({
      func: 'sPC_Get_FrozenMenu',
      ParentID: MenuID,
      TYPE: 40
    }).then(res => {
      if (res.status) {
        let _list = []
 
        res.data.forEach(menu => {
          let _conf = ''
 
          if (menu.ParentParam) {
            try {
              _conf = JSON.parse(window.decodeURIComponent(window.atob(menu.ParentParam)))
            } catch (e) {
              console.warn('Parse Failure')
              _conf = ''
            }
          }
 
          if (_conf) {
            _list.push({
              key: menu.MenuID,
              title: menu.MenuName,
              btnParam: _conf
            })
          }
        })
 
        this.setState({
          thawbtnlist: _list
        })
      } else {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      }
    })
  }
 
  /**
   * @description 解冻按钮提交
   */
  thawBtnSubmit = () => {
    const { thawButtons } = this.props
    const { thawbtnlist, dict, targetKeys } = this.state
    let config = fromJS(this.props.config).toJS()
 
    if (targetKeys.length === 0) {
      notification.warning({
        top: 92,
        message: dict['form.required.select'] + '解冻按钮',
        duration: 5
      })
    } else {
      thawbtnlist.forEach(item => {
        if (targetKeys.includes(item.key)) {
          config.action.push(item.btnParam)
        }
      })
 
      this.props.refresh({
        type: 'thaw',
        thawButtons: [...thawButtons, ...targetKeys],
        config: config
      })
 
      this.setState({
        thawVisible: false,
        targetKeys: []
      })
    }
  }
 
  pasteSubmit = () => {
    const { options, config, type } = this.props
    let _config = fromJS(this.props.config).toJS()
 
    this.pasteFormRef.handleConfirm().then(res => {
      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 {
        notification.warning({
          top: 92,
          message: '配置信息格式错误!',
          duration: 5
        })
        return
      }
      this.setState({
        pasteVisible: false
      })
    })
  }
 
  handleMenuClick = e => {
    if (e.key === 'thaw') {
      this.handleThaw()
    } else if (e.key === 'paste') {
      this.setState({pasteVisible: true})
    }
  }
 
  render() {
    const { MenuID } = this.props
    const { dict } = this.state
 
    return (
      <div style={{display: 'inline-block'}}>
        {MenuID ? <Button className="mk-border-green" onClick={this.handleThaw} icon="unlock">解冻按钮</Button> : null}
        <Button style={{borderColor: '#40a9ff', color: '#40a9ff'}} onClick={() => this.setState({pasteVisible: true})} icon="snippets">{dict['header.form.paste']}</Button>
        {/* 解冻按钮模态框 */}
        <Modal
          title="解冻按钮"
          visible={this.state.thawVisible}
          onOk={this.thawBtnSubmit}
          onCancel={() => {this.setState({thawVisible: false, thawbtnlist: null, targetKeys: []})}}
          destroyOnClose
        >
          {!this.state.thawbtnlist && <Spin style={{marginLeft: 'calc(50% - 22px)', marginTop: '70px', marginBottom: '70px'}} size="large" />}
          {this.state.thawbtnlist && <TransferForm onChange={(vals) => this.setState({targetKeys: vals})} menulist={this.state.thawbtnlist}/>}
        </Modal>
        {/* 按钮配置信息粘贴复制 */}
        <Modal
          title={dict['header.form.paste']}
          visible={this.state.pasteVisible}
          width={600}
          maskClosable={false}
          onOk={this.pasteSubmit}
          onCancel={() => {this.setState({pasteVisible: false})}}
          destroyOnClose
        >
          <PasteForm wrappedComponentRef={(inst) => this.pasteFormRef = inst}/>
        </Modal>
      </div>
    )
  }
}
 
export default editComponent