king
2020-06-24 dac21f9a9941681ccdc87220c2ed12ff277446d3
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Menu, Dropdown, Icon, Modal, Spin, notification } from 'antd'
 
import Api from '@/api'
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 './index.scss'
 
class editComponent extends Component {
  static propTpyes = {
    type: PropTypes.string,
    MenuID: PropTypes.any,
    config: PropTypes.object,
    thawButtons: PropTypes.any,
    refresh: PropTypes.func
  }
 
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    thawVisible: false,
    thawbtnlist: null,
    pasteVisible: false
  }
 
  handleMenuClick = e => {
    if (e.key === 'thaw') {
      this.handleThaw()
    } else if (e.key === 'paste') {
      this.setState({pasteVisible: true})
    }
  }
 
  /**
   * @description 解冻按钮
   */
  handleThaw = () => {
    const { config } = this.props
 
    this.setState({
      thawVisible: true
    })
 
    let uuid = config.uuid
 
    if (this.props.type === 'maintable') {
      uuid = this.props.MenuID
    }
 
    Api.getSystemConfig({
      func: 'sPC_Get_FrozenMenu',
      ParentID: uuid,
      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 } = this.state
    let config = JSON.parse(JSON.stringify(this.props.config))
 
    // 三级菜单解除冻结
    if (this.refs.trawmenu.state.targetKeys.length === 0) {
      notification.warning({
        top: 92,
        message: dict['form.required.select'] + dict['header.form.thawbutton'],
        duration: 5
      })
    } else {
 
      thawbtnlist.forEach(item => {
        if (this.refs.trawmenu.state.targetKeys.includes(item.key)) {
          config.action.push(item.btnParam)
        }
      })
 
      this.props.refresh({
        type: 'thaw',
        thawButtons: [...thawButtons, ...this.refs.trawmenu.state.targetKeys],
        config: config
      })
 
      this.setState({
        thawVisible: false
      })
    }
  }
 
  pasteSubmit = () => {
    const { config } = this.props
 
    this.pasteFormRef.handleConfirm().then(res => {
      if (res.copyType === 'action') {
        if (this.props.type === 'subtable' && !['pop', 'prompt', 'exec', 'excelIn', 'excelOut', 'popview'].includes(res.OpenType)) {
          notification.warning({
            top: 92,
            message: '不支持此打开方式!',
            duration: 5
          })
          return
        }
        this.setState({
          pasteVisible: false
        }, () => {
          this.props.refresh({
            type: 'paste',
            content: res
          })
        })
      } else if (res.copyType === 'search') {
        this.setState({
          pasteVisible: false
        }, () => {
          this.props.refresh({
            type: 'paste',
            content: res
          })
        })
      } else if (res.copyType === 'columns') {
        let _columns = config.columns.filter(col => !col.origin)
        if (_columns.length > 0) {
          notification.warning({
            top: 92,
            message: '显示列已存在!',
            duration: 5
          })
          return
        }
        
        this.setState({
          pasteVisible: false
        }, () => {
          this.props.refresh({
            type: 'paste',
            content: res
          })
        })
      } else {
        notification.warning({
          top: 92,
          message: '配置信息格式错误!',
          duration: 5
        })
      }
    })
  }
 
  render() {
    const { dict } = this.state
    const menu = (
      <Menu onClick={this.handleMenuClick}>
        {this.props.type !== 'TreePage' ? <Menu.Item key="thaw"><Icon type="unlock" />{dict['header.form.thawbutton']}</Menu.Item> : null}
        <Menu.Item key="paste"><Icon type="snippets" />{dict['header.form.paste']}</Menu.Item>
        {/* <Menu.Item key="replace"><Icon type="retweet" />替换</Menu.Item> */}
      </Menu>
    )
 
    return (
      <div style={{display: 'inline-block'}}>
        <Dropdown overlay={menu} overlayClassName="edit-component-box">
          <span style={{color: '#1890ff', display: 'inline-block', height: 25}}>
            {dict['model.edit']} <Icon type="down" />
          </span>
        </Dropdown>
        {/* 解冻按钮模态框 */}
        <Modal
          title={dict['header.form.thawbutton']}
          okText={dict['model.confirm']}
          cancelText={dict['model.cancel']}
          visible={this.state.thawVisible}
          onOk={this.thawBtnSubmit}
          onCancel={() => {this.setState({thawVisible: false, thawbtnlist: null})}}
          destroyOnClose
        >
          {!this.state.thawbtnlist && <Spin style={{marginLeft: 'calc(50% - 22px)', marginTop: '70px', marginBottom: '70px'}} size="large" />}
          {this.state.thawbtnlist && <TransferForm ref="trawmenu" dict={dict} 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
            dict={dict}
            wrappedComponentRef={(inst) => this.pasteFormRef = inst}
          />
        </Modal>
      </div>
    )
  }
}
 
export default editComponent