king
2022-10-28 aa41be24e83653077d85860cb70882551912af24
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal, Button, notification } from 'antd'
import { QuestionCircleOutlined, CalendarOutlined } from '@ant-design/icons'
import moment from 'moment'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import './index.scss'
 
class Versions extends Component {
  static propTpyes = {
    MenuId: PropTypes.string,
    open_edition: PropTypes.string,
    updateConfig: PropTypes.func
  }
 
  state = {
    visible: false,
    loadingTable: false,
    preconfirming: false,
    nextconfirming: false,
    tables: [],
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  trigger = () => {
    this.setState({visible: true})
  }
 
  preVersion = () => {
    const { MenuId, open_edition, updateConfig } = this.props
 
    let param = {
      func: 's_spages_Param_ctrlzy',
      ctrlzy: 'z',
      MenuID: MenuId,
      TypeCharOne: sessionStorage.getItem('kei_no') || '',
      TypeName: sessionStorage.getItem('typename') || '',
      lang: sessionStorage.getItem('lang'),
      timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
      open_edition: open_edition,
      LText: MenuId + window.GLOB.appkey
    }
 
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
    this.setState({preconfirming: true})
 
    Api.getCloudConfig(param).then(res => {
      this.setState({preconfirming: false})
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      } else {
        this.setState({visible: false})
        notification.success({
          top: 92,
          message: '执行成功。',
          duration: 1
        })
 
        if (updateConfig) {
          updateConfig()
        } else {
          setTimeout(() => {
            window.location.reload()
          }, 1000)
        }
      }
    })
  }
 
  nextVersion = () => {
    const { MenuId, open_edition, updateConfig } = this.props
 
    let param = {
      func: 's_spages_Param_ctrlzy',
      ctrlzy: 'y',
      MenuID: MenuId,
      TypeCharOne: sessionStorage.getItem('kei_no') || '',
      TypeName: sessionStorage.getItem('typename') || '',
      lang: sessionStorage.getItem('lang'),
      timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
      open_edition: open_edition,
      LText: MenuId + window.GLOB.appkey
    }
 
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
    this.setState({nextconfirming: true})
 
    Api.getCloudConfig(param).then(res => {
      this.setState({nextconfirming: false})
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      } else {
        this.setState({visible: false})
        notification.success({
          top: 92,
          message: '执行成功。',
          duration: 1
        })
        
        if (updateConfig) {
          updateConfig()
        } else {
          setTimeout(() => {
            window.location.reload()
          }, 1000)
        }
      }
    })
  }
 
  render() {
    const { visible, preconfirming, nextconfirming } = this.state
 
    return (
      <div style={{display: 'inline-block'}}>
        <Button style={{borderColor: '#40a9ff', color: '#40a9ff'}} onClick={this.trigger}><CalendarOutlined /> 版本管理</Button>
        <Modal
          title=""
          wrapClassName="version-modal"
          visible={visible}
          width={500}
          closable={false}
          maskClosable={false}
          footer={[]}
          destroyOnClose
        >
          <div className="header"><QuestionCircleOutlined/>版本切换</div>
          <div className="detail">请选择需要切换的版本,或点击取消关闭弹窗。</div>
          <div className="footer">
            <Button key="pre" type="primary" loading={preconfirming} onClick={this.preVersion}>上一版本</Button>
            <Button key="next" type="primary" loading={nextconfirming} onClick={this.nextVersion}>下一版本</Button>
            <Button key="cancel" onClick={() => { this.setState({ visible: false })}}>取消</Button>
          </div>
        </Modal>
      </div>
    )
  }
}
 
export default Versions