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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Button, Modal, notification } from 'antd'
import moment from 'moment'
 
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import Utils from '@/utils/utils.js'
import MenuUtils from '@/utils/utils-custom.js'
import SettingForm from './settingform'
import Api from '@/api'
import './index.scss'
 
class CreateView extends Component {
  static propTpyes = {
    resetmenu: PropTypes.func
  }
 
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    visible: false,
    loading: false
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  verifySubmit = () => {
    this.verifyRef.handleConfirm().then(res => {
      
 
      let parMenuId = sessionStorage.getItem('kei_no') + sessionStorage.getItem('typename') + sessionStorage.getItem('lang')
      let menuId = Utils.getuuid()
 
      if (res.MenuId) {
        let appMenus = sessionStorage.getItem('appMenus')
        if (appMenus) {
          try {
            appMenus = JSON.parse(appMenus)
          } catch (e) {
            appMenus = []
          }
        } else {
          appMenus = []
        }
        if (appMenus.findIndex(item => item.MenuID === res.MenuId) > -1) {
          notification.warning({
            top: 92,
            message: '当前菜单已存在!',
            duration: 5
          })
          return
        }
        menuId = res.MenuId
      }
 
      this.setState({
        loading: true
      })
 
      let config = {
        version: 1.0,
        uuid: menuId,
        MenuID: menuId,
        Template: 'webPage',
        enabled: false,
        MenuName: res.MenuName || '',
        MenuNo: res.MenuNo || '',
        tables: [],
        components: [],
        viewType: 'menu',
        statusBarbgColor: sessionStorage.getItem('sysBgColor') || '#ffffff',
        style: {
          backgroundColor: sessionStorage.getItem('sysBgColor') || '#ffffff'
        }
      }
 
      let param = {
        func: 'sPC_TrdMenu_AddUpt',
        FstID: parMenuId,
        SndID: parMenuId,
        ParentID: parMenuId,
        MenuID: menuId,
        MenuNo: res.MenuNo || '',
        EasyCode: '',
        Template: 'webPage',
        TypeCharOne: sessionStorage.getItem('kei_no'),
        Typename: sessionStorage.getItem('typename'),
        MenuName: res.MenuName || '',
        PageParam: JSON.stringify({Template: 'webPage'}),
        open_edition: '',
        LText: '',
        LTexttb: ''
      }
 
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt('', param.timestamp)
      
      if (!res.copymenuId) {
        param.LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(config)))
 
        Api.getSystemConfig(param).then(result => {
          if (!result.status) {
            notification.warning({
              top: 92,
              message: result.message,
              duration: 5
            })
          } else {
            notification.success({
              top: 92,
              message: '创建成功',
              duration: 5
            })
          }
 
          this.setState({
            visible: false,
            loading: false
          })
 
          this.props.resetmenu()
        })
      } else {
        Api.getSystemConfig({
          func: 'sPC_Get_LongParam',
          TypeCharOne: sessionStorage.getItem('kei_no'),
          typename: sessionStorage.getItem('typename') || 'pc',
          MenuID: res.copymenuId
        }).then(result => {
          if (!result.status) {
            notification.warning({
              top: 92,
              message: result.message,
              duration: 5
            })
            this.setState({
              loading: false
            })
            return
          }
 
          let _config = null
          try {
            _config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
          } catch (e) {
            console.warn('Parse Failure')
            _config = null
          }
  
          if (!_config) {
            notification.warning({
              top: 92,
              message: '未获取到配置信息!',
              duration: 5
            })
            this.setState({
              loading: false
            })
            return
          }
 
          if (_config.components) {
            config.components = MenuUtils.resetConfig(_config.components)
            config.tables = _config.tables || []
            config.style = _config.style || {}
            config.statusBarbgColor = _config.statusBarbgColor || ''
          }
  
          param.LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(config)))
 
          Api.getSystemConfig(param).then(result => {
            if (!result.status) {
              notification.warning({
                top: 92,
                message: result.message,
                duration: 5
              })
            } else {
              notification.success({
                top: 92,
                message: '创建成功',
                duration: 5
              })
            }
 
            this.setState({
              visible: false,
              loading: false
            })
 
            this.props.resetmenu()
          })
        })
      }
    })
  }
 
  render () {
    const { config } = this.props
    const { visible, dict, loading } = this.state
 
    return (
      <div className="create-view">
        <Button icon="plus" className="mk-border-green" onClick={() => {this.setState({visible: true, loading: false})}}>新建页面</Button>
        <Modal
          title="新建页面"
          visible={visible}
          width={500}
          maskClosable={false}
          okText={dict['model.submit']}
          onOk={this.verifySubmit}
          onCancel={() => { this.setState({ visible: false }) }}
          confirmLoading={loading}
          destroyOnClose
        >
          <SettingForm
            dict={dict}
            config={config}
            wrappedComponentRef={(inst) => this.verifyRef = inst}
          />
        </Modal>
      </div>
    )
  }
}
 
export default CreateView