king
2023-12-12 49f09cc6f8ff8c30a75ed1a9d6f510b69b73962a
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal, Button, notification, Table, Spin } from 'antd'
import { 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,
    Template: PropTypes.string,
    checklog: PropTypes.func,
    updateConfig: PropTypes.func
  }
 
  state = {
    visible: false,
    loading: false,
    logs: [],
    columns: [
      { title: '修改时间', dataIndex: 'createdate', key: 'createdate', align: 'center' },
      { title: '修改人', dataIndex: 'fullname', key: 'fullname', align: 'center' },
      {
        title: '操作',
        key: 'action',
        align: 'center',
        width: '230px',
        render: (text, record) => (
          <div>
            <Button type="link" onClick={() => this.change(record)} style={{color: '#1890ff'}}>切换</Button>
          </div>
        ),
      },
    ]
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  trigger = () => {
    let param = {
      func: 's_get_spages_param_log',
      MenuID: this.props.MenuId,
      TypeCharOne: sessionStorage.getItem('kei_no') || '',
      TypeName: sessionStorage.getItem('typename') || '',
      lang: sessionStorage.getItem('lang'),
      timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
      LText: this.props.MenuId + window.GLOB.appkey
    }
 
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
    this.setState({loading: true, visible: true, logs: []})
 
    Api.getCloudConfig(param).then(res => {
      this.setState({loading: false})
 
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return
      } else if (!res.data || res.data.length === 0) {
        Modal.warning({
          title: '当前菜单无历史版本。',
          okText: '知道了'
        })
        return
      }
 
      this.setState({logs: res.data})
    })
  }
 
  change = (record) => {
    const { checklog } = this.props
 
    if (checklog()) {
      this.getpage(record)
    } else {
      const that = this
 
      Modal.confirm({
        title: '当前配置未保存,确定切换吗?',
        onOk: () => {
          that.getpage(record)
        },
        onCancel() {}
      })
    }
  }
 
  getpage = (record) => {
    const { Template } = this.props
 
    let param = {
      func: 'sPC_Get_LongParam_page_id',
      id: record.id,
      TypeCharOne: sessionStorage.getItem('kei_no') || '',
      TypeName: sessionStorage.getItem('typename') || '',
      lang: sessionStorage.getItem('lang'),
    }
 
    this.setState({loading: true})
 
    Api.getCloudConfig(param).then(res => {
      this.setState({loading: false})
 
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      } else if (!res.LongParam) {
        notification.warning({
          top: 92,
          message: '未获取到配置信息!',
          duration: 5
        })
      } else {
        let config = null
  
        try {
          config = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
        } catch (e) {
          console.warn('Parse Failure')
          config = null
        }
 
        if (!config) {
          notification.warning({
            top: 92,
            message: '配置信息解析失败!',
            duration: 5
          })
        } else {
          if (Template !== config.Template) {
            notification.warning({
              top: 92,
              message: '菜单模板不一致,不可切换!',
              duration: 5
            })
          } else if (config.Template === 'CustomPage' && config.version !== 2.0) {
            notification.warning({
              top: 92,
              message: '历史配置版本过低,不可切换!',
              duration: 5
            })
          } else {
            this.setState({visible: false}, () => {
              this.props.updateConfig(config)
            })
 
            notification.success({
              top: 92,
              message: '版本切换成功,保存后生效!',
              duration: 5
            })
          }
        }
      }
    })
  }
 
  render() {
    const { visible, loading, logs, columns } = this.state
 
    return (
      <>
        <Button style={{borderColor: '#40a9ff', color: '#40a9ff'}} onClick={this.trigger}><CalendarOutlined /> 版本管理</Button>
        <Modal
          title="版本管理"
          wrapClassName="version-modal"
          visible={visible}
          width={800}
          maskClosable={false}
          onCancel={() => { this.setState({ visible: false, logs: [] }) }}
          footer={[
            <Button key="cancel" onClick={() => this.setState({ visible: false, logs: [] })}>关闭</Button>
          ]}
          destroyOnClose
        >
          {loading ? <Spin size="large" /> : null}
          <Table
            rowKey="id"
            columns={columns}
            dataSource={logs}
            pagination={{
              pageSize: 10,
              total: logs.length,
              showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条`
            }}
          />
        </Modal>
      </>
    )
  }
}
 
export default Versions