king
2021-01-12 c27d57333ed38c92f595219d2190ea63cef4d182
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Button, Modal, notification } from 'antd'
 
import Api from '@/api'
import options from '@/store/options.js'
import asyncComponent from '@/utils/asyncSpinComponent'
import './index.scss'
 
const VerifyCard = asyncComponent(() => import('@/tabviews/zshare/verifycard'))
 
class CustomSetting extends Component {
  static propTpyes = {
    dict: PropTypes.any,              // 字典表
    reloadview: PropTypes.func,       // 页面刷新
  }
 
  state = {
    userParam: null,       // 保存用户编辑中的配置
    visible: false,        // 模态框控制
    revertLoading: false,  // 恢复默认设置
    confirmLoading: false, // 自定义设置模态框加载中
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  controlCustomSetting = () => {
    this.setState({
      visible: true,
      confirmLoading: false,
      revertLoading: false
    })
 
    // let deffers = []
    // config.tabgroups.forEach(group => {
    //   group.sublist.forEach(tab => {
    //     deffers.push(new Promise(resolve => {
    //       let param = {
    //         func: 'sPC_Get_LongParam',
    //         MenuID: tab.linkTab
    //       }
    //       Api.getCacheConfig(param).then(res => {
    //         res.tab = tab
    //         resolve(res)
    //       })
    //     }))
    //   })
    // })
 
    // if (deffers.length > 0) {
    //   Promise.all(deffers).then(result => {
    //     let errors = result.filter(res => !res.status)
    //     if (errors.length > 0) {
    //       notification.warning({
    //         top: 92,
    //         message: errors[0].message,
    //         duration: 5
    //       })
    //       this.setState({
    //         loading: false
    //       })
    //       return
    //     }
 
    //     let roleId = sessionStorage.getItem('role_id') || '' // 角色ID
    //     result.forEach(res => {
    //       if (!res.LongParam) return
 
    //       let subconfig = ''
    //       let subUserConfig = userConfig ? userConfig[res.tab.uuid] : ''
    //     }
  }
 
  changeMenuParam = (param) => {
    this.setState({userParam: param})
  }
 
  settingRevert = () => {
    let param = {
      func: 's_TrdMenu_UserParam_del',
      MenuID: this.props.MenuID
    }
    this.setState({
      revertLoading: true
    })
 
    Api.getSystemConfig(param).then(result => {
      if (!result.status) {
        this.setState({
          revertLoading: false
        })
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
        return
      }
      this.setState({
        visible: false,
        revertLoading: false
      }, () => {
        window.GLOB.CacheMap = new Map()
        this.props.reloadview()
      })
    })
  }
 
  settingSubmit = () => {
    const { userParam } = this.state
    let _LongParam = ''
 
    try {
      _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(userParam)))
    } catch (e) {
      notification.warning({
        top: 92,
        message: '编译错误',
        duration: 5
      })
      return
    }
 
    let easyCode = userParam[this.props.MenuID] ? userParam[this.props.MenuID].easyCode : ''
 
    let param = {
      func: 'sPC_TrdMenu_UserParam',
      MenuID: this.props.MenuID,
      EasyCode: easyCode || '',
      LongParam: _LongParam
    }
 
    this.setState({
      confirmLoading: true
    })
 
    Api.getSystemConfig(param).then(result => {
      if (!result.status) {
        this.setState({
          confirmLoading: false
        })
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
        return
      }
 
      Api.deleteMenuStorage(this.props.MenuID).then(() => {
        this.setState({
          visible: false,
          confirmLoading: false
        }, () => {
          window.GLOB.CacheMap = new Map()
          this.props.reloadview()
        })
      })
    })
  }
 
  render() {
    
    return (
      <div className="page-setting-wrap">
        {options.sysType === 'local' ? <Button
          icon="setting"
          shape="circle"
          className="page-setting"
          onClick={this.handleviewconfig}
        /> : null}
        {/* <Icon className="custom-control" type="setting" onClick={this.controlCustomSetting} /> */}
        <Modal
          wrapClassName="common-table-custom-modal"
          title={'自定义设置'}
          maskClosable={false}
          width={950}
          visible={this.state.visible}
          onCancel={() => { this.setState({ visible: false }) }}
          footer={[
            <Button key="revert" type="danger" loading={this.state.revertLoading} onClick={this.settingRevert}>{this.props.dict['main.revert.default']}</Button>,
            <Button key="cancel" onClick={() => { this.setState({ visible: false }) }}>{this.props.dict['main.cancel']}</Button>,
            <Button key="confirm" type="primary" loading={this.state.confirmLoading} onClick={this.settingSubmit}>{this.props.dict['main.submit']}</Button>
          ]}
          destroyOnClose
        >
          {this.state.visible ?
            <VerifyCard
              MenuID={this.props.MenuID}
              MenuName={this.props.MenuName}
              permAction={this.props.permAction}
              config={this.props.config}
              userConfig={this.props.userConfig}
              columns={this.props.columns}
              handleParam={this.changeMenuParam}
            /> : null
          }
        </Modal>
      </div>
    )
  }
}
 
export default CustomSetting