king
2020-11-24 0d6459d3bcd158d358752d2a6721a80e1192e110
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Icon, Button, Modal, notification } from 'antd'
 
import Api from '@/api'
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
    })
  }
 
  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>
        <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}
              permRoles={this.props.permRoles}
              config={this.props.config}
              userConfig={this.props.userConfig}
              columns={this.props.columns}
              handleParam={this.changeMenuParam}
            /> : null
          }
        </Modal>
      </div>
    )
  }
}
 
export default CustomSetting