king
2021-01-14 3cbad93c94c39730e45600efeabdfebcd424c2cc
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Icon, Modal, Button, Popconfirm, Table } from 'antd'
 
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
const { confirm } = Modal
 
class DataSource extends Component {
  static propTpyes = {
    btnlog: PropTypes.array,
    handlelog: PropTypes.func
  }
 
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    visible: false,
    data: [],
    columns: [
      {
        title: '按钮名称',
        dataIndex: 'label',
        width: '40%'
      },
      {
        title: '按钮类型',
        dataIndex: 'OpenType',
        width: '40%'
      },
      {
        title: '操作',
        align: 'center',
        width: '20%',
        dataIndex: 'operation',
        render: (text, record) =>
          (<div style={{textAlign: 'center'}}>
            <Popconfirm
              overlayClassName="popover-confirm"
              title="确定恢复记录吗?"
              onConfirm={() => this.revert(record)}
            >
              <span title="恢复" style={{color: '#26C281', fontSize: '16px', marginRight: '5px', cursor: 'pointer', padding: '5px'}}><Icon type="redo" /></span>
            </Popconfirm>
            <Popconfirm
              overlayClassName="popover-confirm"
              title="确定清除记录吗?"
              onConfirm={() => this.handleDelete(record)}
            >
              <span title="清除" style={{color: '#ff4d4f', fontSize: '16px', cursor: 'pointer', padding: '5px'}}><Icon type="close" /></span>
            </Popconfirm>
          </div>)
      }
    ],
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  trigger = () => {
    this.setState({
      visible: true,
      data: fromJS(this.props.btnlog).toJS()
    })
  }
 
  revert = (item) => {
    const data = this.state.data.filter(d => d.uuid !== item.uuid)
 
    this.setState({data})
    MKEmitter.emit('thawButtons', item.uuid)
    this.props.handlelog('revert', data, item)
  }
 
  handleDelete = (item) => {
    if (item) {
      const data = this.state.data.filter(d => d.uuid !== item.uuid)
  
      this.setState({data})
      this.props.handlelog('delete', data, null)
    } else {
      const _this = this
 
      confirm({
        content: '确定清空记录吗?',
        onOk() {
          _this.setState({data: []})
          _this.props.handlelog('delete', [], null)
        },
        onCancel() {}
      })
    }
  }
 
  render () {
    const { visible, dict, data, columns } = this.state
 
    return (
      <div className="btn-log-wrap">
        <Icon type="rollback" title="解除冻结" onClick={this.trigger} />
        <Modal
          wrapClassName="popview-modal"
          title="历史记录"
          visible={visible}
          width={700}
          maskClosable={false}
          onCancel={() => { this.setState({ visible: false }) }}
          footer={[
            <Button key="close" onClick={() => { this.setState({ visible: false }) }}>{dict['model.close']}</Button>
          ]}
          destroyOnClose
        >
          <Button disabled={data.length === 0} style={{float: 'right', marginBottom: '5px', position: 'relative', zIndex: 1}} onClick={() => this.handleDelete()} type="primary">清空</Button>
          <Table bordered rowKey="uuid" dataSource={data} columns={columns} pagination={false}/>
        </Modal>
      </div>
    )
  }
}
 
export default DataSource